id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
49
117
4d470d1d6b0f-0
.ipynb .pdf How to create a custom prompt template Contents Why are custom prompt templates needed? Creating a Custom Prompt Template Use the custom prompt template How to create a custom prompt template# Let’s suppose we want the LLM to generate English language explanations of a function given its name. To achieve ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/custom_prompt_template.html
4d470d1d6b0f-1
import inspect def get_source_code(function_name): # Get the source code of the function return inspect.getsource(function_name) Next, we’ll create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function. from langchain.prompt...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/custom_prompt_template.html
4d470d1d6b0f-2
prompt = fn_explainer.format(function_name=get_source_code) print(prompt) Given the function name and source code, generate an English language explanation of the function. Function Name: get_source_code Source Code: def get_source_code(function_name): # Get the source code of the fu...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/custom_prompt_template.html
9d12d2748f06-0
.ipynb .pdf How to create a prompt template that uses few shot examples Contents Use Case Using an example set Create the example set Create a formatter for the few shot examples Feed examples and formatter to FewShotPromptTemplate Using an example selector Feed examples into ExampleSelector Feed example selector int...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
9d12d2748f06-1
"answer": """ Are follow up questions needed here: Yes. Follow up: Who was the founder of craigslist? Intermediate answer: Craigslist was founded by Craig Newmark. Follow up: When was Craig Newmark born? Intermediate answer: Craig Newmark was born on December 6, 1952. So the final answer is: December 6, 1952 """ }, ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
9d12d2748f06-2
print(example_prompt.format(**examples[0])) Question: Who lived longer, Muhammad Ali or Alan Turing? Are follow up questions needed here: Yes. Follow up: How old was Muhammad Ali when he died? Intermediate answer: Muhammad Ali was 74 years old when he died. Follow up: How old was Alan Turing when he died? Intermediate ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
9d12d2748f06-3
Are follow up questions needed here: Yes. Follow up: Who was the mother of George Washington? Intermediate answer: The mother of George Washington was Mary Ball Washington. Follow up: Who was the father of Mary Ball Washington? Intermediate answer: The father of Mary Ball Washington was Joseph Ball. So the final answer...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
9d12d2748f06-4
# This is the list of examples available to select from. examples, # This is the embedding class used to produce embeddings which are used to measure semantic similarity. OpenAIEmbeddings(), # This is the VectorStore class that is used to store the embeddings and do a similarity search over. Chroma,...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
9d12d2748f06-5
suffix="Question: {input}", input_variables=["input"] ) print(prompt.format(input="Who was the father of Mary Ball Washington?")) Question: Who was the maternal grandfather of George Washington? Are follow up questions needed here: Yes. Follow up: Who was the mother of George Washington? Intermediate answer: The m...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/few_shot_examples.html
6728745112bd-0
.ipynb .pdf How to serialize prompts Contents PromptTemplate Loading from YAML Loading from JSON Loading Template from a File FewShotPromptTemplate Examples Loading from YAML Loading from JSON Examples in the Config Example Prompt from a File PromptTempalte with OutputParser How to serialize prompts# It is often pref...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
6728745112bd-1
prompt = load_prompt("simple_prompt.yaml") print(prompt.format(adjective="funny", content="chickens")) Tell me a funny joke about chickens. Loading from JSON# This shows an example of loading a PromptTemplate from JSON. !cat simple_prompt.json { "_type": "prompt", "input_variables": ["adjective", "content"], ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
6728745112bd-2
output: sad - input: tall output: short Loading from YAML# This shows an example of loading a few shot example from YAML. !cat few_shot_prompt.yaml _type: few_shot input_variables: ["adjective"] prefix: Write antonyms for the following words. example_prompt: _type: prompt input_variables: ["i...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
6728745112bd-3
!cat few_shot_prompt.json { "_type": "few_shot", "input_variables": ["adjective"], "prefix": "Write antonyms for the following words.", "example_prompt": { "_type": "prompt", "input_variables": ["input", "output"], "template": "Input: {input}\nOutput: {output}" }, "exampl...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
6728745112bd-4
Output: short Input: funny Output: Example Prompt from a File# This shows an example of loading the PromptTemplate that is used to format the examples from a separate file. Note that the key changes from example_prompt to example_prompt_path. !cat example_prompt.json { "_type": "prompt", "input_variables": ["in...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
6728745112bd-5
"_type": "regex_parser" }, "partial_variables": {}, "template": "Given the following question and student answer, provide a correct answer and score the student answer.\nQuestion: {question}\nStudent Answer: {student_answer}\nCorrect Answer:", "template_format": "f-string", "validate_template": true...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/prompt_serialization.html
5f708b71e3a8-0
.ipynb .pdf Connecting to a Feature Store Contents Feast Load Feast Store Prompts Use in a chain Tecton Prerequisites Define and Load Features Prompts Use in a chain Featureform Initialize Featureform Prompts Use in a chain Connecting to a Feature Store# Feature stores are a concept from traditional machine learning ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
5f708b71e3a8-1
Note that the input to this prompt template is just driver_id, since that is the only user defined piece (all other variables are looked up inside the prompt template). from langchain.prompts import PromptTemplate, StringPromptTemplate template = """Given the driver's up to date stats, write them note relaying those st...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
5f708b71e3a8-2
Here are the drivers stats: Conversation rate: 0.4745151400566101 Acceptance rate: 0.055561766028404236 Average Daily Trips: 936 Your response: Use in a chain# We can now use this in a chain, successfully creating a chain that achieves personalization backed by a feature store from langchain.chat_models import ChatOpen...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
5f708b71e3a8-3
user_transaction_metrics = FeatureService( name = "user_transaction_metrics", features = [user_transaction_counts] ) The above Feature Service is expected to be applied to a live workspace. For this example, we will be using the “prod” workspace. import tecton workspace = tecton.get_workspace("prod") feature_se...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
5f708b71e3a8-4
kwargs["transaction_count_30d"] = feature_vector["user_transaction_counts.transaction_count_30d_1d"] return prompt.format(**kwargs) prompt_template = TectonPromptTemplate(input_variables=["user_id"]) print(prompt_template.format(user_id="user_469998441571")) Given the vendor's up to date transaction stats, writ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
5f708b71e3a8-5
client = ff.Client(host="demo.featureform.com") Prompts# Here we will set up a custom FeatureformPromptTemplate. This prompt template will take in the average amount a user pays per transactions. Note that the input to this prompt template is just avg_transaction, since that is the only user defined piece (all other va...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
5f708b71e3a8-6
Define and Load Features Prompts Use in a chain Featureform Initialize Featureform Prompts Use in a chain By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/connecting_to_a_feature_store.html
4747c14617fe-0
.ipynb .pdf How to work with partial Prompt Templates Contents Partial With Strings Partial With Functions How to work with partial Prompt Templates# A prompt template is a class with a .format method which takes in a key-value map and returns a string (a prompt) to pass to the language model. Like other methods, it ...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/partial.html
4747c14617fe-1
print(prompt.format(bar="baz")) foobaz Partial With Functions# The other common use is to partial with a function. The use case for this is when you have a variable you know that you always want to fetch in a common way. A prime example of this is with date or time. Imagine you have a prompt which you always want to ha...
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/partial.html
4747c14617fe-2
Contents Partial With Strings Partial With Functions By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/prompts/prompt_templates/examples/partial.html
cfb3a4d7b592-0
.rst .pdf Tools Tools# Note Conceptual Guide Tools are ways that an agent can use to interact with the outside world. For an overview of what a tool is, how to use them, and a full list of examples, please see the getting started documentation Getting Started Next, we have some examples of customizing and generically w...
https://python.langchain.com/en/latest/modules/agents/tools.html
1a8fae63f107-0
.rst .pdf Agent Executors Agent Executors# Note Conceptual Guide Agent executors take an agent and tools and use the agent to decide which tools to call and in what order. In this part of the documentation we cover other related functionality to agent executors How to combine agents and vectorstores How to use the asyn...
https://python.langchain.com/en/latest/modules/agents/agent_executors.html
fbc9222903af-0
.rst .pdf Agents Agents# Note Conceptual Guide In this part of the documentation we cover the different types of agents, disregarding which specific tools they are used with. For a high level overview of the different types of agents, see the below documentation. Agent Types For documentation on how to create a custom ...
https://python.langchain.com/en/latest/modules/agents/agents.html
5a06e7a3625f-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://python.langchain.com/en/latest/modules/agents/getting_started.html
5a06e7a3625f-1
agent = initialize_agent(tools, llm, agent=AgentType.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 calc...
https://python.langchain.com/en/latest/modules/agents/getting_started.html
3489238b6b9d-0
.rst .pdf Toolkits Toolkits# Note Conceptual Guide This section of documentation covers agents with toolkits - eg an agent applied to a particular use case. See below for a full list of agent toolkits Azure Cognitive Services Toolkit CSV Agent Gmail Toolkit Jira JSON Agent OpenAPI agents Natural Language APIs Pandas Da...
https://python.langchain.com/en/latest/modules/agents/toolkits.html
2b790bfa518c-0
.ipynb .pdf Plan and Execute Contents Plan and Execute Imports Tools Planner, Executor, and Agent Run Example Plan and Execute# Plan and execute agents accomplish an objective by first planning what to do, then executing the sub tasks. This idea is largely inspired by BabyAGI and then the “Plan-and-Solve” paper. The ...
https://python.langchain.com/en/latest/modules/agents/plan_and_execute.html
2b790bfa518c-1
> Entering new PlanAndExecute chain... steps=[Step(value="Search for Leo DiCaprio's girlfriend on the internet."), Step(value='Find her current age.'), Step(value='Raise her current age to the 0.43 power using a calculator or programming language.'), Step(value='Output the result.'), Step(value="Given the above steps t...
https://python.langchain.com/en/latest/modules/agents/plan_and_execute.html
2b790bfa518c-2
Current objective: value='Find her current age.' Action: ``` { "action": "Search", "action_input": "What is Gigi Hadid's current age?" } ``` Observation: 28 years Thought:Previous steps: steps=[(Step(value="Search for Leo DiCaprio's girlfriend on the internet."), StepResponse(response='Leo DiCaprio is currently lin...
https://python.langchain.com/en/latest/modules/agents/plan_and_execute.html
2b790bfa518c-3
Step: Raise her current age to the 0.43 power using a calculator or programming language. Response: Gigi Hadid's current age raised to the 0.43 power is approximately 4.19. > Entering new AgentExecutor chain... Action: ``` { "action": "Final Answer", "action_input": "The result is approximately 4.19." } ``` > Finis...
https://python.langchain.com/en/latest/modules/agents/plan_and_execute.html
601e26f5def5-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
601e26f5def5-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
601e26f5def5-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_iterations.html
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
46a76ee8d68e-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
f74222fe7dcd-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: GoogleSerperAPIWrapper, SerpAPIWrapper and LLMMath...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-1
] llm = OpenAI(temperature=0) tools = load_tools(["google-serper", "llm-math"], 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 {elapse...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-2
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 ... Draw: 128 (16 Q / 8 WC). Champion: Rafael Nadal. Runner-up: Daniil Medvedev. Score: 7–5, 6–3, 5–7, 4–6, 6–4. Bianca Andreescu won the women's singl...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-3
Daniil Medvedev in the men's singles final of the U.S. Open on Sunday. Rafael Nadal survived. The 33-year-old defeated Daniil Medvedev in the final of the 2019 U.S. Open to earn his 19th Grand Slam title Sunday ... NEW YORK -- Rafael Nadal defeated Daniil Medvedev in an epic five-set match, 7-5, 6-3, 5-7, 4-6, 6-4 to w...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-4
Thought: I now know that Rafael Nadal won the US Open men's final in 2019 and he is 33 years old. Action: Calculator Action Input: 33^0.334 Observation: Answer: 3.215019829667466 Thought: I now know the final answer. Final Answer: Rafael Nadal won the US Open men's final in 2019 and his age raised to the 0.334 power is...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-5
Action: Google Serper Action Input: "who won the most recent formula 1 grand prix" Observation: Max Verstappen won his first Formula 1 world title on Sunday after the championship was decided by a last-lap overtake of his rival Lewis Hamilton in the Abu Dhabi Grand Prix. Dec 12, 2021 Thought: I need to find out Max Ver...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-6
Observation: Answer: 2.7212987634680084 Thought: I now know the final answer. Final Answer: Nineteen-year-old Canadian Bianca Andreescu won the US Open women's final in 2019 and her age raised to the 0.34 power is 2.7212987634680084. > Finished chain. > Entering new AgentExecutor chain... I need to find out who Beyonc...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-7
await asyncio.gather(*tasks) elapsed = time.perf_counter() - s print(f"Concurrent executed in {elapsed:0.2f} seconds.") > Entering new AgentExecutor chain... > Entering new AgentExecutor chain... > Entering new AgentExecutor chain... > Entering new AgentExecutor chain... > Entering new AgentExecutor chain... I need to...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-8
Thought: Observation: Jay-Z Thought:
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-9
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 ... Draw: 128 (16 Q / 8 WC). Champion: Rafael Nadal. Runner-up: Daniil Medvedev. Score: 7–5, 6–3, 5–7, 4–6, 6–4. Bianca Andreescu won the women's singl...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-10
Daniil Medvedev in the men's singles final of the U.S. Open on Sunday. Rafael Nadal survived. The 33-year-old defeated Daniil Medvedev in the final of the 2019 U.S. Open to earn his 19th Grand Slam title Sunday ... NEW YORK -- Rafael Nadal defeated Daniil Medvedev in an epic five-set match, 7-5, 6-3, 5-7, 4-6, 6-4 to w...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-11
Thought: Observation: WHAT HAPPENED: #SheTheNorth? She the champion. Nineteen-year-old Canadian Bianca Andreescu sealed her first Grand Slam title on Saturday, downing 23-time major champion Serena Williams in the 2019 US Open women's singles final, 6-3, 7-5. Sep 7, 2019 Thought:
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-12
Thought: Observation: Lewis Hamilton holds the record for the most race wins in Formula One history, with 103 wins to date. Michael Schumacher, the previous record holder, ... Michael Schumacher (top left) and Lewis Hamilton (top right) have each won the championship a record seven times during their careers, while Seb...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-13
Action Input: "Harry Styles age" I need to find out Jay-Z's age Action: Google Serper Action Input: "How old is Jay-Z?" I now know that Rafael Nadal won the US Open men's final in 2019 and he is 33 years old. Action: Calculator Action Input: 33^0.334 I now need to calculate her age raised to the 0.34 power. Action: Cal...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
f74222fe7dcd-14
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html
d845e46e72a7-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
d845e46e72a7-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
02842065fe92-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
02842065fe92-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
02842065fe92-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 May 28, 2023.
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/intermediate_steps.html
5c6ad7ad4c2d-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...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
5c6ad7ad4c2d-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
c97d1a88ecee-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
c97d1a88ecee-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
c97d1a88ecee-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