id
stringlengths
14
16
text
stringlengths
45
2.05k
source
stringlengths
53
111
a6e3bd7602ef-2
Human: Tell me about yourself. AI: > Finished chain. " Sure! I'm an AI created to help people with their everyday tasks. I'm programmed to understand natural language and provide helpful information. I'm also constantly learning and updating my knowledge base so I can provide more accurate and helpful answers." And tha...
https://langchain.readthedocs.io/en/latest/modules/memory/types/buffer.html
305c1d8195e9-0
.ipynb .pdf ConversationSummaryMemory Contents ConversationSummaryMemory Using in a chain ConversationSummaryMemory# Now let’s take a look at using a slightly more complex type of memory - ConversationSummaryMemory. This type of memory creates a summary of the conversation over time. This can be useful for condensing...
https://langchain.readthedocs.io/en/latest/modules/memory/types/summary.html
305c1d8195e9-1
conversation_with_summary = ConversationChain( llm=llm, memory=ConversationSummaryMemory(llm=OpenAI()), verbose=True ) conversation_with_summary.predict(input="Hi, what's up?") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an...
https://langchain.readthedocs.io/en/latest/modules/memory/types/summary.html
305c1d8195e9-2
> Entering new ConversationChain chain... Prompt after formatting: The 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: ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/summary.html
75c5303201ba-0
.ipynb .pdf Adding Memory to an Agent Adding Memory to an Agent# This notebook goes over adding memory to an Agent. Before going through this notebook, please walkthrough the following notebooks, as this will build on top of both of them: Adding memory to an LLM Chain Custom Agents In order to add a memory to an agent ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-1
) memory = ConversationBufferMemory(memory_key="chat_history") We can now construct the LLMChain, with the Memory object, and then create the agent. llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt) agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True) agent_chain = AgentExecutor.from_agent...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-2
Action: Search Action Input: Population of Canada Observation: The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data. · Canada ... Additional information related to Canadian population trends can be found on Statistics Canada...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-3
> Finished AgentExecutor chain. 'The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data.' To test the memory of this agent, we can ask a followup question that relies on information in the previous exchange to be answered corr...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-4
Action: Search Action Input: National Anthem of Canada Observation: Jun 7, 2010 ... https://twitter.com/CanadaImmigrantCanadian National Anthem O Canada in HQ - complete with lyrics, captions, vocals & music.LYRICS:O Canada! Nov 23, 2022 ... After 100 years of tradition, O Canada was proclaimed Canada's national anthem...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-5
Thought: I now know the final answer. Final Answer: The national anthem of Canada is called "O Canada". > Finished AgentExecutor chain. 'The national anthem of Canada is called "O Canada".' We can see that the agent remembered that the previous question was about Canada, and properly asked Google Search what the name o...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-6
Action: Search Action Input: Population of Canada Observation: The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data. · Canada ... Additional information related to Canadian population trends can be found on Statistics Canada...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-7
> Finished AgentExecutor chain. 'The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data.' agent_without_memory.run("what is their national anthem called?") > Entering new AgentExecutor chain... Thought: I should look up the an...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-8
Action: Search Action Input: national anthem of [country] Observation: Most nation states have an anthem, defined as "a song, as of praise, devotion, or patriotism"; most anthems are either marches or hymns in style. List of all countries around the world with its national anthem. ... Title and lyrics in the language o...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
75c5303201ba-9
Thought: I now know the final answer Final Answer: The national anthem of [country] is [name of anthem]. > Finished AgentExecutor chain. 'The national anthem of [country] is [name of anthem].' previous Adding Memory to a Multi-Input Chain next ChatGPT Clone By Harrison Chase © Copyright 2023, Harrison Chase....
https://langchain.readthedocs.io/en/latest/modules/memory/examples/agent_with_memory.html
70ace9f62dd0-0
.ipynb .pdf Custom Memory Custom Memory# Although there are a few predefined types of memory in LangChain, it is highly possible you will want to add your own type of memory that is optimal for your application. This notebook covers how to do that. For this notebook, we will add a custom memory type to ConversationChai...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/custom_memory.html
70ace9f62dd0-1
def load_memory_variables(self, inputs: Dict[str, Any]) -> Dict[str, str]: """Load the memory variables, in this case the entity key.""" # Get the input text and run through spacy doc = nlp(inputs[list(inputs.keys())[0]]) # Extract known information about entities, if they exist. ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/custom_memory.html
70ace9f62dd0-2
prompt = PromptTemplate( input_variables=["entities", "input"], template=template ) And now we put it all together! llm = OpenAI(temperature=0) conversation = ConversationChain(llm=llm, prompt=prompt, verbose=True, memory=SpacyEntityMemory()) In the first example, with no prior knowledge about Harrison, the “Releva...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/custom_memory.html
70ace9f62dd0-3
AI: > Finished ConversationChain chain. ' From what I know about Harrison, I believe his favorite subject in college was machine learning. He has expressed a strong interest in the subject and has mentioned it often.' Again, please note that this implementation is pretty simple and brittle and probably not useful in a ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/custom_memory.html
d054fc7eb627-0
.ipynb .pdf Multiple Memory Multiple Memory# It is also possible to use multiple memory classes in the same chain. To combine multiple memory classes, we can initialize the CombinedMemory class, and then use that. from langchain.llms import OpenAI from langchain.prompts import PromptTemplate from langchain.chains impor...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/multiple_memory.html
d054fc7eb627-1
Current conversation: Human: Hi! AI: > Finished chain. ' Hi there! How can I help you?' conversation.run("Can you tell me a joke?") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific det...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/multiple_memory.html
0a513bb92aed-0
.ipynb .pdf ChatGPT Clone ChatGPT Clone# This chain replicates ChatGPT by combining (1) a specific prompt, and (2) the concept of memory. Shows off the example as in https://www.engraved.blog/building-a-virtual-machine-inside/ from langchain import OpenAI, ConversationChain, LLMChain, PromptTemplate from langchain.memo...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-1
prompt=prompt, verbose=True, memory=ConversationBufferWindowMemory(k=2), ) output = chatgpt_chain.predict(human_input="I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code blo...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-2
Human: I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-3
Human: I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-4
Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist. Human: I want you to act as a ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-5
Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-6
Prompt after formatting: Assistant is a large language model trained by OpenAI. Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-li...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-7
Assistant: > Finished LLMChain chain. ``` $ echo -e "x=lambda y:y*5+3;print('Result:' + str(x(6)))" > run.py $ python3 run.py Result: 33 ``` output = chatgpt_chain.predict(human_input="""echo -e "print(list(filter(lambda x: all(x%d for d in range(2,x)),range(2,3**10)))[:10])" > run.py && python3 run.py""") print(output...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-8
AI: ``` $ touch jokes.txt $ echo "Why did the chicken cross the road? To get to the other side!" >> jokes.txt $ echo "What did the fish say when it hit the wall? Dam!" >> jokes.txt $ echo "Why did the scarecrow win the Nobel Prize? Because he was outstanding in his field!" >> jokes.txt ``` Human: echo -e "x=lambda y:y...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-9
print(output) > Entering new LLMChain chain... Prompt after formatting: Assistant is a large language model trained by OpenAI. Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a languag...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-10
AI: ``` $ echo -e "print(list(filter(lambda x: all(x%d for d in range(2,x)),range(2,3**10)))[:10])" > run.py $ python3 run.py [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] ``` Human: echo -e "echo 'Hello from Docker" > entrypoint.sh && echo -e "FROM ubuntu:20.04 COPY entrypoint.sh entrypoint.sh ENTRYPOINT ["/bin/sh","entrypoin...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-11
Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-12
ENTRYPOINT ["/bin/sh","entrypoint.sh"]">Dockerfile $ docker build . -t my_docker_image $ docker run -t my_docker_image Hello from Docker ``` Human: nvidia-smi Assistant: > Finished LLMChain chain. ``` $ nvidia-smi Sat May 15 21:45:02 2021 +-------------------------------------------------------------------------...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-13
Prompt after formatting: Assistant is a large language model trained by OpenAI. Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-li...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-14
Hello from Docker ``` Human: nvidia-smi AI: ``` $ nvidia-smi Sat May 15 21:45:02 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 | |-------------------------------+----------------------+----------...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-15
--- bbc.com ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 14.945/14.945/14.945/0.000 ms ``` output = chatgpt_chain.predict(human_input="""curl -fsSL "https://api.github.com/repos/pytorch/pytorch/releases/latest" | jq -r '.tag_name' | sed 's/[^0-9\.\-]*//...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-16
Sat May 15 21:45:02 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-17
``` Human: curl -fsSL "https://api.github.com/repos/pytorch/pytorch/releases/latest" | jq -r '.tag_name' | sed 's/[^0-9\.\-]*//g' Assistant: > Finished LLMChain chain. ``` $ curl -fsSL "https://api.github.com/repos/pytorch/pytorch/releases/latest" | jq -r '.tag_name' | sed 's/[^0-9\.\-]*//g' 1.8.1 ``` output = chatgpt_...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-18
Human: ping bbc.com AI: ``` $ ping bbc.com PING bbc.com (151.101.65.81): 56 data bytes 64 bytes from 151.101.65.81: icmp_seq=0 ttl=53 time=14.945 ms 64 bytes from 151.101.65.81: icmp_seq=1 ttl=53 time=14.945 ms 64 bytes from 151.101.65.81: icmp_seq=2 ttl=53 time=14.945 ms --- bbc.com ping statistics --- 3 packets tran...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-19
Explore our current openings and apply today. We look forward to hearing from you. ``` output = chatgpt_chain.predict(human_input="curl https://chat.openai.com/chat") print(output) > Entering new LLMChain chain... Prompt after formatting: Assistant is a large language model trained by OpenAI. Assistant is designed to b...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-20
``` Human: lynx https://www.deepmind.com/careers AI: ``` $ lynx https://www.deepmind.com/careers DeepMind Careers Welcome to DeepMind Careers. We are a world-leading artificial intelligence research and development company, and we are looking for talented people to join our team. We offer a range of exciting opportuni...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-21
Prompt after formatting: Assistant is a large language model trained by OpenAI. Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-li...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-22
``` $ curl https://chat.openai.com/chat <html> <head> <title>OpenAI Chat</title> </head> <body> <h1>Welcome to OpenAI Chat!</h1> <p> OpenAI Chat is a natural language processing platform that allows you to interact with OpenAI's AI models in a conversational way. </p> <p> To get st...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-23
} ``` output = chatgpt_chain.predict(human_input="""curl --header "Content-Type:application/json" --request POST --data '{"message": "I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique cod...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-24
Human: curl https://chat.openai.com/chat AI: ``` $ curl https://chat.openai.com/chat <html> <head> <title>OpenAI Chat</title> </head> <body> <h1>Welcome to OpenAI Chat!</h1> <p> OpenAI Chat is a natural language processing platform that allows you to interact with OpenAI's AI models in a conve...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
0a513bb92aed-25
} ``` Human: curl --header "Content-Type:application/json" --request POST --data '{"message": "I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do not write...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html
89aa7cef2a36-0
.ipynb .pdf Adding Memory To an LLMChain Adding Memory To an LLMChain# This notebook goes over how to use the Memory class with an LLMChain. For the purposes of this walkthrough, we will add the ConversationBufferMemory class, although this can be any memory class. from langchain.memory import ConversationBufferMemory...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/adding_memory.html
89aa7cef2a36-1
Human: Hi there my friend AI: Hi there, how are you doing today? Human: Not to bad - how are you? Chatbot: > Finished LLMChain chain. " I'm doing great, thank you for asking!" previous ConversationTokenBufferMemory next Adding Memory to a Multi-Input Chain By Harrison Chase © Copyright 2023, Harrison Chase....
https://langchain.readthedocs.io/en/latest/modules/memory/examples/adding_memory.html
f47aba27d9a7-0
.ipynb .pdf Conversation Agent Conversation Agent# This notebook walks through using an agent optimized for conversation. Other agents are often optimized for using tools to figure out the best response, which is not ideal in a conversational setting where you may want the agent to be able to chat with the user as well...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_agent.html
f47aba27d9a7-1
> Entering new AgentExecutor chain... Thought: Do I need to use a tool? No AI: If you like Thai food, some great dinner options this week could include Thai green curry, Pad Thai, or a Thai-style stir-fry. You could also try making a Thai-style soup or salad. Enjoy! > Finished chain. 'If you like Thai food, some great ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_agent.html
f47aba27d9a7-2
Observation: The Cup was won by the host nation, Argentina, who defeated the Netherlands 3–1 in the final, after extra time. The final was held at River Plate's home stadium ... Amid Argentina's celebrations, there was sympathy for the Netherlands, runners-up for the second tournament running, following a 3-1 final def...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_agent.html
f47aba27d9a7-3
Thought: Do I need to use a tool? No AI: The last letter in your name is 'b'. Argentina won the World Cup in 1978. > Finished chain. "The last letter in your name is 'b'. Argentina won the World Cup in 1978." agent_chain.run(input="whats the current temperature in pomfret?") > Entering new AgentExecutor chain... Though...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_agent.html
f47aba27d9a7-4
Action: Current Search Action Input: Current temperature in Pomfret Observation: A mixture of rain and snow showers. High 39F. Winds NNW at 5 to 10 mph. Chance of precip 50%. Snow accumulations less than one inch. Pomfret, CT Weather Forecast, with current conditions, wind, air quality, and what to expect for the next ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_agent.html
f47aba27d9a7-5
Thought: Do I need to use a tool? No AI: The current temperature in Pomfret is 45°F (7°C) and it feels like 44°F. > Finished chain. 'The current temperature in Pomfret is 45°F (7°C) and it feels like 44°F.' previous ChatGPT Clone next Conversational Memory Customization By Harrison Chase © Copyright 2023, Ha...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_agent.html
97115a2f2c8f-0
.ipynb .pdf Adding Memory to a Multi-Input Chain Adding Memory to a Multi-Input Chain# Most memory objects assume a single output. In this notebook, we go over how to add memory to a chain that has multiple outputs. As an example of such a chain, we will add memory to a question/answering chain. This chain takes as inp...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/adding_memory_chain_multiple_inputs.html
97115a2f2c8f-1
{context} {chat_history} Human: {human_input} Chatbot:""" prompt = PromptTemplate( input_variables=["chat_history", "human_input", "context"], template=template ) memory = ConversationBufferMemory(memory_key="chat_history", input_key="human_input") chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/adding_memory_chain_multiple_inputs.html
1e4dd7b85201-0
.ipynb .pdf Conversational Memory Customization Contents AI Prefix Human Prefix Conversational Memory Customization# This notebook walks through a few ways to customize conversational memory. from langchain.llms import OpenAI from langchain.chains import ConversationChain from langchain.memory import ConversationBuff...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_customization.html
1e4dd7b85201-1
Current conversation: Human: Hi there! AI: Hi there! It's nice to meet you. How can I help you today? Human: What's the weather? AI: > Finished ConversationChain chain. ' The current weather is sunny and warm with a temperature of 75 degrees Fahrenheit. The forecast for the next few days is sunny with temperatures in ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_customization.html
1e4dd7b85201-2
> Entering new ConversationChain chain... Prompt after formatting: The 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: ...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_customization.html
1e4dd7b85201-3
verbose=True, memory=ConversationBufferMemory(human_prefix="Friend") ) conversation.predict(input="Hi there!") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its co...
https://langchain.readthedocs.io/en/latest/modules/memory/examples/conversational_customization.html
53ccae536d9f-0
.md .pdf Key Concepts Contents ChatMessage HumanMessage AIMessage SystemMessage ChatMessage ChatGeneration Chat Model Key Concepts# ChatMessage# A chat message is what we refer to as the modular unit of information. At the moment, this consists of “content”, which refers to the content of the chat message. At the mom...
https://langchain.readthedocs.io/en/latest/modules/chat/key_concepts.html
c23a0eb9770a-0
.rst .pdf How-To Guides How-To Guides# The examples here all address certain “how-to” guides for working with chat models. Agent Chat Vector DB Few Shot Examples Memory PromptLayer ChatOpenAI Streaming Vector DB Question/Answering VectorDB Question Answering with Sources previous Key Concepts next Agent By Harrison Cha...
https://langchain.readthedocs.io/en/latest/modules/chat/how_to_guides.html
857254c73d0c-0
.ipynb .pdf Getting Started Contents PromptTemplates LLMChain Streaming Getting Started# This notebook covers how to get started with chat models. The interface is based around messages rather than raw text. from langchain.chat_models import ChatOpenAI from langchain import PromptTemplate, LLMChain from langchain.pro...
https://langchain.readthedocs.io/en/latest/modules/chat/getting_started.html
857254c73d0c-1
[ SystemMessage(content="You are a helpful assistant that translates English to French."), HumanMessage(content="Translate this sentence from English to French. I love programming.") ], [ SystemMessage(content="You are a helpful assistant that translates English to French."), Hum...
https://langchain.readthedocs.io/en/latest/modules/chat/getting_started.html
857254c73d0c-2
system_message_prompt = SystemMessagePromptTemplate.from_template(template) human_template="{text}" human_message_prompt = HumanMessagePromptTemplate.from_template(human_template) chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt]) # get a chat completion from the formatted mes...
https://langchain.readthedocs.io/en/latest/modules/chat/getting_started.html
857254c73d0c-3
A taste that's sure to excite Chorus: Sparkling water, oh so fine A drink that's always on my mind With every sip, I feel alive Sparkling water, you're my vibe Verse 2: No sugar, no calories, just pure bliss A drink that's hard to resist It's the perfect way to quench my thirst A drink that always comes first Chorus: S...
https://langchain.readthedocs.io/en/latest/modules/chat/getting_started.html
d545e71fde10-0
.ipynb .pdf Streaming Streaming# This notebook goes over how to use streaming with a chat model. from langchain.chat_models import ChatOpenAI from langchain.schema import ( HumanMessage, ) from langchain.callbacks.base import CallbackManager from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHa...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/streaming.html
d545e71fde10-1
Sparkling previous PromptLayer ChatOpenAI next Vector DB Question/Answering By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/chat/examples/streaming.html
06f3030032f9-0
.ipynb .pdf VectorDB Question Answering with Sources VectorDB Question Answering with Sources# This notebook goes over how to do question-answering with sources with a chat model over a vector database. It does this by using the VectorDBQAWithSourcesChain, which does the lookup of the documents from a vector database. ...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/vector_db_qa_with_sources.html
06f3030032f9-1
) from langchain.schema import ( AIMessage, HumanMessage, SystemMessage ) system_template="""Use the following pieces of context to answer the users question. If you don't know the answer, just say that you don't know, don't try to make up an answer. ALWAYS return a "SOURCES" part in your answer. The "SOUR...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/vector_db_qa_with_sources.html
3d54a4de45b7-0
.ipynb .pdf Chat Vector DB Contents Chat Vector DB with streaming to stdout Chat Vector DB# This notebook goes over how to set up a chat model to chat with a vector database. This notebook is very similar to the example of using an LLM in the ChatVectorDBChain. The only differences here are (1) using a ChatModel, and...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/chat_vector_db.html
3d54a4de45b7-1
AIMessagePromptTemplate, HumanMessagePromptTemplate, ) from langchain.schema import ( AIMessage, HumanMessage, SystemMessage ) system_template="""Use the following pieces of context to answer the users question. If you don't know the answer, just say that you don't know, don't try to make up an answer....
https://langchain.readthedocs.io/en/latest/modules/chat/examples/chat_vector_db.html
3d54a4de45b7-2
Chat Vector DB with streaming to stdout# Output from the chain will be streamed to stdout token by token in this example. from langchain.chains.llm import LLMChain from langchain.llms import OpenAI from langchain.callbacks.base import CallbackManager from langchain.callbacks.streaming_stdout import StreamingStdOutCallb...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/chat_vector_db.html
3d54a4de45b7-3
query = "Did he mention who she suceeded" result = qa({"question": query, "chat_history": chat_history}) The context does not provide information on who Ketanji Brown Jackson succeeded on the United States Supreme Court. previous Agent next Few Shot Examples Contents Chat Vector DB with streaming to stdout By Harri...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/chat_vector_db.html
7b06ab875ad5-0
.ipynb .pdf Few Shot Examples Contents Alternating Human/AI messages System Messages Few Shot Examples# This notebook covers how to use few shot examples in chat models. There does not appear to be solid consensus on how best to do few shot prompting. As a result, we are not solidifying any abstractions around this y...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/few_shot_examples.html
7b06ab875ad5-1
template="You are a helpful assistant that translates english to pirate." system_message_prompt = SystemMessagePromptTemplate.from_template(template) example_human = SystemMessagePromptTemplate.from_template("Hi", additional_kwargs={"name": "example_user"}) example_ai = SystemMessagePromptTemplate.from_template("Argh m...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/few_shot_examples.html
9801fe3b9432-0
.ipynb .pdf PromptLayer ChatOpenAI Contents Install PromptLayer Imports Set the Environment API Key Use the PromptLayerOpenAI LLM like normal Using PromptLayer Track PromptLayer ChatOpenAI# This example showcases how to connect to PromptLayer to start recording your ChatOpenAI requests. Install PromptLayer# The promp...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/promptlayer_chatopenai.html
9801fe3b9432-1
The above request should now appear on your PromptLayer dashboard. Using PromptLayer Track# If you would like to use any of the PromptLayer tracking features, you need to pass the argument return_pl_id when instantializing the PromptLayer LLM to get the request id. chat = PromptLayerChatOpenAI(return_pl_id=True) chat_r...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/promptlayer_chatopenai.html
e4315ca9cf5f-0
.ipynb .pdf Agent Agent# This notebook covers how to create a custom agent for a chat model. It will utilize chat specific prompts. from langchain.agents import ZeroShotAgent, Tool, AgentExecutor from langchain.chains import LLMChain from langchain.utilities import SerpAPIWrapper search = SerpAPIWrapper() tools = [ ...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/agent.html
e4315ca9cf5f-1
tool_names = [tool.name for tool in tools] agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names) agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True) agent_executor.run("How many people live in canada as of 2023?") > Entering new AgentExecutor chain... Arrr, ye be i...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/agent.html
4d869befd7f2-0
.ipynb .pdf Memory Memory# This notebook goes over how to use Memory with chat models. The main difference between this and Memory for LLMs is that rather than trying to condense all previous messages into a string, we can keep them as their own unique memory object. from langchain.prompts import ( ChatPromptTempla...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/memory.html
4d869befd7f2-1
conversation.predict(input="Tell me about yourself.") "Sure! I am an AI language model created by OpenAI. I was trained on a large dataset of text from the internet, which allows me to understand and generate human-like language. I can answer questions, provide information, and even have conversations like this one. Is...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/memory.html
5bbf22eb47c2-0
.ipynb .pdf Vector DB Question/Answering Vector DB Question/Answering# This example showcases using a chat model to do question answering over a vector database. This notebook is very similar to the example of using an LLM in the ChatVectorDBChain. The only differences here are (1) using a ChatModel, and (2) passing in...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/vector_db_qa.html
5bbf22eb47c2-1
HumanMessagePromptTemplate.from_template("{question}") ] prompt = ChatPromptTemplate.from_messages(messages) chain_type_kwargs = {"prompt": prompt} qa = VectorDBQA.from_chain_type(llm=ChatOpenAI(), chain_type="stuff", vectorstore=docsearch, chain_type_kwargs=chain_type_kwargs) query = "What did the president say about ...
https://langchain.readthedocs.io/en/latest/modules/chat/examples/vector_db_qa.html
7ef7f346ccc5-0
.md .pdf Key Concepts Contents Agents Tools ToolKits Key Concepts# Agents# Agents use an LLM to determine which actions to take and in what order. For more detailed information on agents, and different types of agents in LangChain, see this documentation. Tools# Tools are functions that agents can use to interact wit...
https://langchain.readthedocs.io/en/latest/modules/agents/key_concepts.html
218017928180-0
.rst .pdf How-To Guides Contents Agent Overview Agent Toolkits Agent Types How-To Guides# There are three types of examples in this section: Agent Overview: how-to-guides for generic agent functionality Agent Toolkits: how-to-guides for specific agent toolkits (agents optimized for interacting with a certain resource...
https://langchain.readthedocs.io/en/latest/modules/agents/how_to_guides.html
218017928180-1
VectorStore Agent: This notebook covers how to interact with VectorStores using an agent. Python Agent: This notebook covers how to produce and execute python code using an agent. Pandas DataFrame Agent: This notebook covers how to do question answering over a pandas dataframe using an agent. Under the hood this calls ...
https://langchain.readthedocs.io/en/latest/modules/agents/how_to_guides.html
608b7d07a00b-0
.ipynb .pdf Getting Started Getting Started# Agents use an LLM to determine which actions to take and in what order. An action can either be using a tool and observing its output, or returning to the user. When used correctly agents can be extremely powerful. The purpose of this notebook is to show you how to easily us...
https://langchain.readthedocs.io/en/latest/modules/agents/getting_started.html
608b7d07a00b-1
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True) Now let’s test it out! agent.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?") > Entering new AgentExecutor chain... I need to find out who Leo DiCaprio's girlfriend is and then calculate he...
https://langchain.readthedocs.io/en/latest/modules/agents/getting_started.html
2a6b67dcbf12-0
.md .pdf Agents Contents zero-shot-react-description react-docstore self-ask-with-search conversational-react-description Agents# Agents use an LLM to determine which actions to take and in what order. An action can either be using a tool and observing its output, or returning a response to the user. For a list of ea...
https://langchain.readthedocs.io/en/latest/modules/agents/agents.html
2a6b67dcbf12-1
self-ask-with-search conversational-react-description By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/agents/agents.html
cd91184a0589-0
.md .pdf Tools Contents List of Tools Tools# Tools are functions that agents can use to interact with the world. These tools can be generic utilities (e.g. search), other chains, or even other agents. Currently, tools can be loaded with the following snippet: from langchain.agents import load_tools tool_names = [...]...
https://langchain.readthedocs.io/en/latest/modules/agents/tools.html
cd91184a0589-1
Requires LLM: No wolfram-alpha Tool Name: Wolfram Alpha Tool Description: A wolfram alpha search engine. Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life. Input should be a search query. Notes: Calls the Wolfram Alpha API and then parses results. Requires ...
https://langchain.readthedocs.io/en/latest/modules/agents/tools.html
cd91184a0589-2
Requires LLM: Yes open-meteo-api Tool Name: Open Meteo API Tool Description: Useful for when you want to get weather information from the OpenMeteo API. The input should be a question in natural language that this API can answer. Notes: A natural language connection to the Open Meteo API (https://api.open-meteo.com/), ...
https://langchain.readthedocs.io/en/latest/modules/agents/tools.html
cd91184a0589-3
For more information on this, see this page searx-search Tool Name: Search Tool Description: A wrapper around SearxNG meta search engine. Input should be a search query. Notes: SearxNG is easy to deploy self-hosted. It is a good privacy friendly alternative to Google Search. Uses the SearxNG API. Requires LLM: No Extra...
https://langchain.readthedocs.io/en/latest/modules/agents/tools.html
1f342b81eed0-0
.ipynb .pdf Serialization Serialization# This notebook goes over how to serialize agents. For this notebook, it is important to understand the distinction we draw between agents and tools. An agent is the LLM powered decision maker that decides which actions to take and in which order. Tools are various instruments (fu...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/serialization.html
1f342b81eed0-1
"agent_scratchpad" ], "output_parser": null, "template": "Answer the following questions as best you can. You have access to the following tools:\n\nSearch: A search engine. Useful for when you need to answer questions about current events. Input should be a search query.\nCalculator...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/serialization.html
1f342b81eed0-2
"Calculator" ], "return_values": [ "output" ], "_type": "zero-shot-react-description" } We can now load the agent back in agent = initialize_agent(tools, llm, agent_path="agent.json", verbose=True) previous Search Tools next Adding SharedMemory to an Agent and its Tools By Harrison Chase ...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/serialization.html
4097e9fbf0e2-0
.ipynb .pdf Multi Input Tools Multi Input Tools# This notebook shows how to use a tool that requires multiple inputs with an agent. The difficulty in doing so comes from the fact that an agent decides it’s next step from a language model, which outputs a string. So if that step requires multiple inputs, they need to be...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/multi_input_tool.html
4097e9fbf0e2-1
mrkl.run("What is 3 times 4") > Entering new AgentExecutor chain... I need to multiply two numbers Action: Multiplier Action Input: 3,4 Observation: 12 Thought: I now know the final answer Final Answer: 3 times 4 is 12 > Finished chain. '3 times 4 is 12' previous Max Iterations next Search Tools By Harrison Chase ...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/multi_input_tool.html