id stringlengths 14 16 | text stringlengths 36 2.73k | source stringlengths 49 117 |
|---|---|---|
ae4dc0ad56c8-1 | By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/agents/agents/agent_types.html |
0405a16ff569-0 | .ipynb
.pdf
Structured Tool Chat Agent
Contents
Initialize Tools
Adding in memory
Structured Tool Chat Agent#
This notebook walks through using a chat agent capable of using multi-input tools.
Older agents are configured to specify an action input as a single string, but this agent can use the provided tools’ args_sc... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-1 | print(response)
> Entering new AgentExecutor chain...
Action:
```
{
"action": "Final Answer",
"action_input": "Hello Erica, how can I assist you today?"
}
```
> Finished chain.
Hello Erica, how can I assist you today?
response = await agent_chain.arun(input="Don't need help really just chatting.")
print(response)
>... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-2 | We recently open-sourced an auto-evaluator tool for grading LLM question-answer chains. We are now releasing an open source, free to use hosted app and API to expand usability. Below we discuss a few opportunities to further improve May 1, 2023 5 min read Callbacks Improvements TL;DR: We're announcing improvements to o... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-3 | discussions around a single agent. If multiple Apr 28, 2023 4 min read Gradio & LLM Agents Editor's note: this is a guest blog post from Freddy Boulton, a software engineer at Gradio. We're excited to share this post because it brings a large number of exciting new tools into the ecosystem. Agents are largely defined b... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-4 | 💡 TL;DR: We’ve introduced a new abstraction and a new document Retriever to facilitate the post-processing of retrieved documents. Specifically, the new abstraction makes it easy to take a set of retrieved documents and extract from them Apr 20, 2023 3 min read Autonomous Agents & Agent Simulations Over the past two w... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-5 | Context
Originally we designed LangChain.js to run in Node.js, which is the Apr 11, 2023 3 min read LangChain x Supabase Supabase is holding an AI Hackathon this week. Here at LangChain we are big fans of both Supabase and hackathons, so we thought this would be a perfect time to highlight the multiple ways you can use... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-6 | The reason we like Supabase so much is that Apr 8, 2023 2 min read Announcing our $10M seed round led by Benchmark It was only six months ago that we released the first version of LangChain, but it seems like several years. When we launched, generative AI was starting to go mainstream: stable diffusion had just been re... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-7 | This is done with the goals of (1) allowing retrievers constructed elsewhere to be used more easily in LangChain, (2) encouraging more experimentation with alternative Mar 23, 2023 4 min read LangChain + Zapier Natural Language Actions (NLA) We are super excited to team up with Zapier and integrate their new Zapier NLA... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-8 | Ingham and Jon Luo are two of the community members leading the change on the SQL integrations. We’re really excited to write this blog post with them going over all the tips and tricks they’ve learned doing so. We’re even more excited to announce that we’ Mar 13, 2023 8 min read Origin Web Browser [Editor's Note]: Thi... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-9 | Authors: Parth Asawa (pgasawa@), Ayushi Batwara (ayushi.batwara@), Jason Mar 8, 2023 4 min read Prompt Selectors One common complaint we've heard is that the default prompt templates do not work equally well for all models. This became especially pronounced this past week when OpenAI released a ChatGPT API. This new AP... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-10 | What does this mean? It means that all your favorite prompts, chains, and agents are all recreatable in TypeScript natively. Both the Python version and TypeScript version utilize the same serializable format, meaning that artifacts can seamlessly be shared between languages. As an Feb 17, 2023 2 min read Streaming Sup... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-11 | "url": "https://xkcd.com/"
}
}
```
Observation: Navigating to https://xkcd.com/ returned status code 200
Thought:I can extract the latest comic title and alt text using CSS selectors.
Action:
```
{
"action": "get_elements",
"action_input": {
"selector": "#ctitle, #comic img",
"attributes": ["alt", "src"]
... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
0405a16ff569-12 | Action:
```
{
"action": "Final Answer",
"action_input": "Hi Erica! How can I assist you today?"
}
```
> Finished chain.
Hi Erica! How can I assist you today?
response = await agent_chain.arun(input="whats my name?")
print(response)
> Entering new AgentExecutor chain...
Your name is Erica.
> Finished chain.
Your nam... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
493c58bcc1dc-0 | .ipynb
.pdf
Self Ask With Search
Self Ask With Search#
This notebook showcases the Self Ask With Search chain.
from langchain import OpenAI, SerpAPIWrapper
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType
llm = OpenAI(temperature=0)
search = SerpAPIWrapper()
tools = [
Tool(... | https://python.langchain.com/en/latest/modules/agents/agents/examples/self_ask_with_search.html |
3bace757096a-0 | .ipynb
.pdf
MRKL Chat
MRKL Chat#
This notebook showcases using an agent to replicate the MRKL chain using an agent optimized for chat models.
This uses the example Chinook database.
To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at t... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html |
3bace757096a-1 | mrkl.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?")
> Entering new AgentExecutor chain...
Thought: The first question requires a search, while the second question requires a calculator.
Action:
```
{
"action": "Search",
"action_input": "Leo DiCaprio girlfriend"
}
```
Obse... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html |
3bace757096a-2 | mrkl.run("What is the full name of the artist who recently released an album called 'The Storm Before the Calm' and are they in the FooBar database? If so, what albums of theirs are in the FooBar database?")
> Entering new AgentExecutor chain...
Question: What is the full name of the artist who recently released an alb... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html |
3bace757096a-3 | sample_rows = connection.execute(command)
SELECT "Title" FROM "Album" WHERE "ArtistId" IN (SELECT "ArtistId" FROM "Artist" WHERE "Name" = 'Alanis Morissette') LIMIT 5;
SQLResult: [('Jagged Little Pill',)]
Answer: Alanis Morissette has the album Jagged Little Pill in the database.
> Finished chain.
Observation: Alanis... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html |
d989b53699dc-0 | .ipynb
.pdf
ReAct
ReAct#
This notebook showcases using an agent to implement the ReAct logic.
from langchain import OpenAI, Wikipedia
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType
from langchain.agents.react.base import DocstoreExplorer
docstore=DocstoreExplorer(Wikipedia())... | https://python.langchain.com/en/latest/modules/agents/agents/examples/react.html |
d989b53699dc-1 | Action: Search[David Chanoff]
Observation: David Chanoff is a noted author of non-fiction work. His work has typically involved collaborations with the principal protagonist of the work concerned. His collaborators have included; Augustus A. White, Joycelyn Elders, Đoàn Văn Toại, William J. Crowe, Ariel Sharon, Kenneth... | https://python.langchain.com/en/latest/modules/agents/agents/examples/react.html |
1fe945f658e5-0 | .ipynb
.pdf
Conversation Agent (for Chat Models)
Conversation Agent (for Chat Models)#
This notebook walks through using an agent optimized for conversation, using ChatModels. Other agents are often optimized for using tools to figure out the best response, which is not ideal in a conversational setting where you may w... | https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html |
1fe945f658e5-1 | > Entering new AgentExecutor chain...
{
"action": "Final Answer",
"action_input": "Hello Bob! How can I assist you today?"
}
> Finished chain.
'Hello Bob! How can I assist you today?'
agent_chain.run(input="what's my name?")
> Entering new AgentExecutor chain...
{
"action": "Final Answer",
"action_input... | https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html |
1fe945f658e5-2 | > Entering new AgentExecutor chain...
{
"action": "Final Answer",
"action_input": "The last letter in your name is 'b'. Argentina won the World Cup in 1978."
}
> Finished chain.
"The last letter in your name is 'b'. Argentina won the World Cup in 1978."
agent_chain.run(input="whats the weather like in pomfret?"... | https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html |
d97b2743cbba-0 | .ipynb
.pdf
Conversation Agent
Conversation Agent#
This notebook walks through using an agent optimized for conversation. Other agents are often optimized for using tools to figure out the best response, which is not ideal in a conversational setting where you may want the agent to be able to chat with the user as well... | https://python.langchain.com/en/latest/modules/agents/agents/examples/conversational_agent.html |
d97b2743cbba-1 | AI: Your name is Bob!
> Finished chain.
'Your name is Bob!'
agent_chain.run("what are some good dinners to make this week, if i like thai food?")
> Entering new AgentExecutor chain...
Thought: Do I need to use a tool? Yes
Action: Current Search
Action Input: Thai food dinner recipes
Observation: 59 easy Thai recipes fo... | https://python.langchain.com/en/latest/modules/agents/agents/examples/conversational_agent.html |
d97b2743cbba-2 | > Finished chain.
'The last letter in your name is "b" and the winner of the 1978 World Cup was the Argentina national football team.'
agent_chain.run(input="whats the current temperature in pomfret?")
> Entering new AgentExecutor chain...
Thought: Do I need to use a tool? Yes
Action: Current Search
Action Input: Curre... | https://python.langchain.com/en/latest/modules/agents/agents/examples/conversational_agent.html |
b8dd81005168-0 | .ipynb
.pdf
MRKL
MRKL#
This notebook showcases using an agent to replicate the MRKL chain.
This uses the example Chinook database.
To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at the root of this repository.
from langchain import L... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html |
b8dd81005168-1 | > Entering new AgentExecutor chain...
I need to find out who Leo DiCaprio's girlfriend is and then calculate her age raised to the 0.43 power.
Action: Search
Action Input: "Who is Leo DiCaprio's girlfriend?"
Observation: DiCaprio met actor Camila Morrone in December 2017, when she was 20 and he was 43. They were spott... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html |
b8dd81005168-2 | > Entering new AgentExecutor chain...
I need to find out the artist's full name and then search the FooBar database for their albums.
Action: Search
Action Input: "The Storm Before the Calm" artist
Observation: The Storm Before the Calm (stylized in all lowercase) is the tenth (and eighth international) studio album b... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html |
b8dd81005168-3 | Thought: I now know the final answer.
Final Answer: The artist who released the album 'The Storm Before the Calm' is Alanis Morissette and the albums of hers in the FooBar database are Jagged Little Pill.
> Finished chain.
"The artist who released the album 'The Storm Before the Calm' is Alanis Morissette and the album... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html |
bed64a41511d-0 | .ipynb
.pdf
Vectorstore Agent
Contents
Create the Vectorstores
Initialize Toolkit and Agent
Examples
Multiple Vectorstores
Examples
Vectorstore Agent#
This notebook showcases an agent designed to retrieve information from one or more vectorstores, either with or without sources.
Create the Vectorstores#
from langchai... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/vectorstore.html |
bed64a41511d-1 | )
vectorstore_info = VectorStoreInfo(
name="state_of_union_address",
description="the most recent state of the Union adress",
vectorstore=state_of_union_store
)
toolkit = VectorStoreToolkit(vectorstore_info=vectorstore_info)
agent_executor = create_vectorstore_agent(
llm=llm,
toolkit=toolkit,
ve... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/vectorstore.html |
bed64a41511d-2 | Action Input: What did biden say about ketanji brown jackson
Observation: {"answer": " Biden said that he nominated Circuit Court of Appeals Judge Ketanji Brown Jackson to the United States Supreme Court, and that she is one of the nation's top legal minds who will continue Justice Breyer's legacy of excellence.\n", "s... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/vectorstore.html |
bed64a41511d-3 | toolkit=router_toolkit,
verbose=True
)
Examples#
agent_executor.run("What did biden say about ketanji brown jackson is the state of the union address?")
> Entering new AgentExecutor chain...
I need to use the state_of_union_address tool to answer this question.
Action: state_of_union_address
Action Input: What did... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/vectorstore.html |
bed64a41511d-4 | Thought: I now know the final answer
Final Answer: Ruff is integrated into nbQA, a tool for running linters and code formatters over Jupyter Notebooks. After installing ruff and nbqa, you can run Ruff over a notebook like so: > nbqa ruff Untitled.ipynb
> Finished chain.
'Ruff is integrated into nbQA, a tool for running... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/vectorstore.html |
bed64a41511d-5 | previous
SQL Database Agent
next
Agent Executors
Contents
Create the Vectorstores
Initialize Toolkit and Agent
Examples
Multiple Vectorstores
Examples
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/vectorstore.html |
971d6aff4be7-0 | .ipynb
.pdf
Spark SQL Agent
Contents
Initialization
Example: describing a table
Example: running queries
Spark SQL Agent#
This notebook shows how to use agents to interact with a Spark SQL. Similar to SQL Database Agent, it is designed to address general inquiries about Spark SQL and facilitate error recovery.
NOTE: ... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-1 | +-----------+--------+------+--------------------+------+----+-----+-----+----------------+-------+-----+--------+
| 1| 0| 3|Braund, Mr. Owen ...| male|22.0| 1| 0| A/5 21171| 7.25| null| S|
| 2| 1| 1|Cumings, Mrs. Joh...|female|38.0| 1| 0| PC 17599... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-2 | | 7| 0| 1|McCarthy, Mr. Tim...| male|54.0| 0| 0| 17463|51.8625| E46| S|
| 8| 0| 3|Palsson, Master. ...| male| 2.0| 3| 1| 349909| 21.075| null| S|
| 9| 1| 3|Johnson, Mrs. Osc...|female|27.0| 0| 2| 347742... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-3 | | 14| 0| 3|Andersson, Mr. An...| male|39.0| 1| 5| 347082| 31.275| null| S|
| 15| 0| 3|Vestrom, Miss. Hu...|female|14.0| 0| 0| 350406| 7.8542| null| S|
| 16| 1| 2|Hewlett, Mrs. (Ma...|female|55.0| 0| 0| 248706... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-4 | only showing top 20 rows
# Note, you can also connect to Spark via Spark connect. For example:
# db = SparkSQL.from_uri("sc://localhost:15002", schema=schema)
spark_sql = SparkSQL(schema=schema)
llm = ChatOpenAI(temperature=0)
toolkit = SparkSQLToolkit(db=spark_sql, llm=llm)
agent_executor = create_spark_sql_agent(
... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-5 | 3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.925 None S
*/
Thought:I now know the schema and sample rows for the titanic table.
Final Answer: The titanic table has the following columns: PassengerId (INT), Survived (INT), Pclass (INT), Name (STRING), Sex (STRING), Age (DOUBLE), SibSp (INT), Parch (IN... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-6 | > Finished chain.
'The titanic table has the following columns: PassengerId (INT), Survived (INT), Pclass (INT), Name (STRING), Sex (STRING), Age (DOUBLE), SibSp (INT), Parch (INT), Ticket (STRING), Fare (DOUBLE), Cabin (STRING), and Embarked (STRING). Here are some sample rows from the table: \n\n1. PassengerId: 1, Su... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-7 | Action: list_tables_sql_db
Action Input:
Observation: titanic
Thought:I should check the schema of the titanic table to see if there is an age column.
Action: schema_sql_db
Action Input: titanic
Observation: CREATE TABLE langchain_example.titanic (
PassengerId INT,
Survived INT,
Pclass INT,
Name STRING,
Sex ... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-8 | SELECT SQRT(AVG(Age)) as square_root_of_avg_age FROM titanic
Thought:The query is correct, so I can execute it to find the square root of the average age.
Action: query_sql_db
Action Input: SELECT SQRT(AVG(Age)) as square_root_of_avg_age FROM titanic
Observation: [('5.449689683556195',)]
Thought:I now know the final an... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
971d6aff4be7-9 | 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38.0 1 0 PC 17599 71.2833 C85 C
3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.925 None S
*/
Thought:I can use the titanic table to find the oldest survived passenger. I will query the Name and Age columns, filtering by Survived and order... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html |
7d2e64dc8fd5-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 |
7d2e64dc8fd5-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 |
7d2e64dc8fd5-2 | --2023-03-31 15:45:57-- https://raw.githubusercontent.com/APIs-guru/openapi-directory/main/APIs/spotify.com/1.0.0/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.githubusercontent.com)|18... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-3 | You’ll have to set up an application in the Spotify developer console, documented here, to get credentials: CLIENT_ID, CLIENT_SECRET, and REDIRECT_URI.
To get an access tokens (and keep them fresh), you can implement the oauth flows, or you can use spotipy. If you’ve set your Spotify creedentials as environment variabl... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-4 | from langchain.agents.agent_toolkits.openapi import planner
llm = OpenAI(model_name="gpt-4", temperature=0.0)
/Users/jeremywelborn/src/langchain/langchain/llms/openai.py:169: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: `from langchain.chat_mo... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-5 | Thought:I have the plan, now I need to execute the API calls.
Action: api_controller
Action Input: 1. GET /search to search for the album "Kind of Blue"
2. GET /albums/{id}/tracks to get the tracks from the "Kind of Blue" album
3. GET /me to get the current user's information
4. POST /users/{user_id}/playlists to creat... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-6 | Thought:Action: requests_post
Action Input: {"url": "https://api.spotify.com/v1/users/22rhrz4m4kvpxlsb5hezokzwi/playlists", "data": {"name": "Machine Blues"}, "output_instructions": "Extract the id of the created playlist"}
Observation: 7lzoEi44WOISnFYlrAIqyX
Thought:Action: requests_post
Action Input: {"url": "https:/... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-7 | user_query = "give me a song I'd like, make it blues-ey"
spotify_agent.run(user_query)
> Entering new AgentExecutor chain...
Action: api_planner
Action Input: I need to find the right API calls to get a blues song recommendation for the user
Observation: 1. GET /me to get the current user's information
2. GET /recommen... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-8 | Observation: acoustic, afrobeat, alt-rock, alternative, ambient, anime, black-metal, bluegrass, blues, bossanova, brazil, breakbeat, british, cantopop, chicago-house, children, chill, classical, club, comedy, country, dance, dancehall, death-metal, deep-house, detroit-techno, disco, disney, drum-and-bass, dub, dubstep,... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-9 | Observation: [
{
id: '03lXHmokj9qsXspNsPoirR',
name: 'Get Away Jordan'
}
]
Thought:I am finished executing the plan.
Final Answer: The recommended blues song for user Jeremy Welborn (ID: 22rhrz4m4kvpxlsb5hezokzwi) is "Get Away Jordan" with the track ID: 03lXHmokj9qsXspNsPoirR.
> Finished chain.
Observation:... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-10 | > Entering new AgentExecutor chain...
Action: api_planner
Action Input: I need to find the right API calls to generate a short piece of advice
Observation: 1. GET /engines to retrieve the list of available engines
2. POST /completions with the selected engine and a prompt for generating a short piece of advice
Thought:... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-11 | Action: requests_post
Action Input: {"url": "https://api.openai.com/v1/completions", "data": {"engine": "davinci", "prompt": "Give me a short piece of advice on how to be more productive."}, "output_instructions": "Extract the text from the first choice"}
Observation: "you must provide a model parameter"
Thought:!! Cou... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-12 | Observation: babbage, davinci, text-davinci-edit-001, babbage-code-search-code, text-similarity-babbage-001, code-davinci-edit-001, text-davinci-edit-001, ada
Thought:Action: requests_post
Action Input: {"url": "https://api.openai.com/v1/completions", "data": {"model": "davinci", "prompt": "Give me a short piece of adv... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-13 | Action: api_controller
Action Input: 1. GET /models to retrieve the list of available models
2. Choose a suitable model for generating text (e.g., text-davinci-002)
3. POST /completions with the chosen model and a prompt related to improving communication skills to generate a short piece of advice
> Entering new AgentE... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-14 | Takes awhile to get there!
2nd example: “json explorer” agent#
Here’s an agent that’s not particularly practical, but neat! The agent has access to 2 toolkits. One comprises tools to interact with json: one tool to list the keys of a json object and another tool to get the value for a given key. The other toolkit compr... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-15 | Thought: I should look at the servers key to see what the base url is
Action: json_spec_list_keys
Action Input: data["servers"][0]
Observation: ValueError('Value at path `data["servers"][0]` is not a dict, get the value directly.')
Thought: I should get the value of the servers key
Action: json_spec_get_value
Action In... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-16 | Action: json_spec_list_keys
Action Input: data["paths"]
Observation: ['/engines', '/engines/{engine_id}', '/completions', '/chat/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/audio/transcriptions', '/audio/translations', '/engines/{engine_id}/search', '/files', '... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-17 | Action: json_spec_list_keys
Action Input: data["paths"]
Observation: ['/engines', '/engines/{engine_id}', '/completions', '/chat/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/audio/transcriptions', '/audio/translations', '/engines/{engine_id}/search', '/files', '... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-18 | Action: json_spec_list_keys
Action Input: data["paths"]["/completions"]["post"]["requestBody"]["content"]["application/json"]
Observation: ['schema']
Thought: I should look at the schema key to see what parameters are required
Action: json_spec_list_keys
Action Input: data["paths"]["/completions"]["post"]["requestBody"... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-19 | > Finished chain.
Observation: The required parameters for a POST request to the /completions endpoint are 'model'.
Thought: I now know the parameters needed to make the request.
Action: requests_post
Action Input: { "url": "https://api.openai.com/v1/completions", "data": { "model": "davinci", "prompt": "tell me a joke... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
7d2e64dc8fd5-20 | > Finished chain.
'The response of the POST request is {"id":"cmpl-70Ivzip3dazrIXU8DSVJGzFJj2rdv","object":"text_completion","created":1680307139,"model":"davinci","choices":[{"text":" with mummy not there”\\n\\nYou dig deep and come up with,","index":0,"logprobs":null,"finish_reason":"length"}],"usage":{"prompt_tokens... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html |
3aae110d5c1d-0 | .ipynb
.pdf
Python Agent
Contents
Fibonacci Example
Training neural net
Python Agent#
This notebook showcases an agent designed to write and execute python code to answer a question.
from langchain.agents.agent_toolkits import create_python_agent
from langchain.tools.python.tool import PythonREPLTool
from langchain.p... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/python.html |
3aae110d5c1d-1 | I need to write a neural network in PyTorch and train it on the given data.
Action: Python REPL
Action Input:
import torch
# Define the model
model = torch.nn.Sequential(
torch.nn.Linear(1, 1)
)
# Define the loss
loss_fn = torch.nn.MSELoss()
# Define the optimizer
optimizer = torch.optim.SGD(model.parameters(), lr... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/python.html |
3aae110d5c1d-2 | Thought: I now know the final answer
Final Answer: The prediction for x = 5 is 10.0.
> Finished chain.
'The prediction for x = 5 is 10.0.'
previous
PowerBI Dataset Agent
next
Spark Dataframe Agent
Contents
Fibonacci Example
Training neural net
By Harrison Chase
© Copyright 2023, Harrison Chase.
... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/python.html |
33544317bc12-0 | .ipynb
.pdf
JSON Agent
Contents
Initialization
Example: getting the required POST parameters for a request
JSON Agent#
This notebook showcases an agent designed to interact with large JSON/dict objects. This is useful when you want to answer questions about a JSON blob that’s too large to fit in the context window of... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html |
33544317bc12-1 | Thought: I should look at the paths key to see what endpoints exist
Action: json_spec_list_keys
Action Input: data["paths"]
Observation: ['/engines', '/engines/{engine_id}', '/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/engines/{engine_id}/search', '/files', '/... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html |
33544317bc12-2 | Action: json_spec_list_keys
Action Input: data["paths"]["/completions"]["post"]["requestBody"]["content"]
Observation: ['application/json']
Thought: I should look at the application/json key to see what parameters are required
Action: json_spec_list_keys
Action Input: data["paths"]["/completions"]["post"]["requestBody"... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html |
33544317bc12-3 | Initialization
Example: getting the required POST parameters for a request
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html |
50924fbdf931-0 | .ipynb
.pdf
Azure Cognitive Services Toolkit
Contents
Create the Toolkit
Use within an Agent
Azure Cognitive Services Toolkit#
This toolkit is used to interact with the Azure Cognitive Services API to achieve some multimodal capabilities.
Currently There are four tools bundled in this toolkit:
AzureCogsImageAnalysisT... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/azure_cognitive_services.html |
50924fbdf931-1 | toolkit = AzureCognitiveServicesToolkit()
[tool.name for tool in toolkit.get_tools()]
['Azure Cognitive Services Image Analysis',
'Azure Cognitive Services Form Recognizer',
'Azure Cognitive Services Speech2Text',
'Azure Cognitive Services Text2Speech']
Use within an Agent#
from langchain import OpenAI
from langchai... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/azure_cognitive_services.html |
50924fbdf931-2 | 'You can make pancakes, omelettes, or quiches with these ingredients!'
audio_file = agent.run("Tell me a joke and read it out for me.")
> Entering new AgentExecutor chain...
Action:
```
{
"action": "Azure Cognitive Services Text2Speech",
"action_input": "Why did the chicken cross the playground? To get to the other... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/azure_cognitive_services.html |
179bc0bb4eaf-0 | .ipynb
.pdf
PlayWright Browser Toolkit
Contents
Instantiating a Browser Toolkit
Use within an Agent
PlayWright Browser Toolkit#
This toolkit is used to interact with the browser. While other tools (like the Requests tools) are fine for static sites, Browser toolkits let your agent navigate the web and interact with d... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-1 | tools = toolkit.get_tools()
tools
[ClickTool(name='click_element', description='Click on an element with the given CSS selector', args_schema=<class 'langchain.tools.playwright.click.ClickToolInput'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, sync_browser=None, async_browser=<Browser ty... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-2 | ExtractTextTool(name='extract_text', description='Extract all the text on the current webpage', args_schema=<class 'pydantic.main.BaseModel'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, sync_browser=None, async_browser=<Browser type=<BrowserType name=chromium executable_path=/Users/wfh/L... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-3 | CurrentWebPageTool(name='current_webpage', description='Returns the URL of the current page', args_schema=<class 'pydantic.main.BaseModel'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, sync_browser=None, async_browser=<Browser type=<BrowserType name=chromium executable_path=/Users/wfh/Lib... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-4 | '[{"innerText": "These Ukrainian veterinarians are risking their lives to care for dogs and cats in the war zone"}, {"innerText": "Life in the ocean\\u2019s \\u2018twilight zone\\u2019 could disappear due to the climate crisis"}, {"innerText": "Clashes renew in West Darfur as food and water shortages worsen in Sudan vi... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-5 | "Australian police sift through 3,000 tons of trash for missing woman\\u2019s remains"}, {"innerText": "As US and Philippine defense ties grow, China warns over Taiwan tensions"}, {"innerText": "Don McLean offers duet with South Korean president who sang \\u2018American Pie\\u2019 to Biden"}, {"innerText": "Almost two-... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-6 | to extend Sudan ceasefire"}, {"innerText": "Spanish Leopard 2 tanks are on their way to Ukraine, defense minister confirms"}, {"innerText": "Flamb\\u00e9ed pizza thought to have sparked deadly Madrid restaurant fire"}, {"innerText": "Another bomb found in Belgorod just days after Russia accidentally struck the city"}, ... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-7 | comes from textile dyes. But a shellfish-inspired solution could clean it up"}, {"innerText": "\\u2018People sacrificed their lives for just\\u00a010 dollars\\u2019: At least 78 killed in Yemen crowd surge"}, {"innerText": "Israeli police say two men shot near Jewish tomb in Jerusalem in suspected \\u2018terror attack\... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-8 | from Khartoum prison"}, {"innerText": "WHO warns of \\u2018biological risk\\u2019 after Sudan fighters seize lab, as violence mars US-brokered ceasefire"}, {"innerText": "How Colombia\\u2019s Petro, a former leftwing guerrilla, found his opening in Washington"}, {"innerText": "Bolsonaro accidentally created Facebook po... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-9 | "Inside the Italian village being repopulated by Americans"}, {"innerText": "Strikes, soaring airfares and yo-yoing hotel fees: A traveler\\u2019s guide to the coronation"}, {"innerText": "A year in Azerbaijan: From spring\\u2019s Grand Prix to winter ski adventures"}, {"innerText": "The bicycle mayor peddling a two-wh... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-10 | as millions in Texas could see damaging winds and hail"}, {"innerText": "The South is in the crosshairs of severe weather again, as the multi-day threat of large hail and tornadoes continues"}, {"innerText": "Spring snowmelt has cities along the Mississippi bracing for flooding in homes and businesses"}, {"innerText": ... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-11 | evacuation from Sudan"}, {"innerText": "Girl to get life-saving treatment for rare immune disease"}, {"innerText": "Haiti\\u2019s crime rate more than doubles in a year"}, {"innerText": "Ocean census aims to discover 100,000 previously unknown marine species"}, {"innerText": "Wall Street Journal editor discusses report... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-12 | stress is huge\\u2019 as she battles to return to tennis following positive drug test"}, {"innerText": "Barcelona reaches third straight Women\\u2019s Champions League final with draw against Chelsea"}, {"innerText": "Wrexham: An intoxicating tale of Hollywood glamor and sporting romance"}, {"innerText": "Shohei Ohtani... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-13 | # If the agent wants to remember the current webpage, it can use the `current_webpage` tool
await tools_by_name['current_webpage'].arun({})
'https://web.archive.org/web/20230428133211/https://cnn.com/world'
Use within an Agent#
Several of the browser tools are StructuredTool’s, meaning they expect multiple arguments. T... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
179bc0bb4eaf-14 | ```
{
"action": "get_elements",
"action_input": {
"selector": "h1, h2, h3, h4, h5, h6"
}
}
```
Observation: []
Thought: Thought: I need to navigate to langchain.com to see the headers
Action:
```
{
"action": "navigate_browser",
"action_input": "https://langchain.com/"
}
```
Observation: Navigating to http... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html |
8ab61eed2a93-0 | .ipynb
.pdf
Gmail Toolkit
Contents
Create the Toolkit
Customizing Authentication
Use within an Agent
Gmail Toolkit#
This notebook walks through connecting a LangChain email to the Gmail API.
To use this toolkit, you will need to set up your credentials explained in the Gmail API docs. Once you’ve downloaded the crede... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/gmail.html |
8ab61eed2a93-1 | toolkit = GmailToolkit(api_resource=api_resource)
tools = toolkit.get_tools()
tools
[GmailCreateDraft(name='create_gmail_draft', description='Use this tool to create a draft email with the provided message fields.', args_schema=<class 'langchain.tools.gmail.create_draft.CreateDraftSchema'>, return_direct=False, verbose... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/gmail.html |
8ab61eed2a93-2 | GmailGetThread(name='get_gmail_thread', description=('Use this tool to search for email messages. The input must be a valid Gmail query. The output is a JSON list of messages.',), args_schema=<class 'langchain.tools.gmail.get_thread.GetThreadSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/gmail.html |
8ab61eed2a93-3 | WARNING:root:Failed to persist run: {"detail":"Not Found"}
"The latest email in your drafts is from hopefulparrot@gmail.com with the subject 'Collaboration Opportunity'. The body of the email reads: 'Dear [Friend], I hope this letter finds you well. I am writing to you in the hopes of rekindling our friendship and to d... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/gmail.html |
07a4c54ea624-0 | .ipynb
.pdf
Pandas Dataframe Agent
Contents
Multi DataFrame Example
Pandas Dataframe Agent#
This notebook shows how to use agents to interact with a pandas dataframe. It is mostly optimized for question answering.
NOTE: this agent calls the Python agent under the hood, which executes LLM generated Python code - this ... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/pandas.html |
07a4c54ea624-1 | Action: python_repl_ast
Action Input: df['Age'].mean()
Observation: 29.69911764705882
Thought: I now need to calculate the square root of the average age
Action: python_repl_ast
Action Input: math.sqrt(df['Age'].mean())
Observation: NameError("name 'math' is not defined")
Thought: I need to import the math library
Acti... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/pandas.html |
07a4c54ea624-2 | '177 rows in the age column are different.'
previous
Natural Language APIs
next
PlayWright Browser Toolkit
Contents
Multi DataFrame Example
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/pandas.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.