id
stringlengths
14
16
text
stringlengths
29
2.73k
source
stringlengths
50
116
1b54f3692ba3-1
Tool( name = "Summary", func=summry_chain.run, description="useful for when you summarize a conversation. The input to this tool should be a string, representing who will read this summary." ) ] prefix = """Have a conversation with a human, answering the following questions as best you can. ...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-2
Action: Search Action Input: "ChatGPT" Observation: Nov 30, 2022 ... We've trained a model called ChatGPT which interacts in a conversational way. The dialogue format makes it possible for ChatGPT to answer ... ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built ...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-3
Thought: I now know the final answer. Final Answer: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large language models and is optimized for dialogue by using Reinforcement Learning with Human-in-the-Loop. It is also capab...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-4
Action Input: Who developed ChatGPT Observation: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large ... Feb 15, 2023 ... Who owns Chat GPT? Chat GPT is owned and developed by AI research and deployment company, OpenAI. Th...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-5
Thought: I now know the final answer Final Answer: ChatGPT was developed by OpenAI. > Finished chain. 'ChatGPT was developed by OpenAI.' agent_chain.run(input="Thanks. Summarize the conversation, for my daughter 5 years old.") > Entering new AgentExecutor chain... Thought: I need to simplify the conversation for a 5 ye...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-6
print(agent_chain.memory.buffer) Human: What is ChatGPT? AI: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large language models and is optimized for dialogue by using Reinforcement Learning with Human-in-the-Loop. It is a...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-7
Tool( name = "Summary", func=summry_chain.run, description="useful for when you summarize a conversation. The input to this tool should be a string, representing who will read this summary." ) ] prefix = """Have a conversation with a human, answering the following questions as best you can. ...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-8
Action: Search Action Input: "ChatGPT" Observation: Nov 30, 2022 ... We've trained a model called ChatGPT which interacts in a conversational way. The dialogue format makes it possible for ChatGPT to answer ... ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built ...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-9
Thought: I now know the final answer. Final Answer: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large language models and is optimized for dialogue by using Reinforcement Learning with Human-in-the-Loop. It is also capab...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-10
Action Input: Who developed ChatGPT Observation: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large ... Feb 15, 2023 ... Who owns Chat GPT? Chat GPT is owned and developed by AI research and deployment company, OpenAI. Th...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-11
Thought: I now know the final answer Final Answer: ChatGPT was developed by OpenAI. > Finished chain. 'ChatGPT was developed by OpenAI.' agent_chain.run(input="Thanks. Summarize the conversation, for my daughter 5 years old.") > Entering new AgentExecutor chain... Thought: I need to simplify the conversation for a 5 ye...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
1b54f3692ba3-12
print(agent_chain.memory.buffer) Human: What is ChatGPT? AI: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large language models and is optimized for dialogue by using Reinforcement Learning with Human-in-the-Loop. It is a...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
f4c86f023527-0
.ipynb .pdf How to create ChatGPT Clone How to create 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, Prompt...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-1
llm=OpenAI(temperature=0), 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 o...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
f4c86f023527-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:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html
a2d96cfe6138-0
.ipynb .pdf How to use a timeout for the agent How to use a timeout for the agent# This notebook walks through how to cap an agent executor after a certain amount of time. This can be useful for safeguarding against long running agent runs. from langchain.agents import load_tools from langchain.agents import initialize...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_time_limit.html
a2d96cfe6138-1
Final Answer: foo > Finished chain. 'foo' Now let’s try it again with the max_execution_time=1 keyword argument. It now stops nicely after 1 second (only one iteration usually) agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, max_execution_time=1) agent.run(adversarial_pro...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_time_limit.html
c41cb8ca22ca-0
.ipynb .pdf How to use the async API for Agents Contents Serial vs. Concurrent Execution How to use the async API for Agents# LangChain provides async support for Agents by leveraging the asyncio library. Async methods are currently supported for the following Tools: SerpAPIWrapper and LLMMathChain. Async support for...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
c41cb8ca22ca-1
] llm = OpenAI(temperature=0) tools = load_tools(["llm-math", "serpapi"], llm=llm) agent = initialize_agent( tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True ) s = time.perf_counter() for q in questions: agent.run(q) elapsed = time.perf_counter() - s print(f"Serial executed in {elapsed:0.2f...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
c41cb8ca22ca-2
> Finished chain. > Entering new AgentExecutor chain... I need to find out who Olivia Wilde's boyfriend is and then calculate his age raised to the 0.23 power. Action: Search Action Input: "Olivia Wilde boyfriend" Observation: Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sud...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
c41cb8ca22ca-3
Thought: I now know the final answer Final Answer: Michael Schumacher, aged 54, raised to the 0.23 power is 2.502940725307012. > Finished chain. > Entering new AgentExecutor chain... I need to find out who won the US Open women's final in 2019 and then calculate her age raised to the 0.34 power. Action: Search Action ...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
c41cb8ca22ca-4
Thought: I now know the final answer Final Answer: Jay-Z is Beyonce's husband and his age raised to the 0.19 power is 2.12624064206896. > Finished chain. Serial executed in 52.47 seconds. llm = OpenAI(temperature=0) tools = load_tools(["llm-math", "serpapi"], llm=llm) agent = initialize_agent( tools, llm, agent=Age...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
c41cb8ca22ca-5
Action: Search Action Input: "US Open men's final 2019 winner" Observation: Rafael Nadal defeated Daniil Medvedev in the final, 7–5, 6–3, 5–7, 4–6, 6–4 to win the men's singles tennis title at the 2019 US Open. It was his fourth US ... Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his a...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
c41cb8ca22ca-6
Thought: I need to calculate her age raised to the 0.34 power Action: Calculator Action Input: 22^0.34 I need to calculate 53 raised to the 0.19 power Action: Calculator Action Input: 53^0.19 I need to calculate 29 raised to the 0.23 power. Action: Calculator Action Input: 29^0.23 I need to find out the age of the winn...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
c41cb8ca22ca-7
Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
44ae69215ad3-0
.ipynb .pdf How to combine agents and vectorstores Contents Create the Vectorstore Create the Agent Use the Agent solely as a router Multi-Hop vectorstore reasoning How to combine agents and vectorstores# This notebook covers how to combine agents and vectorstores. The use case for this is that you’ve ingested your d...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
44ae69215ad3-1
texts = text_splitter.split_documents(documents) embeddings = OpenAIEmbeddings() docsearch = Chroma.from_documents(texts, embeddings, collection_name="state-of-union") Running Chroma using direct local API. Using DuckDB in-memory for database. Data will be transient. state_of_union = RetrievalQA.from_chain_type(llm=llm...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
44ae69215ad3-2
), ] # Construct the agent. We will use the default agent type here. # See documentation for a full list of options. agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True) agent.run("What did biden say about ketanji brown jackson is the state of the union address?") > Entering n...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
44ae69215ad3-3
Action Input: What are the advantages of using ruff over flake8? Observation: Ruff can be used as a drop-in replacement for Flake8 when used (1) without or with a small number of plugins, (2) alongside Black, and (3) on Python 3 code. It also re-implements some of the most popular Flake8 plugins and related code quali...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
44ae69215ad3-4
Notice that in the above examples the agent did some extra work after querying the RetrievalQAChain. You can avoid that and just return the result directly. tools = [ Tool( name = "State of Union QA System", func=state_of_union.run, description="useful for when you need to answer questions a...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
44ae69215ad3-5
Action Input: What are the advantages of using ruff over flake8? Observation: Ruff can be used as a drop-in replacement for Flake8 when used (1) without or with a small number of plugins, (2) alongside Black, and (3) on Python 3 code. It also re-implements some of the most popular Flake8 plugins and related code quali...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
44ae69215ad3-6
Tool( name = "Ruff QA System", func=ruff.run, description="useful for when you need to answer questions about ruff (a python linter). Input should be a fully formed question, not referencing any obscure pronouns from the conversation before." ), ] # Construct the agent. We will use the defau...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
44ae69215ad3-7
previous Agent Executors next How to use the async API for Agents Contents Create the Vectorstore Create the Agent Use the Agent solely as a router Multi-Hop vectorstore reasoning By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
de7be484e8c1-0
.ipynb .pdf How to access intermediate steps How to access intermediate steps# In order to get more visibility into what an agent is doing, we can also return intermediate steps. This comes in the form of an extra key in the return value, which is a list of (action, observation) tuples. from langchain.agents import loa...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/intermediate_steps.html
de7be484e8c1-1
> Finished chain. # The actual return type is a NamedTuple for the agent action, and then an observation print(response["intermediate_steps"]) [(AgentAction(tool='Search', tool_input='Leo DiCaprio girlfriend', log=' I should look up who Leo DiCaprio is dating\nAction: Search\nAction Input: "Leo DiCaprio girlfriend"'), ...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/intermediate_steps.html
de7be484e8c1-2
], "Answer: 3.991298452658078\n" ] ] previous How to create ChatGPT Clone next How to cap the max number of iterations By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/intermediate_steps.html
f8cb0df45527-0
.ipynb .pdf How to cap the max number of iterations How to cap the max number of iterations# This notebook walks through how to cap an agent at taking a certain number of steps. This can be useful to ensure that they do not go haywire and take too many steps. from langchain.agents import load_tools from langchain.agent...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_iterations.html
f8cb0df45527-1
Final Answer: foo > Finished chain. 'foo' Now let’s try it again with the max_iterations=2 keyword argument. It now stops nicely after a certain amount of iterations! agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, max_iterations=2) agent.run(adversarial_prompt) > Enterin...
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_iterations.html
f8cb0df45527-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_iterations.html
ff8aa3da58f0-0
.rst .pdf Text Embedding Models Text Embedding Models# Note Conceptual Guide This documentation goes over how to use the Embedding class in LangChain. The Embedding class is a class designed for interfacing with embeddings. There are lots of Embedding providers (OpenAI, Cohere, Hugging Face, etc) - this class is design...
https:///python.langchain.com/en/latest/modules/models/text_embedding.html
dc066d0022c7-0
.rst .pdf LLMs LLMs# Note Conceptual Guide Large Language Models (LLMs) are a core component of LangChain. LangChain is not a provider of LLMs, but rather provides a standard interface through which you can interact with a variety of LLMs. The following sections of documentation are provided: Getting Started: An overvi...
https:///python.langchain.com/en/latest/modules/models/llms.html
56f3e22bb85f-0
.rst .pdf Chat Models Chat Models# Note Conceptual Guide Chat models are a variation on language models. While chat models use language models under the hood, the interface they expose is a bit different. Rather than expose a “text in, text out” API, they expose an interface where “chat messages” are the inputs and out...
https:///python.langchain.com/en/latest/modules/models/chat.html
9d5945d24789-0
.ipynb .pdf Sentence Transformers Embeddings Sentence Transformers Embeddings# SentenceTransformers embeddings are called using the HuggingFaceEmbeddings integration. We have also added an alias for SentenceTransformerEmbeddings for users who are more familiar with directly using that package. SentenceTransformers is a...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/sentence_transformers.html
c9521a55c862-0
.ipynb .pdf TensorflowHub TensorflowHub# Let’s load the TensorflowHub Embedding class. from langchain.embeddings import TensorflowHubEmbeddings embeddings = TensorflowHubEmbeddings() 2023-01-30 23:53:01.652176: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neu...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/tensorflowhub.html
1354c03ac35e-0
.ipynb .pdf SageMaker Endpoint Embeddings SageMaker Endpoint Embeddings# Let’s load the SageMaker Endpoints Embeddings class. The class can be used if you host, e.g. your own Hugging Face model on SageMaker. For instructions on how to do this, please see here. Note: In order to handle batched requests, you will need to...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/sagemaker-endpoint.html
1354c03ac35e-1
query_result = embeddings.embed_query("foo") doc_results = embeddings.embed_documents(["foo"]) doc_results previous OpenAI next Self Hosted Embeddings By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/sagemaker-endpoint.html
5b21c5d1fec9-0
.ipynb .pdf InstructEmbeddings InstructEmbeddings# Let’s load the HuggingFace instruct Embeddings class. from langchain.embeddings import HuggingFaceInstructEmbeddings embeddings = HuggingFaceInstructEmbeddings( query_instruction="Represent the query for retrieval: " ) load INSTRUCTOR_Transformer max_seq_length 51...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/instruct_embeddings.html
8aab9f71d72e-0
.ipynb .pdf Cohere Cohere# Let’s load the Cohere Embedding class. from langchain.embeddings import CohereEmbeddings embeddings = CohereEmbeddings(cohere_api_key=cohere_api_key) text = "This is a test document." query_result = embeddings.embed_query(text) doc_result = embeddings.embed_documents([text]) previous AzureOpe...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/cohere.html
4626c70bf315-0
.ipynb .pdf Aleph Alpha Contents Asymmetric Symmetric Aleph Alpha# There are two possible ways to use Aleph Alpha’s semantic embeddings. If you have texts with a dissimilar structure (e.g. a Document and a Query) you would want to use asymmetric embeddings. Conversely, for texts with comparable structures, symmetric ...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/aleph_alpha.html
fd614016e339-0
.ipynb .pdf AzureOpenAI AzureOpenAI# Let’s load the OpenAI Embedding class with environment variables set to indicate to use Azure endpoints. # set the environment variables needed for openai package to know to reach out to azure import os os.environ["OPENAI_API_TYPE"] = "azure" os.environ["OPENAI_API_BASE"] = "https:/...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/azureopenai.html
e9fb978e8ebe-0
.ipynb .pdf Fake Embeddings Fake Embeddings# LangChain also provides a fake embedding class. You can use this to test your pipelines. from langchain.embeddings import FakeEmbeddings embeddings = FakeEmbeddings(size=1352) query_result = embeddings.embed_query("foo") doc_results = embeddings.embed_documents(["foo"]) prev...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/fake.html
df14706483d9-0
.ipynb .pdf Llama-cpp Llama-cpp# This notebook goes over how to use Llama-cpp embeddings within LangChain !pip install llama-cpp-python from langchain.embeddings import LlamaCppEmbeddings llama = LlamaCppEmbeddings(model_path="/path/to/model/ggml-model-q4_0.bin") text = "This is a test document." query_result = llama.e...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/llamacpp.html
19ac4b46d863-0
.ipynb .pdf Self Hosted Embeddings Self Hosted Embeddings# Let’s load the SelfHostedEmbeddings, SelfHostedHuggingFaceEmbeddings, and SelfHostedHuggingFaceInstructEmbeddings classes. from langchain.embeddings import ( SelfHostedEmbeddings, SelfHostedHuggingFaceEmbeddings, SelfHostedHuggingFaceInstructEmbeddi...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/self-hosted.html
19ac4b46d863-1
tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id) return pipeline("feature-extraction", model=model, tokenizer=tokenizer) def inference_fn(pipeline, prompt): # Return last hidden state of the model if isinstance(prompt, list): return [emb[...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/self-hosted.html
04f2d69cf4d1-0
.ipynb .pdf Hugging Face Hub Hugging Face Hub# Let’s load the Hugging Face Embedding class. from langchain.embeddings import HuggingFaceEmbeddings embeddings = HuggingFaceEmbeddings() text = "This is a test document." query_result = embeddings.embed_query(text) doc_result = embeddings.embed_documents([text]) previous F...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/huggingfacehub.html
bc8e1b19f69b-0
.ipynb .pdf Jina Jina# Let’s load the Jina Embedding class. from langchain.embeddings import JinaEmbeddings embeddings = JinaEmbeddings(jina_auth_token=jina_auth_token, model_name="ViT-B-32::openai") text = "This is a test document." query_result = embeddings.embed_query(text) doc_result = embeddings.embed_documents([t...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/jina.html
8dd53b89bc43-0
.ipynb .pdf OpenAI OpenAI# Let’s load the OpenAI Embedding class. from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() text = "This is a test document." query_result = embeddings.embed_query(text) doc_result = embeddings.embed_documents([text]) Let’s load the OpenAI Embedding class with fir...
https:///python.langchain.com/en/latest/modules/models/text_embedding/examples/openai.html
aa3c07c6d8c7-0
.rst .pdf How-To Guides How-To Guides# The examples here all address certain “how-to” guides for working with chat models. How to use few shot examples How to stream responses previous Getting Started next How to use few shot examples By Harrison Chase © Copyright 2023, Harrison Chase. Last updated ...
https:///python.langchain.com/en/latest/modules/models/chat/how_to_guides.html
4c1121a0996b-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:///python.langchain.com/en/latest/modules/models/chat/getting_started.html
4c1121a0996b-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:///python.langchain.com/en/latest/modules/models/chat/getting_started.html
4c1121a0996b-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:///python.langchain.com/en/latest/modules/models/chat/getting_started.html
4c1121a0996b-3
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: Sparkling water, oh so fine A drink that's always on my mind With e...
https:///python.langchain.com/en/latest/modules/models/chat/getting_started.html
9d61c5046a2a-0
.rst .pdf Integrations Integrations# The examples here all highlight how to integrate with different chat models. Anthropic Azure OpenAI PromptLayer ChatOpenAI previous How to stream responses next Anthropic By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/models/chat/integrations.html
7fed9917aaca-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:///python.langchain.com/en/latest/modules/models/chat/integrations/promptlayer_chatopenai.html
7fed9917aaca-1
chat = PromptLayerChatOpenAI(return_pl_id=True) chat_results = chat.generate([[HumanMessage(content="I am a cat and I want")]]) for res in chat_results.generations: pl_request_id = res[0].generation_info["pl_request_id"] promptlayer.track.score(request_id=pl_request_id, score=100) Using this allows you to track...
https:///python.langchain.com/en/latest/modules/models/chat/integrations/promptlayer_chatopenai.html
f36b1a651334-0
.ipynb .pdf Azure Azure# This notebook goes over how to connect to an Azure hosted OpenAI endpoint from langchain.chat_models import AzureChatOpenAI from langchain.schema import HumanMessage BASE_URL = "https://${TODO}.openai.azure.com" API_KEY = "..." DEPLOYMENT_NAME = "chat" model = AzureChatOpenAI( openai_api_ba...
https:///python.langchain.com/en/latest/modules/models/chat/integrations/azure_chat_openai.html
21f49a0bd4a9-0
.ipynb .pdf Anthropic Contents ChatAnthropic also supports async and streaming functionality: Anthropic# This notebook covers how to get started with Anthropic chat models. from langchain.chat_models import ChatAnthropic from langchain.prompts.chat import ( ChatPromptTemplate, SystemMessagePromptTemplate, ...
https:///python.langchain.com/en/latest/modules/models/chat/integrations/anthropic.html
4d52752cd681-0
.ipynb .pdf OpenAI OpenAI# This notebook covers how to get started with OpenAI chat models. from langchain.chat_models import ChatOpenAI from langchain.prompts.chat import ( ChatPromptTemplate, SystemMessagePromptTemplate, AIMessagePromptTemplate, HumanMessagePromptTemplate, ) from langchain.schema impo...
https:///python.langchain.com/en/latest/modules/models/chat/integrations/openai.html
4d52752cd681-1
AIMessage(content="J'adore la programmation.", additional_kwargs={}) previous Azure next PromptLayer ChatOpenAI By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/models/chat/integrations/openai.html
d45faf2b7b47-0
.ipynb .pdf How to stream responses How to stream responses# 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.streaming_stdout import StreamingStdOutCallbackHandler chat = ChatOpenAI(s...
https:///python.langchain.com/en/latest/modules/models/chat/examples/streaming.html
d45faf2b7b47-1
previous How to use few shot examples next Integrations By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/models/chat/examples/streaming.html
fb9cd7ca768d-0
.ipynb .pdf How to use few shot examples Contents Alternating Human/AI messages System Messages How to use 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 abst...
https:///python.langchain.com/en/latest/modules/models/chat/examples/few_shot_examples.html
fb9cd7ca768d-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:///python.langchain.com/en/latest/modules/models/chat/examples/few_shot_examples.html
97f06f1eb7d4-0
.rst .pdf Generic Functionality Generic Functionality# The examples here all address certain “how-to” guides for working with LLMs. How to use the async API for LLMs How to write a custom LLM wrapper How (and why) to use the fake LLM How to cache LLM calls How to serialize LLM classes How to stream LLM and Chat Model r...
https:///python.langchain.com/en/latest/modules/models/llms/how_to_guides.html
7483212a5b12-0
.ipynb .pdf Getting Started Getting Started# This notebook goes over how to use the LLM class in LangChain. The LLM class is a class designed for interfacing with LLMs. There are lots of LLM providers (OpenAI, Cohere, Hugging Face, etc) - this class is designed to provide a standard interface for all of them. In this p...
https:///python.langchain.com/en/latest/modules/models/llms/getting_started.html
7483212a5b12-1
llm_result.generations[-1] [Generation(text="\n\nWhat if love neverspeech\n\nWhat if love never ended\n\nWhat if love was only a feeling\n\nI'll never know this love\n\nIt's not a feeling\n\nBut it's what we have for each other\n\nWe just know that love is something strong\n\nAnd we can't help but be happy\n\nWe just f...
https:///python.langchain.com/en/latest/modules/models/llms/getting_started.html
7483212a5b12-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 02, 2023.
https:///python.langchain.com/en/latest/modules/models/llms/getting_started.html