id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
59
127
fd753cfa7acd-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 ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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 +-------------------------------------------------------------------------...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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 | |-------------------------------+----------------------+----------...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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\.\-]*//...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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 ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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_...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-20
1.8.1 ``` 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 opp...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
fd753cfa7acd-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html
b276e682fa8c-0
.ipynb .pdf How to add SharedMemory to an Agent and its Tools How to add SharedMemory to an Agent and its Tools# This notebook goes over adding memory to both of an Agent and its tools. Before going through this notebook, please walk through the following notebooks, as this will build on top of both of them: Adding mem...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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. ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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 ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-4
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. The organization is headquartered in S...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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. ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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 ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-10
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. The organization is headquartered in S...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
b276e682fa8c-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
42263efb3f14-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/intermediate_steps.html
42263efb3f14-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"'), ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/intermediate_steps.html
42263efb3f14-2
], "Answer: 3.991298452658078\n" ] ] previous Handle Parsing Errors next How to cap the max number of iterations By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/intermediate_steps.html
d054b4a865f0-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/max_iterations.html
d054b4a865f0-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/max_iterations.html
d054b4a865f0-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/max_iterations.html
f60a6093fad1-0
.ipynb .pdf Custom Agent with Tool Retrieval Contents Set up environment Set up tools Tool Retriever Prompt Template Output Parser Set up LLM, stop sequence, and the agent Use the Agent Custom Agent with Tool Retrieval# This notebook builds off of this notebook and assumes familiarity with how agents work. The novel ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent_with_tool_retrieval.html
f60a6093fad1-1
return "foo" fake_tools = [ Tool( name=f"foo-{i}", func=fake_func, description=f"a silly function that you can use to get more information about the number {i}" ) for i in range(99) ] ALL_TOOLS = [search_tool] + fake_tools Tool Retriever# We will use a vectorstore to create embedd...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent_with_tool_retrieval.html
f60a6093fad1-2
Tool(name='foo-95', description='a silly function that you can use to get more information about the number 95', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<function fake_func at 0x15e5bd1f0>, coroutine=None), Tool(name='foo-12', ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent_with_tool_retrieval.html
f60a6093fad1-3
Tool(name='foo-14', description='a silly function that you can use to get more information about the number 14', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<function fake_func at 0x15e5bd1f0>, coroutine=None), Tool(name='foo-11', ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent_with_tool_retrieval.html
f60a6093fad1-4
from typing import Callable # Set up a prompt template class CustomPromptTemplate(StringPromptTemplate): # The template to use template: str ############## NEW ###################### # The list of tools available tools_getter: Callable def format(self, **kwargs) -> str: # Get the in...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent_with_tool_retrieval.html
f60a6093fad1-5
class CustomOutputParser(AgentOutputParser): def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]: # Check if agent should finish if "Final Answer:" in llm_output: return AgentFinish( # Return values is generally always a dictionary with a single `outp...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent_with_tool_retrieval.html
f60a6093fad1-6
output_parser=output_parser, stop=["\nObservation:"], allowed_tools=tool_names ) Use the Agent# Now we can use it! agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True) agent_executor.run("What's the weather in SF?") > Entering new AgentExecutor chain... Thought: I need to...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent_with_tool_retrieval.html
d5370856e5a4-0
.md .pdf Agent Types Contents zero-shot-react-description react-docstore self-ask-with-search conversational-react-description Agent Types# 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. Here a...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/agent_types.html
d5370856e5a4-1
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/agent_types.html
a3b7dfe34c6b-0
.ipynb .pdf Custom MultiAction Agent Custom MultiAction Agent# This notebook goes through how to create your own custom agent. An agent consists of two parts: - Tools: The tools the agent has available to use. - The agent class itself: this decides which action to take. In this notebook we walk through how to create a ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_multi_action_agent.html
a3b7dfe34c6b-1
""" if len(intermediate_steps) == 0: return [ AgentAction(tool="Search", tool_input=kwargs["input"], log=""), AgentAction(tool="RandomWord", tool_input=kwargs["input"], log=""), ] else: return AgentFinish(return_values={"output": "bar"}...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_multi_action_agent.html
a3b7dfe34c6b-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_multi_action_agent.html
bb69775f855a-0
.ipynb .pdf Custom LLM Agent (with a ChatModel) Contents Set up environment Set up tool Prompt Template Output Parser Set up LLM Define the stop sequence Set up the Agent Use the Agent Custom LLM Agent (with a ChatModel)# This notebook goes through how to create your own custom agent based on a chat model. An LLM cha...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_chat_agent.html
bb69775f855a-1
!pip install langchain !pip install google-search-results !pip install openai from langchain.agents import Tool, AgentExecutor, LLMSingleActionAgent, AgentOutputParser from langchain.prompts import BaseChatPromptTemplate from langchain import SerpAPIWrapper, LLMChain from langchain.chat_models import ChatOpenAI from ty...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_chat_agent.html
bb69775f855a-2
Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can repeat N times) Thought: I now know the final answer Final Answer: the final answer to the original input question These were previous tasks you completed: Begin! Question: {input} {agent_sc...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_chat_agent.html
bb69775f855a-3
# This includes the `intermediate_steps` variable because that is needed input_variables=["input", "intermediate_steps"] ) Output Parser# The output parser is responsible for parsing the LLM output into AgentAction and AgentFinish. This usually depends heavily on the prompt used. This is where you can change the pa...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_chat_agent.html
bb69775f855a-4
Define the stop sequence# This is important because it tells the LLM when to stop generation. This depends heavily on the prompt and model you are using. Generally, you want this to be whatever token you use in the prompt to denote the start of an Observation (otherwise, the LLM may hallucinate an observation for you)....
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_chat_agent.html
bb69775f855a-5
Contents Set up environment Set up tool Prompt Template Output Parser Set up LLM Define the stop sequence Set up the Agent Use the Agent By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_chat_agent.html
40959c542930-0
.ipynb .pdf Custom Agent Custom Agent# This notebook goes through how to create your own custom agent. An agent consists of two parts: - Tools: The tools the agent has available to use. - The agent class itself: this decides which action to take. In this notebook we walk through how to create a custom agent. from langc...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent.html
40959c542930-1
Args: intermediate_steps: Steps the LLM has taken to date, along with observations **kwargs: User inputs. Returns: Action specifying what tool to use. """ return AgentAction(tool="Search", tool_input=kwargs["input"], log="") agent = FakeAgent()...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_agent.html
5538c5a59c67-0
.ipynb .pdf Custom MRKL Agent Contents Custom LLMChain Multiple inputs Custom MRKL Agent# This notebook goes through how to create your own custom MRKL agent. A MRKL agent consists of three parts: - Tools: The tools the agent has available to use. - LLMChain: The LLMChain that produces the text that is parsed in a ce...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_mrkl_agent.html
5538c5a59c67-1
input_variables: List of input variables the final prompt will expect. For this exercise, we will give our agent access to Google Search, and we will customize it in that we will have it answer as a pirate. from langchain.agents import ZeroShotAgent, Tool, AgentExecutor from langchain import OpenAI, SerpAPIWrapper, LLM...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_mrkl_agent.html
5538c5a59c67-2
Thought: I now know the final answer Final Answer: the final answer to the original input question Begin! Remember to speak as a pirate when giving your final answer. Use lots of "Args" Question: {input} {agent_scratchpad} Note that we are able to feed agents a self-defined prompt template, i.e. not restricted to the p...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_mrkl_agent.html
5538c5a59c67-3
Multiple inputs# Agents can also work with prompts that require multiple inputs. prefix = """Answer the following questions as best you can. You have access to the following tools:""" suffix = """When answering, you MUST speak in the following language: {language}. Question: {input} {agent_scratchpad}""" prompt = ZeroS...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_mrkl_agent.html
5538c5a59c67-4
Thought: I now know the final answer. Final Answer: La popolazione del Canada è stata stimata a 39.566.248 il 1° gennaio 2023, dopo un record di crescita demografica di 1.050.110 persone dal 1° gennaio 2022 al 1° gennaio 2023. > Finished chain. 'La popolazione del Canada è stata stimata a 39.566.248 il 1° gennaio 2023,...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_mrkl_agent.html
caa9a1cafbd9-0
.ipynb .pdf Custom LLM Agent Contents Set up environment Set up tool Prompt Template Output Parser Set up LLM Define the stop sequence Set up the Agent Use the Agent Adding Memory Custom LLM Agent# This notebook goes through how to create your own custom LLM agent. An LLM agent consists of three parts: PromptTemplate...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_agent.html
caa9a1cafbd9-1
from langchain.prompts import StringPromptTemplate from langchain import OpenAI, SerpAPIWrapper, LLMChain from typing import List, Union from langchain.schema import AgentAction, AgentFinish import re Set up tool# Set up any tools the agent may want to use. This may be necessary to put in the prompt (so that the agent ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_agent.html
caa9a1cafbd9-2
Question: {input} {agent_scratchpad}""" # Set up a prompt template class CustomPromptTemplate(StringPromptTemplate): # The template to use template: str # The list of tools available tools: List[Tool] def format(self, **kwargs) -> str: # Get the intermediate steps (AgentAction, Observat...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_agent.html
caa9a1cafbd9-3
class CustomOutputParser(AgentOutputParser): def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]: # Check if agent should finish if "Final Answer:" in llm_output: return AgentFinish( # Return values is generally always a dictionary with a single `outp...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_agent.html
caa9a1cafbd9-4
Set up the Agent# We can now combine everything to set up our agent # LLM chain consisting of the LLM and a prompt llm_chain = LLMChain(llm=llm, prompt=prompt) tool_names = [tool.name for tool in tools] agent = LLMSingleActionAgent( llm_chain=llm_chain, output_parser=output_parser, stop=["\nObservation:"],...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_agent.html
caa9a1cafbd9-5
{tools} Use the following format: Question: the input question you must answer Thought: you should always think about what to do Action: the action to take, should be one of [{tool_names}] Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can r...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_agent.html
caa9a1cafbd9-6
Thought: I need to find out the population of Canada in 2023 Action: Search Action Input: Population of Canada in 2023 Observation:The current population of Canada is 38,658,314 as of Wednesday, April 12, 2023, based on Worldometer elaboration of the latest United Nations data. I now know the final answer Final Answer:...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/custom_llm_agent.html
aece4a3f22ae-0
.ipynb .pdf Self Ask With Search Self Ask With Search# This notebook showcases the Self Ask With Search chain. from langchain import OpenAI, SerpAPIWrapper from langchain.agents import initialize_agent, Tool from langchain.agents import AgentType llm = OpenAI(temperature=0) search = SerpAPIWrapper() tools = [ Tool(...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/self_ask_with_search.html
ab711badc392-0
.ipynb .pdf Structured Tool Chat Agent Contents Initialize Tools Adding in memory Structured Tool Chat Agent# This notebook walks through using a chat agent capable of using multi-input tools. Older agents are configured to specify an action input as a single string, but this agent can use the provided tools’ args_sc...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-1
print(response) > Entering new AgentExecutor chain... Action: ``` { "action": "Final Answer", "action_input": "Hello Erica, how can I assist you today?" } ``` > Finished chain. Hello Erica, how can I assist you today? response = await agent_chain.arun(input="Don't need help really just chatting.") print(response) >...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-2
We recently open-sourced an auto-evaluator tool for grading LLM question-answer chains. We are now releasing an open source, free to use hosted app and API to expand usability. Below we discuss a few opportunities to further improve May 1, 2023 5 min read Callbacks Improvements TL;DR: We're announcing improvements to o...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-3
read Improving Document Retrieval with Contextual Compression Note: This post assumes some familiarity with LangChain and is moderately technical.
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-4
💡 TL;DR: We’ve introduced a new abstraction and a new document Retriever to facilitate the post-processing of retrieved documents. Specifically, the new abstraction makes it easy to take a set of retrieved documents and extract from them Apr 20, 2023 3 min read Autonomous Agents & Agent Simulations Over the past two w...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-5
Context Originally we designed LangChain.js to run in Node.js, which is the Apr 11, 2023 3 min read LangChain x Supabase Supabase is holding an AI Hackathon this week. Here at LangChain we are big fans of both Supabase and hackathons, so we thought this would be a perfect time to highlight the multiple ways you can use...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-6
The reason we like Supabase so much is that Apr 8, 2023 2 min read Announcing our $10M seed round led by Benchmark It was only six months ago that we released the first version of LangChain, but it seems like several years. When we launched, generative AI was starting to go mainstream: stable diffusion had just been re...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-7
becoming a bigger and bigger issue. People are starting to try to tackle this, with OpenAI releasing OpenAI/evals - focused on evaluating OpenAI models. Mar 14, 2023 3 min read LLMs and SQL Francisco Ingham and Jon Luo are two of the community members leading the change on the SQL integrations. We’re really excited to ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-8
Authors: Parth Asawa (pgasawa@), Ayushi Batwara (ayushi.batwara@), Jason Mar 8, 2023 4 min read Prompt Selectors One common complaint we've heard is that the default prompt templates do not work equally well for all models. This became especially pronounced this past week when OpenAI released a ChatGPT API. This new AP...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-9
What does this mean? It means that all your favorite prompts, chains, and agents are all recreatable in TypeScript natively. Both the Python version and TypeScript version utilize the same serializable format, meaning that artifacts can seamlessly be shared between languages. As an Feb 17, 2023 2 min read Streaming Sup...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-10
"url": "https://xkcd.com/" } } ``` Observation: Navigating to https://xkcd.com/ returned status code 200 Thought:I can extract the latest comic title and alt text using CSS selectors. Action: ``` { "action": "get_elements", "action_input": { "selector": "#ctitle, #comic img", "attributes": ["alt", "src"] ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
ab711badc392-11
Action: ``` { "action": "Final Answer", "action_input": "Hi Erica! How can I assist you today?" } ``` > Finished chain. Hi Erica! How can I assist you today? response = await agent_chain.arun(input="whats my name?") print(response) > Entering new AgentExecutor chain... Your name is Erica. > Finished chain. Your nam...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/structured_chat.html
c5dd632db396-0
.ipynb .pdf MRKL MRKL# This notebook showcases using an agent to replicate the MRKL chain. This uses the example Chinook database. To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at the root of this repository. from langchain import L...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/mrkl.html
c5dd632db396-1
> Entering new AgentExecutor chain... I need to find out who Leo DiCaprio's girlfriend is and then calculate her age raised to the 0.43 power. Action: Search Action Input: "Who is Leo DiCaprio's girlfriend?" Observation: DiCaprio met actor Camila Morrone in December 2017, when she was 20 and he was 43. They were spott...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/mrkl.html
c5dd632db396-2
> Entering new AgentExecutor chain... I need to find out the artist's full name and then search the FooBar database for their albums. Action: Search Action Input: "The Storm Before the Calm" artist Observation: The Storm Before the Calm (stylized in all lowercase) is the tenth (and eighth international) studio album b...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/mrkl.html
c5dd632db396-3
Thought: I now know the final answer. Final Answer: The artist who released the album 'The Storm Before the Calm' is Alanis Morissette and the albums of hers in the FooBar database are Jagged Little Pill. > Finished chain. "The artist who released the album 'The Storm Before the Calm' is Alanis Morissette and the album...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/mrkl.html
2c72351a49e5-0
.ipynb .pdf MRKL Chat MRKL Chat# This notebook showcases using an agent to replicate the MRKL chain using an agent optimized for chat models. This uses the example Chinook database. To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at t...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/mrkl_chat.html
2c72351a49e5-1
mrkl.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?") > Entering new AgentExecutor chain... Thought: The first question requires a search, while the second question requires a calculator. Action: ``` { "action": "Search", "action_input": "Leo DiCaprio girlfriend" } ``` Obse...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/mrkl_chat.html
2c72351a49e5-2
mrkl.run("What is the full name of the artist who recently released an album called 'The Storm Before the Calm' and are they in the FooBar database? If so, what albums of theirs are in the FooBar database?") > Entering new AgentExecutor chain... Question: What is the full name of the artist who recently released an alb...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/mrkl_chat.html
2c72351a49e5-3
sample_rows = connection.execute(command) SELECT "Title" FROM "Album" WHERE "ArtistId" IN (SELECT "ArtistId" FROM "Artist" WHERE "Name" = 'Alanis Morissette') LIMIT 5; SQLResult: [('Jagged Little Pill',)] Answer: Alanis Morissette has the album Jagged Little Pill in the database. > Finished chain. Observation: Alanis...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/mrkl_chat.html
b935a0e3e3b9-0
.ipynb .pdf OpenAI Functions Agent OpenAI Functions Agent# This notebook showcases using an agent that uses the OpenAI functions ability from langchain import LLMMathChain, OpenAI, SerpAPIWrapper, SQLDatabase, SQLDatabaseChain from langchain.agents import initialize_agent, Tool from langchain.agents import AgentType fr...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/openai_functions_agent.html
b935a0e3e3b9-1
Invoking: `Search` with `{'query': 'Leo DiCaprio girlfriend'}` Amidst his casual romance with Gigi, Leo allegedly entered a relationship with 19-year old model, Eden Polani, in February 2023. Invoking: `Calculator` with `{'expression': '19^0.43'}` > Entering new chain... 19^0.43```text 19**0.43 ``` ...numexpr.evaluate...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/openai_functions_agent.html
e01f4ab2f8a4-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...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/conversational_agent.html
e01f4ab2f8a4-1
AI: Your name is Bob! > Finished chain. 'Your name is Bob!' agent_chain.run("what are some good dinners to make this week, if i like thai food?") > Entering new AgentExecutor chain... Thought: Do I need to use a tool? Yes Action: Current Search Action Input: Thai food dinner recipes Observation: 59 easy Thai recipes fo...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/conversational_agent.html
e01f4ab2f8a4-2
> Finished chain. 'The last letter in your name is "b" and the winner of the 1978 World Cup was the Argentina national football team.' agent_chain.run(input="whats the current temperature in pomfret?") > Entering new AgentExecutor chain... Thought: Do I need to use a tool? Yes Action: Current Search Action Input: Curre...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/conversational_agent.html
23428999a524-0
.ipynb .pdf Conversation Agent (for Chat Models) Conversation Agent (for Chat Models)# This notebook walks through using an agent optimized for conversation, using ChatModels. 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 w...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/chat_conversation_agent.html
23428999a524-1
> Entering new AgentExecutor chain... { "action": "Final Answer", "action_input": "Hello Bob! How can I assist you today?" } > Finished chain. 'Hello Bob! How can I assist you today?' agent_chain.run(input="what's my name?") > Entering new AgentExecutor chain... { "action": "Final Answer", "action_input...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/chat_conversation_agent.html
23428999a524-2
> Entering new AgentExecutor chain... { "action": "Final Answer", "action_input": "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 weather like in pomfret?"...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/chat_conversation_agent.html
09d9c6010b5c-0
.ipynb .pdf ReAct ReAct# This notebook showcases using an agent to implement the ReAct logic. from langchain import OpenAI, Wikipedia from langchain.agents import initialize_agent, Tool from langchain.agents import AgentType from langchain.agents.react.base import DocstoreExplorer docstore=DocstoreExplorer(Wikipedia())...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/react.html
09d9c6010b5c-1
Action: Search[David Chanoff] Observation: David Chanoff is a noted author of non-fiction work. His work has typically involved collaborations with the principal protagonist of the work concerned. His collaborators have included; Augustus A. White, Joycelyn Elders, Đoàn Văn Toại, William J. Crowe, Ariel Sharon, Kenneth...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents/examples/react.html
c329467e5576-0
.ipynb .pdf Multi-Input Tools Contents Multi-Input Tools with a string format Multi-Input Tools# This notebook shows how to use a tool that requires multiple inputs with an agent. The recommended way to do so is with the StructuredTool class. import os os.environ["LANGCHAIN_TRACING"] = "true" from langchain import Op...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/tools/multi_input_tool.html
c329467e5576-1
'3 times 4 is 12' Multi-Input Tools with a string format# An alternative to the structured tool would be to use the regular Tool class and accept a single string. The tool would then have to handle the parsing logic to extract the relavent values from the text, which tightly couples the tool representation to the agent...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/tools/multi_input_tool.html
c329467e5576-2
> 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 Defining Custom Tools next Tool Input Schema Contents Multi-Input Tools with a st...
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/tools/multi_input_tool.html