id stringlengths 14 16 | text stringlengths 31 3.14k | source stringlengths 58 124 |
|---|---|---|
0c0a31d0e70a-2 | conversation_with_summary.predict(input="Just working on writing some documentation!")
> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not kno... | /content/https://python.langchain.com/en/latest/modules/memory/types/summary_buffer.html |
0c0a31d0e70a-3 | # We can see here that the summary and the buffer are updated
conversation_with_summary.predict(input="Haha nope, although a lot of people confuse it for that")
> Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and ... | /content/https://python.langchain.com/en/latest/modules/memory/types/summary_buffer.html |
4cfc887466c3-0 | .ipynb
.pdf
Conversation Knowledge Graph Memory
Contents
Using in a chain
Conversation Knowledge Graph Memory#
This type of memory uses a knowledge graph to recreate memory.
Let’s first walk through how to use the utilities
from langchain.memory import ConversationKGMemory
from langchain.llms import OpenAI
llm = Open... | /content/https://python.langchain.com/en/latest/modules/memory/types/kg.html |
4cfc887466c3-1 | We can also more modularly get current entities from a new message (will use previous messages as context.)
memory.get_current_entities("what's Sams favorite color?")
['Sam']
We can also more modularly get knowledge triplets from a new message (will use previous messages as context.)
memory.get_knowledge_triplets("her ... | /content/https://python.langchain.com/en/latest/modules/memory/types/kg.html |
4cfc887466c3-2 | > Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context.
If the AI does not know the answer to a question, it truthfully says it does not know. The AI ONLY uses info... | /content/https://python.langchain.com/en/latest/modules/memory/types/kg.html |
4cfc887466c3-3 | > Entering new ConversationChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context.
If the AI does not know the answer to a question, it truthfully says it does not know. The AI ONLY uses info... | /content/https://python.langchain.com/en/latest/modules/memory/types/kg.html |
d3efb8835a6c-0 | .ipynb
.pdf
ConversationSummaryMemory
Contents
Using in a chain
ConversationSummaryMemory#
Now let’s take a look at using a slightly more complex type of memory - ConversationSummaryMemory. This type of memory creates a summary of the conversation over time. This can be useful for condensing information from the conv... | /content/https://python.langchain.com/en/latest/modules/memory/types/summary.html |
d3efb8835a6c-1 | messages = memory.chat_memory.messages
previous_summary = ""
memory.predict_new_summary(messages, previous_summary)
'\nThe human greets the AI, to which the AI responds.'
Using in a chain#
Let’s walk through an example of using this in a chain, again setting verbose=True so we can see the prompt.
from langchain.llms im... | /content/https://python.langchain.com/en/latest/modules/memory/types/summary.html |
d3efb8835a6c-2 | Current conversation:
The human greeted the AI and asked how it was doing. The AI replied that it was doing great and was currently helping a customer with a technical issue.
Human: Tell me more about it!
AI:
> Finished chain.
" Sure! The customer is having trouble with their computer not connecting to the internet. I'... | /content/https://python.langchain.com/en/latest/modules/memory/types/summary.html |
d3efb8835a6c-3 | previous
Conversation Knowledge Graph Memory
next
ConversationSummaryBufferMemory
Contents
Using in a chain
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Apr 26, 2023. | /content/https://python.langchain.com/en/latest/modules/memory/types/summary.html |
6be23a87284c-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... | /content/https://python.langchain.com/en/latest/modules/agents/tools.html |
4ccc2c13e6f3-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 ... | /content/https://python.langchain.com/en/latest/modules/agents/agents.html |
bcdd90034647-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... | /content/https://python.langchain.com/en/latest/modules/agents/getting_started.html |
bcdd90034647-1 | tools = load_tools(["serpapi", "llm-math"], llm=llm)
Finally, let’s initialize an agent with the tools, the language model, and the type of agent we want to use.
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 girlfr... | /content/https://python.langchain.com/en/latest/modules/agents/getting_started.html |
a981b1884fa6-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors.html |
839f94b64533-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
CSV Agent
Jira
JSON Agent
OpenAPI agents
Natural Language APIs
Pandas Dataframe Agent
PowerBI Dataset Agent
Python Agen... | /content/https://python.langchain.com/en/latest/modules/agents/toolkits.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-1 | tools = [
Tool(
name = "Search",
func=search.run,
description="useful for when you need to answer questions about current events"
),
Tool(
name = "Summary",
func=summry_chain.run,
description="useful for when you summarize a conversation. The input to this too... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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 ... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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 yo... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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 ... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a7c5c9a36c87-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
bf59173e7f46-0 | .ipynb
.pdf
How to use the async API for Agents
Contents
Serial vs. Concurrent Execution
Using Tracing with Asynchronous Agents
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: SerpAPIWrap... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-1 | "Who won the most recent formula 1 grand prix? What is their age raised to the 0.23 power?",
"Who won the US Open women's final in 2019? What is her age raised to the 0.34 power?",
"Who is Beyonce's husband? What is his age raised to the 0.19 power?"
]
def generate_serially():
for q in questions:
ll... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-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: Jason Sudeikis
Thought: I need to find out Jason Sudeikis' age
Action: Search
Action Input: ... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-3 | Action: Search
Action Input: "US Open women's final 2019 winner"
Observation: Bianca Andreescu defeated Serena Williams in the final, 6–3, 7–5 to win the women's singles tennis title at the 2019 US Open. It was her first major title, and she became the first Canadian, as well as the first player born in the 2000s, to w... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-4 | > Finished chain.
Serial executed in 65.11 seconds.
async def generate_concurrently():
agents = []
# To make async requests in Tools more efficient, you can pass in your own aiohttp.ClientSession,
# but you must manually close the client session at the end of your program/event loop
aiosession = Client... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-5 | > Entering new AgentExecutor chain...
> Entering new AgentExecutor chain...
> Entering new AgentExecutor 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" I need to... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-6 | 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:
Observation: 47 years
Thought: I need to find out Max Verstappen's age
Acti... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-7 | 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.
I now know the final answer
Final Answer: Max Verstappen, 25 years old, raised to the 0.23 power is 1.84599359907945.
> Finished chain.
Observation: Answer: 3.309825... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-8 | tracer = LangChainTracer()
tracer.load_default_session()
manager = CallbackManager([StdOutCallbackHandler(), tracer])
# Pass the manager into the llm if you want llm calls traced.
llm = OpenAI(temperature=0, callback_manager=manager)
async_tools = load_tools(["llm-math", "serpapi"], llm=llm, aiosession=aiosession)
asyn... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
bf59173e7f46-9 | > Finished chain.
previous
How to combine agents and vectorstores
next
How to create ChatGPT Clone
Contents
Serial vs. Concurrent Execution
Using Tracing with Asynchronous Agents
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Apr 26, 2023. | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
9edabe1573c8-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
9edabe1573c8-1 | loader = TextLoader(doc_path)
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
docsearch = Chroma.from_documents(texts, embeddings, collection_name="state-of-union")
Running Chroma using dir... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
9edabe1573c8-2 | from langchain.agents import AgentType
from langchain.tools import BaseTool
from langchain.llms import OpenAI
from langchain import LLMMathChain, SerpAPIWrapper
tools = [
Tool(
name = "State of Union QA System",
func=state_of_union.run,
description="useful for when you need to answer questio... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
9edabe1573c8-3 | > Finished chain.
"Biden said that Jackson is one of the nation's top legal minds and that she will continue Justice Breyer's legacy of excellence."
agent.run("Why use ruff over flake8?")
> Entering new AgentExecutor chain...
I need to find out the advantages of using ruff over flake8
Action: Ruff QA System
Action Inp... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
9edabe1573c8-4 | > Finished chain.
'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 quality tools natively, including isort, yesqa, eradicate, and mo... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
9edabe1573c8-5 | > Entering new AgentExecutor chain...
I need to find out what Biden said about Ketanji Brown Jackson in the State of the Union address.
Action: State of Union QA System
Action Input: What did Biden say about Ketanji Brown Jackson in the State of the Union address?
Observation: Biden said that Jackson is one of the na... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
9edabe1573c8-6 | > Finished chain.
' 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 quality tools natively, including isort, yesqa, eradicate, and m... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
9edabe1573c8-7 | agent.run("What tool does ruff use to run over Jupyter Notebooks? Did the president mention that tool in the state of the union?")
> Entering new AgentExecutor chain...
I need to find out what tool ruff uses to run over Jupyter Notebooks, and if the president mentioned it in the state of the union.
Action: Ruff QA Sys... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
5afcb9573f46-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_time_limit.html |
5afcb9573f46-1 | Action: Jester
Action Input: foo
Observation: foo
Thought: I now know the final answer
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.ZER... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_time_limit.html |
5afcb9573f46-2 | 'foo'
previous
How to cap the max number of iterations
next
How to add SharedMemory to an Agent and its Tools
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Apr 26, 2023. | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_time_limit.html |
05ad68808b05-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/intermediate_steps.html |
05ad68808b05-1 | Observation: Answer: 3.991298452658078
Thought: I now know the final answer
Final Answer: Camila Morrone is Leo DiCaprio's girlfriend and she is 3.991298452658078 years old.
> Finished chain.
# The actual return type is a NamedTuple for the agent action, and then an observation
print(response["intermediate_steps"])
[(A... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/intermediate_steps.html |
05ad68808b05-2 | ],
"Camila Morrone"
],
[
[
"Search",
"Camila Morrone age",
" I should look up how old Camila Morrone is\nAction: Search\nAction Input: \"Camila Morrone age\""
],
"25 years"
],
[
[
"Calculator",
"25^0.43",
" I should calculate what 25 years raised to the 0.... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/intermediate_steps.html |
25d82493a280-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_iterations.html |
25d82493a280-1 | Thought: Is there more I can do?
Action: Jester
Action Input: foo
Observation: foo
Thought: I now know the final answer
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, l... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_iterations.html |
25d82493a280-2 | I should try Jester again
Action: Jester
Action Input: foo
Observation: foo is not a valid tool, try another one.
Final Answer: Jester is the tool to use for this question.
> Finished chain.
'Jester is the tool to use for this question.'
previous
How to access intermediate steps
next
How to use a timeout for the agent
... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_iterations.html |
1eca45abd753-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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-1 | Assistant:"""
prompt = PromptTemplate(
input_variables=["history", "human_input"],
template=template
)
chatgpt_chain = LLMChain(
llm=OpenAI(temperature=0),
prompt=prompt,
verbose=True,
memory=ConversationBufferWindowMemory(k=2),
)
output = chatgpt_chain.predict(human_input="I want you to act... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-2 | 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 ... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-3 | 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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-4 | Assistant:
> Finished LLMChain chain.
```
$ ls ~
Desktop Documents Downloads Music Pictures Public Templates Videos
```
output = chatgpt_chain.predict(human_input="cd ~")
print(output)
> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.
Assistant is de... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-5 | 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 ... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-6 | 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 ... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-7 | > 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 language model, Assis... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-8 | ```
Human: echo -e "x=lambda y:y*5+3;print('Result:' + str(x(6)))" > run.py && python3 run.py
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: al... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-9 | 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: {Please make a file jok... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-10 | $ python3 run.py
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
```
docker_input = """echo -e "echo 'Hello from Docker" > entrypoint.sh && echo -e "FROM ubuntu:20.04\nCOPY entrypoint.sh entrypoint.sh\nENTRYPOINT [\"/bin/sh\",\"entrypoint.sh\"]">Dockerfile && docker build . -t my_docker_image && docker run -t my_docker_image"""
o... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-11 | 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: echo -e "x=lambda y:y*5... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-12 | Assistant:
> Finished LLMChain chain.
```
$ echo -e "echo 'Hello from Docker" > entrypoint.sh
$ echo -e "FROM ubuntu:20.04
COPY entrypoint.sh entrypoint.sh
ENTRYPOINT ["/bin/sh","entrypoint.sh"]">Dockerfile
$ docker build . -t my_docker_image
$ docker run -t my_docker_image
Hello from Docker
```
output = chatgpt_chain.... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-13 | 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: echo -e "print(list(fil... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-14 | Hello from Docker
```
Human: nvidia-smi
Assistant:
> Finished LLMChain chain.
```
$ nvidia-smi
Sat May 15 21:45:02 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 |
|-------------------------------+... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-15 | 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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-16 | $ echo -e "FROM ubuntu:20.04
COPY entrypoint.sh entrypoint.sh
ENTRYPOINT ["/bin/sh","entrypoint.sh"]">Dockerfile
$ docker build . -t my_docker_image
$ docker run -t my_docker_image
Hello from Docker
```
Human: nvidia-smi
AI:
```
$ nvidia-smi
Sat May 15 21:45:02 2021
+--------------------------------------------... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-17 | 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 transmitted, 3 packets received, 0.0% packet los... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-18 | 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 ... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-19 | +-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-20 | 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... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-21 | --- 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
```
Human: curl -fsSL "https://api.github.com/repos/pytorch/pytorch/releases/latest" | jq -r '.tag_name' | sed 's/[^0-9\.\-]*//g'
AI:
```
$ curl -fsSL "https://api.g... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-22 | > 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 language model, Assis... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-23 | AI:
```
$ curl -fsSL "https://api.github.com/repos/pytorch/pytorch/releases/latest" | jq -r '.tag_name' | sed 's/[^0-9\.\-]*//g'
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 intell... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-24 | </p>
</body>
</html>
```
output = chatgpt_chain.predict(human_input="""curl --header "Content-Type:application/json" --request POST --data '{"message": "What is artificial intelligence?"}' https://chat.openai.com/chat""")
print(output)
> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large lan... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-25 | ```
$ 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 opportunities in research, engineering, product, and operations... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-26 | {
"response": "Artificial intelligence (AI) is the simulation of human intelligence processes by machines, especially computer systems. These processes include learning (the acquisition of information and rules for using the information), reasoning (using the rules to reach approximate or definite conclusions) and se... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-27 | 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 ... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-28 | {
"response": "Artificial intelligence (AI) is the simulation of human intelligence processes by machines, especially computer systems. These processes include learning (the acquisition of information and rules for using the information), reasoning (using the rules to reach approximate or definite conclusions) and se... | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
1eca45abd753-29 | {
"response": "```\n/current/working/directory\n```"
}
```
previous
How to use the async API for Agents
next
How to access intermediate steps
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Apr 26, 2023. | /content/https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
a99fb7434c8c-0 | .ipynb
.pdf
Defining Custom Tools
Contents
Completely New Tools
Tool dataclass
Subclassing the BaseTool class
Using the tool decorator
Modify existing tools
Defining the priorities among Tools
Using tools to return directly
Multi-argument tools
Defining Custom Tools#
When constructing your own agent, you will need to... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-1 | search = SerpAPIWrapper()
llm_math_chain = LLMMathChain(llm=llm, verbose=True)
tools = [
Tool(
name = "Search",
func=search.run,
description="useful for when you need to answer questions about current events"
),
]
# You can also define an args_schema to provide more information about inp... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-2 | ```
...numexpr.evaluate("25**(0.43)")...
Answer: 3.991298452658078
> Finished chain.
Answer: 3.991298452658078I now know the final answer
Final Answer: 3.991298452658078
> Finished chain.
'3.991298452658078'
Subclassing the BaseTool class#
from typing import Type
class CustomSearchTool(BaseTool):
name = "Search"
... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-3 | tools = [CustomSearchTool(), CustomCalculatorTool()]
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
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 Leo DiCaprio's gi... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-4 | from langchain.agents import tool
@tool
def search_api(query: str) -> str:
"""Searches the API for the query."""
return f"Results for query {query}"
search_api
Tool(name='search_api', description='search_api(query: str) -> str - Searches the API for the query.', args_schema=<class 'pydantic.main.SearchApi'>, re... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-5 | You can also provide args_schema to provide more information about the argument
class SearchInput(BaseModel):
query: str = Field(description="should be a search query")
@tool("search", return_direct=True, args_schema=SearchInput)
def search_api(query: str) -> str:
"""Searches the API for the query."""
... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-6 | > Entering new AgentExecutor chain...
I need to find out Leo DiCaprio's girlfriend's name and her age.
Action: Google Search
Action Input: "Leo DiCaprio girlfriend"I draw the lime at going to get a Mohawk, though." DiCaprio broke up with girlfriend Camila Morrone, 25, in the summer of 2022, after dating for four years.... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-7 | from langchain import LLMMathChain, SerpAPIWrapper
search = SerpAPIWrapper()
tools = [
Tool(
name = "Search",
func=search.run,
description="useful for when you need to answer questions about current events"
),
Tool(
name="Music Search",
func=lambda x: "'All I Want For... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-8 | Tool(
name="Calculator",
func=llm_math_chain.run,
description="useful for when you need to answer questions about math",
return_direct=True
)
]
llm = OpenAI(temperature=0)
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
agent.run("whats... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-9 | # Regex pattern to match arguments and their values
pattern = r"(\w+)\s*=\s*(None|\"[^\"]*\"|\d+)"
matches = re.findall(pattern, action_input)
if not matches:
raise ValueError(f"Could not parse action input: `{action_input}`")
# Create a dictionary with the parsed ar... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-10 | match = re.search(regex, llm_output, re.DOTALL)
if not match:
raise ValueError(f"Could not parse LLM output: `{llm_output}`")
action = match.group(1).strip()
action_input = match.group(2)
tool_input = self.parse_tool_input(action_input)
# Return the action and action ... | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
a99fb7434c8c-11 | Using tools to return directly
Multi-argument tools
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Apr 26, 2023. | /content/https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html |
ce026599302c-0 | .ipynb
.pdf
Multi-Input Tools
Multi-Input Tools#
This notebook shows how to use a tool that requires multiple inputs with an agent.
The difficulty in doing so comes from the fact that an agent decides its next step from a language model, which outputs a string. So if that step requires multiple inputs, they need to be ... | /content/https://python.langchain.com/en/latest/modules/agents/tools/multi_input_tool.html |
ce026599302c-1 | Tool(
name = "Multiplier",
func=parsing_multiplier,
description="useful for when you need to multiply two numbers together. The input to this tool should be a comma separated list of numbers of length two, representing the two numbers you want to multiply together. For example, `1,2` would be th... | /content/https://python.langchain.com/en/latest/modules/agents/tools/multi_input_tool.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.