mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-05 17:35:28 +03:00
11 KiB
11 KiB
In [1]:
from langchain import OpenAI, ConversationChain
llm = OpenAI(temperature=0)
conversation = ConversationChain(llm=llm, verbose=True)
conversation.predict(input="Hi there!")Out [1]:
[1m> Entering new chain...[0m Prompt after formatting: [32;1m[1;3mThe following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: Human: Hi there! AI:[0m [1m> Finished chain.[0m
' Hello! How are you today?'
In [2]:
conversation.predict(input="I'm doing well! Just having a conversation with an AI.")Out [2]:
[1m> Entering new chain...[0m Prompt after formatting: [32;1m[1;3mThe following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: Human: Hi there! AI: Hello! How are you today? Human: I'm doing well! Just having a conversation with an AI. AI:[0m [1m> Finished chain.[0m
" That's great! What would you like to talk about?"
In [3]:
conversation.predict(input="Tell me about yourself.")Out [3]:
[1m> Entering new chain...[0m Prompt after formatting: [32;1m[1;3mThe following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: Human: Hi there! AI: Hello! How are you today? Human: I'm doing well! Just having a conversation with an AI. AI: That's great! What would you like to talk about? Human: Tell me about yourself. AI:[0m [1m> Finished chain.[0m
' I am an AI created to provide information and support to humans. I enjoy learning and exploring new things.'
In [4]:
from langchain.chains.conversation.memory import ConversationSummaryMemoryIn [5]:
conversation_with_summary = ConversationChain(llm=llm, memory=ConversationSummaryMemory(llm=OpenAI()), verbose=True)
conversation_with_summary.predict(input="Hi, what's up?")Out [5]:
[1m> Entering new chain...[0m Prompt after formatting: [32;1m[1;3mThe following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: Human: Hi, what's up? AI:[0m [1m> Finished chain.[0m
"\n\nI'm doing well, thank you for asking. I'm currently working on a project that I'm really excited about."
In [6]:
conversation_with_summary.predict(input="Tell me more about it!")Out [6]:
[1m> Entering new chain...[0m Prompt after formatting: [32;1m[1;3mThe following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: The human and artificial intelligence are talking. The human asked the AI what it is doing, and the AI said that it is working on a project that it is excited about. Human: Tell me more about it! AI:[0m [1m> Finished chain.[0m
"\n\nI'm working on a project that I'm really excited about. It's a lot of work, but I think it's going to be really great when it's finished. I can't wait to show it to you!"
In [7]:
conversation_with_summary.predict(input="Very cool -- what is the scope of the project?")Out [7]:
[1m> Entering new chain...[0m Prompt after formatting: [32;1m[1;3mThe following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: The human and artificial intelligence are talking. The human asked the AI what it is doing, and the AI said that it is working on a project that it is excited about. The AI said that the project is a lot of work, but it is going to be great when it is finished. Human: Very cool -- what is the scope of the project? AI:[0m [1m> Finished chain.[0m
'\n\nThe project is quite large in scope. It involves a lot of data analysis and work with artificial intelligence algorithms.'
In [ ]: