105 lines
3.3 KiB
Plaintext
105 lines
3.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "431f44e2-ad47-458c-8a21-c88d1b71251a",
|
|
"metadata": {},
|
|
"source": [
|
|
"# ConversationSummaryMemory"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "bbb34950-bc59-4ef3-a87b-697d10058ac3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from langchain.chat_models import ChatOpenAI\n",
|
|
"from langchain.chains import ConversationChain\n",
|
|
"from langchain.memory import ConversationSummaryBufferMemory"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "1eee37a4-11f8-4657-bad9-cd046eac6fdb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"llm = ChatOpenAI(temperature=0)\n",
|
|
"memory = ConversationSummaryBufferMemory(llm=llm)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "5dcafc17-d2b1-4373-9255-9a270528bb98",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"skii_trip= \"\"\"\n",
|
|
"Guess what? I just came back from an incredible ski trip to Colorado and I cannot wait to tell you all about it!\n",
|
|
"\n",
|
|
"First things first, the mountains in Colorado are absolutely breathtaking. The picturesque landscapes of snow-capped peaks were straight out of a winter wonderland postcard. The moment I arrived, I couldn't help but feel this rush of excitement and anticipation for hitting the slopes.\n",
|
|
"\n",
|
|
"We stayed at this cozy ski lodge nestled right by the slopes, which made it super convenient for us to get on our skis and start exploring. The lodge had great amenities and a fireplace that was perfect for relaxing and warming up after a long day of skiing.\n",
|
|
"\n",
|
|
"Now, let me tell you about the skiing itself. I have to admit, I was a bit nervous at first because I'm not the most experienced skier, but the ski instructors there were so patient and helpful. They gave us pointers, taught us how to navigate the slopes safely, and even showed us a few tricks to improve our technique. I felt much more confident and excited about hitting the slopes after that.\n",
|
|
"\n",
|
|
"The ski resort had a variety of trails for all levels, from beginner-friendly slopes to more challenging ones. I started with the easier ones to get familiar with the snow.\n",
|
|
"\"\"\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "fda66bfc-b5e8-466d-b146-694677cde698",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Conversation chain with build in summarizer"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "ee0bf642-8161-4af1-a367-52c3143e7685",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=100)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5b4b284b-6812-447f-958b-45ac6fb7e1da",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"memory.save_context({},{})"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.11.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|