id stringlengths 14 16 | text stringlengths 29 2.73k | source stringlengths 49 117 |
|---|---|---|
66457d097e58-4 | 'Ive Tim Cook Angela Ahrendts',
'Date': '1976 - present'},
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS3liELlhrMz3Wpsox29U8jJ3L8qETR0hBWHXbFnwjwQc34zwZvFELst2E&s',
'position': 3},
{'title': 'AAPL: Apple Inc Stock Price Quote -... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-5 | 'snippet': 'Find the latest Apple Inc. (AAPL) stock quote, '
'history, news and other vital information to help '
'you with your stock trading and investing.',
'position': 6}],
'peopleAlsoAsk': [{'question': 'What does Apple Inc do?',
... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-6 | 'title': 'Apple Inc Company Profile - Apple Inc Overview - '
'GlobalData',
'link': 'https://www.globaldata.com/company-profile/apple-inc/'},
{'question': 'Who runs Apple Inc?',
'snippet': 'Timothy Donald Cook (born November 1, 1960)... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-7 | 'images': [{'title': 'Lion - Wikipedia',
'imageUrl': 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Lion_waiting_in_Namibia.jpg/1200px-Lion_waiting_in_Namibia.jpg',
'imageWidth': 1200,
'imageHeight': 900,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-8 | 'position': 2},
{'title': 'African lion, facts and photos',
'imageUrl': 'https://i.natgeofe.com/n/487a0d69-8202-406f-a6a0-939ed3704693/african-lion.JPG',
'imageWidth': 3072,
'imageHeight': 2043,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-9 | 'thumbnailWidth': 225,
'thumbnailHeight': 225,
'source': 'St. Louis Zoo',
'domain': 'stlzoo.org',
'link': 'https://stlzoo.org/animals/mammals/carnivores/lion',
'position': 4},
{'title': 'How to Draw a Realistic Lion like an Artist - Studio '
... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-10 | 'imageWidth': 1600,
'imageHeight': 1085,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSCqaKY_THr0IBZN8c-2VApnnbuvKmnsWjfrwKoWHFR9w3eN5o&s',
'thumbnailWidth': 273,
'thumbnailHeight': 185,
'source': 'Encyclopedia Britannica',
... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-11 | 'thumbnailHeight': 168,
'source': 'USA Today',
'domain': 'www.usatoday.com',
'link': 'https://www.usatoday.com/story/news/2023/01/08/where-do-lions-live-habitat/10927718002/',
'position': 7},
{'title': 'Lion',
'imageUrl': 'https://i.natgeofe.c... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-12 | 'imageWidth': 1400,
'imageHeight': 845,
'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSgB3z_D4dMEOWJ7lajJk4XaQSL4DdUvIRj4UXZ0YoE5fGuWuo&s',
'thumbnailWidth': 289,
'thumbnailHeight': 174,
'source': "Smithsonian's National Zoo",... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-13 | Searching for Google News#
We can also query Google News using this wrapper. For example:
search = GoogleSerperAPIWrapper(type="news")
results = search.results("Tesla Inc.")
pprint.pp(results)
{'searchParameters': {'q': 'Tesla Inc.',
'gl': 'us',
'hl': 'en',
... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-14 | 'quarterly earnings after it...',
'date': '1 day ago',
'source': 'Reuters',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4u4CP8aOdGyRFH6o4PkXi-_eZDeY96vLSag5gDjhKMYf98YBER2cZPbkStQ&s',
'position': 2},
{'title': 'Tesla Wanted an EV Price War. F... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-15 | 'contract extension to deliver up to nine air taxis to '
'the U.S. Air Force,...',
'date': '4 hours ago',
'source': 'Yahoo Finance',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQO0uVn297LI-xryrPNqJ-apUOulj4ohM-xkN4OfmvMOYh1CPdUEBbYx6hviw&s',
... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-16 | 'snippet': 'Tesla has reopened orders for the Model 3 Long Range '
'RWD, which has been unavailable for months due to high '
'demand.',
'date': '7 hours ago',
'source': 'Not a Tesla App',
'imageUrl': 'https://encrypted-tbn0.gstatic.com/images?... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-17 | 'Business Journal',
'link': 'https://www.bizjournals.com/austin/news/2023/05/02/tesla-leases-building-seattle-area.html',
'snippet': 'Check out what Puget Sound Business Journal has to '
"report about the Austin-based company's real estate "
'footprint i... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-18 | 'position': 9}]}
If you want to only receive news articles published in the last hour, you can do the following:
search = GoogleSerperAPIWrapper(type="news", tbs="qdr:h")
results = search.results("Tesla Inc.")
pprint.pp(results)
{'searchParameters': {'q': 'Tesla Inc.',
'gl': 'us',
... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-19 | 'snippet': 'Ryder System Inc. presentó RyderElectric+ TM como su '
'nueva solución llave en mano ... Ryder también tiene '
'reservados los semirremolques Tesla y continúa...',
'date': '56 mins ago',
'source': 'Revista Transportes y Turismo',
'... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-20 | 'position': 3}]}
Some examples of the tbs parameter:
qdr:h (past hour)
qdr:d (past day)
qdr:w (past week)
qdr:m (past month)
qdr:y (past year)
You can specify intermediate time periods by adding a number:
qdr:h12 (past 12 hours)
qdr:d3 (past 3 days)
qdr:w2 (past 2 weeks)
qdr:m6 (past 6 months)
qdr:m2 (past 2 years)
For... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-21 | 'ratingCount': 91,
'category': 'Italian'},
{'position': 2,
'title': "Tony's Di Napoli",
'address': '1081 3rd Ave',
'latitude': 40.7643567,
'longitude': -73.9642373,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipNbNv6j... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-22 | 'longitude': -73.950351,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipNPCpCPuqPAb1Mv6_fOP7cjb8Wu1rbqbk2sMBlh=w92-h92-n-k-no',
'rating': 4.5,
'ratingCount': 140,
'category': 'Italian'},
{'position': 5,
'title': "Paola's",
... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-23 | 'address': '1606 1st Ave.',
'latitude': 40.7750785,
'longitude': -73.9504801,
'thumbnailUrl': 'https://lh5.googleusercontent.com/p/AF1QipPPN5GXxfH3NDacBc0Pt3uGAInd9OChS5isz9RF=w92-h92-n-k-no',
'rating': 4.4,
'ratingCount': 152,
'category': 'I... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
66457d097e58-24 | 'rating': 4.5,
'ratingCount': 113,
'category': 'Italian'},
{'position': 10,
'title': 'Barbaresco',
'address': '843 Lexington Ave #1',
'latitude': 40.7654332,
'longitude': -73.9656873,
'thumbnailUrl': 'https://lh5.goog... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_serper.html |
6d8665f11b06-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 |
6d8665f11b06-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 |
6d8665f11b06-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 |
6d8665f11b06-3 | Action Input: What are the advantages of using ruff over flake8?
Observation: Ruff can be used as a drop-in replacement for Flake8 when used (1) without or with a small number of plugins, (2) alongside Black, and (3) on Python 3 code. It also re-implements some of the most popular Flake8 plugins and related code quali... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
6d8665f11b06-4 | Notice that in the above examples the agent did some extra work after querying the RetrievalQAChain. You can avoid that and just return the result directly.
tools = [
Tool(
name = "State of Union QA System",
func=state_of_union.run,
description="useful for when you need to answer questions a... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
6d8665f11b06-5 | Action: Ruff QA System
Action Input: What are the advantages of using ruff over flake8?
Observation: Ruff can be used as a drop-in replacement for Flake8 when used (1) without or with a small number of plugins, (2) alongside Black, and (3) on Python 3 code. It also re-implements some of the most popular Flake8 plugins... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
6d8665f11b06-6 | name = "Ruff QA System",
func=ruff.run,
description="useful for when you need to answer questions about ruff (a python linter). Input should be a fully formed question, not referencing any obscure pronouns from the conversation before."
),
]
# Construct the agent. We will use the default agent type ... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
6d8665f11b06-7 | previous
Agent Executors
next
How to use the async API for Agents
Contents
Create the Vectorstore
Create the Agent
Use the Agent solely as a router
Multi-Hop vectorstore reasoning
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 02, 2023. | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html |
5f154bcf6ae2-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 |
5f154bcf6ae2-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 |
5f154bcf6ae2-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 02, 2023. | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/intermediate_steps.html |
00114c124644-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 |
00114c124644-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 |
00114c124644-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 |
00114c124644-3 | “super happy to be back in the ... Watch the full match between Daniil Medvedev and Rafael ... Duration: 4:47:32. Posted: Mar 20, 2020. US Open 2019: Rafael Nadal beats Daniil Medvedev · Updated: Sep. 08, 2019, 11:11 p.m. |; Published: Sep · Published: Sep. 08, 2019, 10:06 p.m.. 26. US Open ... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
00114c124644-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 |
00114c124644-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 |
00114c124644-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 |
00114c124644-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 |
00114c124644-8 | Thought:
Observation: Jay-Z
Thought: | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
00114c124644-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 |
00114c124644-10 | “super happy to be back in the ... Watch the full match between Daniil Medvedev and Rafael ... Duration: 4:47:32. Posted: Mar 20, 2020. US Open 2019: Rafael Nadal beats Daniil Medvedev · Updated: Sep. 08, 2019, 11:11 p.m. |; Published: Sep · Published: Sep. 08, 2019, 10:06 p.m.. 26. US Open ... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
00114c124644-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 |
00114c124644-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 |
00114c124644-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 |
00114c124644-14 | By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 02, 2023. | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/async_agent.html |
a6bda261bd0f-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 |
a6bda261bd0f-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 |
a6bda261bd0f-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 |
a6bda261bd0f-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 |
a6bda261bd0f-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... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a6bda261bd0f-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 |
a6bda261bd0f-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 |
a6bda261bd0f-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 |
a6bda261bd0f-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 |
a6bda261bd0f-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 |
a6bda261bd0f-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... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/sharedmemory_for_tools.html |
a6bda261bd0f-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 |
a6bda261bd0f-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-9 | output = chatgpt_chain.predict(human_input=docker_input)
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 explanation... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
3bc9b649e044-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 |
08437481b4d5-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 |
08437481b4d5-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 |
08437481b4d5-2 | By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 02, 2023. | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/max_iterations.html |
0381bdb66be1-0 | .ipynb
.pdf
Handle Parsing Errors
Contents
Setup
Error
Default error handling
Custom Error Message
Custom Error Function
Handle Parsing Errors#
Occasionally the LLM cannot determine what step to take because it outputs format in incorrect form to be handled by the output parser. In this case, by default the agent err... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html |
0381bdb66be1-1 | IndexError: list index out of range
During handling of the above exception, another exception occurred:
OutputParserException Traceback (most recent call last)
Cell In[4], line 1
----> 1 mrkl.run("Who is Leo DiCaprio's girlfriend? No need to add Action")
File ~/workplace/langchain/langchain/chains/b... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html |
0381bdb66be1-2 | 136 else self._call(inputs)
137 )
138 except (KeyboardInterrupt, Exception) as e:
139 run_manager.on_chain_error(e)
File ~/workplace/langchain/langchain/agents/agent.py:947, in AgentExecutor._call(self, inputs, run_manager)
945 # We now enter the agent loop (until it returns something).
... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html |
0381bdb66be1-3 | 759 """
760 try:
761 # Call the LLM to see what to do.
--> 762 output = self.agent.plan(
763 intermediate_steps,
764 callbacks=run_manager.get_child() if run_manager else None,
765 **inputs,
766 )
767 except OutputParserException as e:
768 if isins... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html |
0381bdb66be1-4 | > Entering new AgentExecutor chain...
Observation: Invalid or incomplete response
Thought:
Observation: Invalid or incomplete response
Thought:Search for Leo DiCaprio's current girlfriend
Action:
```
{
"action": "Search",
"action_input": "Leo DiCaprio current girlfriend"
}
```
Observation: Just Jared on Instagram: ... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html |
0381bdb66be1-5 | Thought:The answer to the question is that Leo DiCaprio's current girlfriend is Gigi Hadid.
Final Answer: Gigi Hadid.
> Finished chain.
'Gigi Hadid.'
Custom Error Function#
You can also customize the error to be a function that takes the error in and outputs a string.
def _handle_error(error) -> str:
return str(er... | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html |
0381bdb66be1-6 | Error
Default error handling
Custom Error Message
Custom Error Function
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 02, 2023. | https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html |
9daf61ed0088-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 |
9daf61ed0088-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 |
ead928f7d320-0 | .ipynb
.pdf
OpenAPI agents
Contents
1st example: hierarchical planning agent
To start, let’s collect some OpenAPI specs.
How big is this spec?
Let’s see some examples!
Try another API.
2nd example: “json explorer” agent
OpenAPI agents#
We can construct agents to consume arbitrary APIs, here APIs conformant to the Ope... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
ead928f7d320-1 | !mv openapi.yaml spotify_openapi.yaml
--2023-03-31 15:45:56-- https://raw.githubusercontent.com/openai/openai-openapi/master/openapi.yaml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.111.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercont... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.