{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "\n", "import dotenv\n", "from httpx import Timeout\n", "from langchain_core.prompts import (\n", " ChatPromptTemplate,\n", " SystemMessagePromptTemplate,\n", " HumanMessagePromptTemplate,\n", ")\n", "from langchain_openai import ChatOpenAI\n", "from pydantic import BaseModel\n", "from langchain_community.callbacks import get_openai_callback\n", "\n", "dotenv.load_dotenv()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import data.samples_to_split as samples\n", "from utils import GPTModels, create_split_text_chain" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "characters: ['narrator', 'Mr. Carraway', 'Daisy', 'Miss Baker', 'Tom', 'Nick']\n", "[narrator] “If you’ll get up.”\n", "[Mr. Carraway] “I will. Good night, Mr. Carraway. See you anon.”\n", "[Daisy] “Of course you will,” confirmed Daisy. “In fact I think I’ll arrange a marriage. Come over often, Nick, and I’ll sort of—oh—fling you together. You know—lock you up accidentally in linen closets and push you out to sea in a boat, and all that sort of thing—”\n", "[Miss Baker] “Good night,” called Miss Baker from the stairs. “I haven’t heard a word.”\n", "[Tom] “She’s a nice girl,” said Tom after a moment. “They oughtn’t to let her run around the country this way.”\n", "[Daisy] “Who oughtn’t to?” inquired Daisy coldly.\n", "[narrator] “Her family.”\n", "[narrator] “Her family is one aunt about a thousand years old. Besides, Nick’s going to look after her, aren’t you, Nick? She’s going to spend lots of weekends out here this summer. I think the home influence will be very good for her.”\n", "[narrator] Daisy and Tom looked at each other for a moment in silence.\n" ] } ], "source": [ "chain = create_split_text_chain(llm_model=GPTModels.GPT_4_TURBO_2024_04_09)\n", "with get_openai_callback() as cb:\n", " res = chain.invoke({'text': samples.GATSBY_2})\n", "print(res.to_pretty_text())" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Tokens Used: 1579\n", "\tPrompt Tokens: 1253\n", "\tCompletion Tokens: 326\n", "Successful Requests: 1\n", "Total Cost (USD): $0.02231" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cb" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "characters: ['narrator', 'Mr. Carraway', 'Daisy', 'Miss Baker', 'Tom', 'Nick']\n", "[narrator] “If you’ll get up.”\n", "[Mr. Carraway] “I will. Good night, Mr. Carraway. See you anon.”\n", "[Daisy] “Of course you will,” confirmed Daisy. “In fact I think I’ll arrange a marriage. Come over often, Nick, and I’ll sort of—oh—fling you together. You know—lock you up accidentally in linen closets and push you out to sea in a boat, and all that sort of thing—”\n", "[Miss Baker] “Good night,” called Miss Baker from the stairs. “I haven’t heard a word.”\n", "[Tom] “She’s a nice girl,” said Tom after a moment. “They oughtn’t to let her run around the country this way.”\n", "[Daisy] “Who oughtn’t to?” inquired Daisy coldly.\n", "[narrator] “Her family.”\n", "[narrator] “Her family is one aunt about a thousand years old. Besides, Nick’s going to look after her, aren’t you, Nick? She’s going to spend lots of weekends out here this summer. I think the home influence will be very good for her.”\n", "[narrator] Daisy and Tom looked at each other for a moment in silence.\n" ] } ], "source": [ "print(res.to_pretty_text())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "ai-audio-books", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.4" } }, "nbformat": 4, "nbformat_minor": 2 }