id stringlengths 14 16 | text stringlengths 45 2.73k | source stringlengths 49 114 |
|---|---|---|
ff75455b44e6-2 | × Hunter was adapted into a 62-episode anime television series produced by Nippon Animation and directed by Kazuhiro Furuhashi, which ran on Fuji Television from October 1999 to March 2001. Three separate original video animations (OVAs) totaling 30 episodes were subsequently produced by Nippon Animation and released i... | https://python.langchain.com/en/latest/modules/agents/tools/examples/wikipedia.html |
ff75455b44e6-3 | × Hunter has been a huge critical and financial success and has become one of the best-selling manga series of all time, having over 84 million copies in circulation by July 2022.\n\nPage: Hunter × Hunter (2011 TV series)\nSummary: Hunter × Hunter is an anime television series that aired from 2011 to 2014 based on Yosh... | https://python.langchain.com/en/latest/modules/agents/tools/examples/wikipedia.html |
ff75455b44e6-4 | new Hunter × Hunter anime was announced on July 24, 2011. It is a complete reboot of the anime adaptation starting from the beginning of the manga, with no connections to the first anime from 1999. Produced by Nippon TV, VAP, Shueisha and Madhouse, the series is directed by Hiroshi Kōjina, with Atsushi Maekawa and Tsut... | https://python.langchain.com/en/latest/modules/agents/tools/examples/wikipedia.html |
ff75455b44e6-5 | On television, the series began airing on Adult Swim\'s Toonami programming block on April 17, 2016, and ended on June 23, 2019.The anime series\' opening theme is alternated between the song "Departure!" and an alternate version titled "Departure! -Second Version-" both sung by Galneryus\' vocalist Masatoshi Ono. Five... | https://python.langchain.com/en/latest/modules/agents/tools/examples/wikipedia.html |
ff75455b44e6-6 | The background music and soundtrack for the series was composed by Yoshihisa Hirano.\n\n\n\nPage: List of Hunter × Hunter characters\nSummary: The Hunter × Hunter manga series, created by Yoshihiro Togashi, features an extensive cast of characters. It takes place in a fictional universe where licensed specialists known... | https://python.langchain.com/en/latest/modules/agents/tools/examples/wikipedia.html |
ff75455b44e6-7 | previous
SerpAPI
next
Wolfram Alpha
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Apr 21, 2023. | https://python.langchain.com/en/latest/modules/agents/tools/examples/wikipedia.html |
b4b85a7b8aae-0 | .ipynb
.pdf
Bash
Bash#
It can often be useful to have an LLM generate bash commands, and then run them. A common use case for this is letting the LLM interact with your local file system. We provide an easy util to execute bash commands.
from langchain.utilities import BashProcess
bash = BashProcess()
print(bash.run("l... | https://python.langchain.com/en/latest/modules/agents/tools/examples/bash.html |
316bcd428527-0 | .ipynb
.pdf
OpenWeatherMap API
OpenWeatherMap API#
This notebook goes over how to use the OpenWeatherMap component to fetch weather information.
First, you need to sign up for an OpenWeatherMap API key:
Go to OpenWeatherMap and sign up for an API key here
pip install pyowm
Then we will need to set some environment vari... | https://python.langchain.com/en/latest/modules/agents/tools/examples/openweathermap.html |
44c055ae501e-0 | .ipynb
.pdf
Zapier Natural Language Actions API
Contents
Zapier Natural Language Actions API
Example with Agent
Example with SimpleSequentialChain
Zapier Natural Language Actions API#
Full docs here: https://nla.zapier.com/api/v1/docs
Zapier Natural Language Actions gives you access to the 5k+ apps, 20k+ actions on Z... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
44c055ae501e-1 | %autoreload 2
import os
# get from https://platform.openai.com/
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "")
# get from https://nla.zapier.com/demo/provider/debug (under User Information, after logging in):
os.environ["ZAPIER_NLA_API_KEY"] = os.environ.get("ZAPIER_NLA_API_KEY", "")
Example with ... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
44c055ae501e-2 | Action: Gmail: Find Email
Action Input: Find the latest email from Silicon Valley Bank
Observation: {"from__name": "Silicon Valley Bridge Bank, N.A.", "from__email": "sreply@svb.com", "body_plain": "Dear Clients, After chaotic, tumultuous & stressful days, we have clarity on path for SVB, FDIC is fully insuring all dep... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
44c055ae501e-3 | Observation: {"message__text": "Silicon Valley Bank has announced that Tim Mayopoulos is the new CEO. FDIC is fully insuring all deposits and they have an ask for clients and partners as they rebuild.", "message__permalink": "https://langchain.slack.com/archives/C04TSGU0RA7/p1678859932375259", "channel": "C04TSGU0RA7",... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
44c055ae501e-4 | from langchain.tools.zapier.tool import ZapierNLARunAction
from langchain.utilities.zapier import ZapierNLAWrapper
## step 0. expose gmail 'find email' and slack 'send direct message' actions
# first go here, log in, expose (enable) the two actions: https://nla.zapier.com/demo/start -- for this example, can leave all f... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
44c055ae501e-5 | SLACK_HANDLE = "@Ankush Gola"
def nla_slack(inputs):
action = next((a for a in actions if a["description"].startswith("Slack: Send Direct Message")), None)
instructions = f'Send this to {SLACK_HANDLE} in Slack: {inputs["draft_reply"]}'
return {"slack_data": ZapierNLARunAction(action_id=action["id"], zapier_... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
44c055ae501e-6 | overall_chain.run(GMAIL_SEARCH_INSTRUCTIONS)
> Entering new SimpleSequentialChain chain...
{"from__name": "Silicon Valley Bridge Bank, N.A.", "from__email": "sreply@svb.com", "body_plain": "Dear Clients, After chaotic, tumultuous & stressful days, we have clarity on path for SVB, FDIC is fully insuring all deposits & h... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
44c055ae501e-7 | Best regards,
[Your Name]
{"message__text": "Dear Silicon Valley Bridge Bank, \n\nThank you for your email and the update regarding your new CEO Tim Mayopoulos. We appreciate your dedication to keeping your clients and partners informed and we look forward to continuing our relationship with you. \n\nBest regards, \n[... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
44c055ae501e-8 | > Finished chain.
'{"message__text": "Dear Silicon Valley Bridge Bank, \\n\\nThank you for your email and the update regarding your new CEO Tim Mayopoulos. We appreciate your dedication to keeping your clients and partners informed and we look forward to continuing our relationship with you. \\n\\nBest regards, \\n[You... | https://python.langchain.com/en/latest/modules/agents/tools/examples/zapier.html |
db0a91174bd0-0 | .ipynb
.pdf
Google Places
Google Places#
This notebook goes through how to use Google Places API
#!pip install googlemaps
import os
os.environ["GPLACES_API_KEY"] = ""
from langchain.tools import GooglePlacesTool
places = GooglePlacesTool()
places.run("al fornos")
"1. Delfina Restaurant\nAddress: 3621 18th St, San Franc... | https://python.langchain.com/en/latest/modules/agents/tools/examples/google_places.html |
7524994dcd69-0 | .ipynb
.pdf
CSV Agent
CSV Agent#
This notebook shows how to use agents to interact with a csv. It is mostly optimized for question answering.
NOTE: this agent calls the Pandas DataFrame agent under the hood, which in turn calls the Python agent, which executes LLM generated Python code - this can be bad if the LLM gene... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/csv.html |
7524994dcd69-1 | Observation: 29.69911764705882
Thought: I can now calculate the square root
Action: python_repl_ast
Action Input: math.sqrt(df['Age'].mean())
Observation: name 'math' is not defined
Thought: I need to import the math library
Action: python_repl_ast
Action Input: import math
Observation:
Thought: I can now calculate th... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/csv.html |
41e455b935fa-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 |
41e455b935fa-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 |
41e455b935fa-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 |
41e455b935fa-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 |
41e455b935fa-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 |
41e455b935fa-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 Apr 21, 2023. | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/vectorstore.html |
49d05cea55ad-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 |
49d05cea55ad-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 |
49d05cea55ad-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 |
49d05cea55ad-3 | Initialization
Example: getting the required POST parameters for a request
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Apr 21, 2023. | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html |
394e1eb7d14c-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 |
394e1eb7d14c-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 |
394e1eb7d14c-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
Pandas Dataframe Agent
next
SQL Database Agent
Contents
Fibonacci Example
Training neural net
By Harrison Chase
© Copyright 2023, Harrison Chase.
La... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/python.html |
05680b97f4ad-0 | .ipynb
.pdf
SQL Database Agent
Contents
Initialization
Example: describing a table
Example: describing a table, recovering from an error
Example: running queries
Recovering from an error
SQL Database Agent#
This notebook showcases an agent designed to interact with a sql databases. The agent builds off of SQLDatabase... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-1 | Action: schema_sql_db
Action Input: "PlaylistTrack"
Observation:
CREATE TABLE "PlaylistTrack" (
"PlaylistId" INTEGER NOT NULL,
"TrackId" INTEGER NOT NULL,
PRIMARY KEY ("PlaylistId", "TrackId"),
FOREIGN KEY("TrackId") REFERENCES "Track" ("TrackId"),
FOREIGN KEY("PlaylistId") REFERENCES "Playlist" ("PlaylistId"... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-2 | Thought: The table is called PlaylistTrack
Action: schema_sql_db
Action Input: "PlaylistTrack"
Observation:
CREATE TABLE "PlaylistTrack" (
"PlaylistId" INTEGER NOT NULL,
"TrackId" INTEGER NOT NULL,
PRIMARY KEY ("PlaylistId", "TrackId"),
FOREIGN KEY("TrackId") REFERENCES "Track" ("TrackId"),
FOREIGN KEY("Playl... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-3 | "Address" NVARCHAR(70),
"City" NVARCHAR(40),
"State" NVARCHAR(40),
"Country" NVARCHAR(40),
"PostalCode" NVARCHAR(10),
"Phone" NVARCHAR(24),
"Fax" NVARCHAR(24),
"Email" NVARCHAR(60) NOT NULL,
"SupportRepId" INTEGER,
PRIMARY KEY ("CustomerId"),
FOREIGN KEY("SupportRepId") REFERENCES "Employee" ("Emplo... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-4 | "BillingCity" NVARCHAR(40),
"BillingState" NVARCHAR(40),
"BillingCountry" NVARCHAR(40),
"BillingPostalCode" NVARCHAR(10),
"Total" NUMERIC(10, 2) NOT NULL,
PRIMARY KEY ("InvoiceId"),
FOREIGN KEY("CustomerId") REFERENCES "Customer" ("CustomerId")
)
SELECT * FROM 'Invoice' LIMIT 3;
InvoiceId CustomerId Invoice... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-5 | Observation: [('USA', 523.0600000000003), ('Canada', 303.9599999999999), ('France', 195.09999999999994), ('Brazil', 190.09999999999997), ('Germany', 156.48), ('United Kingdom', 112.85999999999999), ('Czech Republic', 90.24000000000001), ('Portugal', 77.23999999999998), ('India', 75.25999999999999), ('Chile', 46.62)]
Th... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-6 | "TrackId" INTEGER NOT NULL,
PRIMARY KEY ("PlaylistId", "TrackId"),
FOREIGN KEY("TrackId") REFERENCES "Track" ("TrackId"),
FOREIGN KEY("PlaylistId") REFERENCES "Playlist" ("PlaylistId")
)
SELECT * FROM 'PlaylistTrack' LIMIT 3;
PlaylistId TrackId
1 3402
1 3389
1 3390
Thought: I can use a SELECT statement to get the... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-7 | Thought: I now know the final answer.
Final Answer: The total number of tracks in each playlist are: '90’s Music' (1477), 'Brazilian Music' (39), 'Classical' (75), 'Classical 101 - Deep Cuts' (25), 'Classical 101 - Next Steps' (25), 'Classical 101 - The Basics' (25), 'Grunge' (15), 'Heavy Metal Classic' (26), 'Music' (... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-8 | CREATE TABLE "Artist" (
"ArtistId" INTEGER NOT NULL,
"Name" NVARCHAR(120),
PRIMARY KEY ("ArtistId")
)
SELECT * FROM 'Artist' LIMIT 3;
ArtistId Name
1 AC/DC
2 Accept
3 Aerosmith
CREATE TABLE "Track" (
"TrackId" INTEGER NOT NULL,
"Name" NVARCHAR(200) NOT NULL,
"AlbumId" INTEGER,
"MediaTypeId" INTEGER NOT NULL... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-9 | "InvoiceId" INTEGER NOT NULL,
"TrackId" INTEGER NOT NULL,
"UnitPrice" NUMERIC(10, 2) NOT NULL,
"Quantity" INTEGER NOT NULL,
PRIMARY KEY ("InvoiceLineId"),
FOREIGN KEY("TrackId") REFERENCES "Track" ("TrackId"),
FOREIGN KEY("InvoiceId") REFERENCES "Invoice" ("InvoiceId")
)
SELECT * FROM 'InvoiceLine' LIMIT 3;... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
05680b97f4ad-10 | Thought: I should double check my query before executing it.
Action: query_checker_sql_db
Action Input: SELECT Artist.Name, SUM(InvoiceLine.Quantity) AS TotalQuantity FROM Artist INNER JOIN Track ON Artist.ArtistId = Track.ArtistId INNER JOIN InvoiceLine ON Track.TrackId = InvoiceLine.TrackId GROUP BY Artist.Name ORDER... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html |
1de7b864f93f-0 | .ipynb
.pdf
Natural Language APIs
Contents
First, import dependencies and load the LLM
Next, load the Natural Language API Toolkits
Create the Agent
Using Auth + Adding more Endpoints
Thank you!
Natural Language APIs#
Natural Language API Toolkits (NLAToolkits) permit LangChain Agents to efficiently plan and combine ... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi_nla.html |
1de7b864f93f-1 | Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.
Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.
Create the Agent#
# Slightly twe... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi_nla.html |
1de7b864f93f-2 | Action: Open_AI_Klarna_product_Api.productsUsingGET
Action Input: Italian clothes
Observation: The API response contains two products from the Alé brand in Italian Blue. The first is the Alé Colour Block Short Sleeve Jersey Men - Italian Blue, which costs $86.49, and the second is the Alé Dolid Flash Jersey Men - Itali... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi_nla.html |
1de7b864f93f-3 | llm,
"https://spoonacular.com/application/frontend/downloads/spoonacular-openapi-3.json",
requests=requests,
max_text_length=1800, # If you want to truncate the response text
)
Attempting to load an OpenAPI 3.0.0 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for be... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi_nla.html |
1de7b864f93f-4 | Unsupported APIPropertyLocation "header" for parameter Accept. Valid values are ['path', 'query'] Ignoring optional parameter
Unsupported APIPropertyLocation "header" for parameter Content-Type. Valid values are ['path', 'query'] Ignoring optional parameter
Unsupported APIPropertyLocation "header" for parameter Accept.... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi_nla.html |
1de7b864f93f-5 | Action: spoonacular_API.searchRecipes
Action Input: Italian
Observation: The API response contains 10 Italian recipes, including Turkey Tomato Cheese Pizza, Broccolini Quinoa Pilaf, Bruschetta Style Pork & Pasta, Salmon Quinoa Risotto, Italian Tuna Pasta, Roasted Brussels Sprouts With Garlic, Asparagus Lemon Risotto, I... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi_nla.html |
1de7b864f93f-6 | > Finished chain.
'To present for your Italian language class, you could wear an Italian Gold Sparkle Perfectina Necklace - Gold, an Italian Design Miami Cuban Link Chain Necklace - Gold, or an Italian Gold Miami Cuban Link Chain Necklace - Gold. For a recipe, you could make Turkey Tomato Cheese Pizza, Broccolini Quino... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi_nla.html |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
096f92112a3a-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 |
7819f2f8239f-0 | .ipynb
.pdf
Jira
Jira#
This notebook goes over how to use the Jira tool.
The Jira tool allows agents to interact with a given Jira instance, performing actions such as searching for issues and creating issues, the tool wraps the atlassian-python-api library, for more see: https://atlassian-python-api.readthedocs.io/jir... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/jira.html |
7819f2f8239f-1 | Observation: None
Thought: I now know the final answer
Final Answer: A new issue has been created in project PW with the summary "Make more fried rice" and description "Reminder to make more fried rice".
> Finished chain.
'A new issue has been created in project PW with the summary "Make more fried rice" and descriptio... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/jira.html |
5c10fe7bc5da-0 | .ipynb
.pdf
Pandas Dataframe Agent
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 can be bad if the LLM generated Pyt... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/pandas.html |
5c10fe7bc5da-1 | Action: python_repl_ast
Action Input: df['Age'].mean()
Observation: 29.69911764705882
Thought: I can now calculate the square root
Action: python_repl_ast
Action Input: math.sqrt(df['Age'].mean())
Observation: name 'math' is not defined
Thought: I need to import the math library
Action: python_repl_ast
Action Input: im... | https://python.langchain.com/en/latest/modules/agents/toolkits/examples/pandas.html |
1db01f7cc7be-0 | .ipynb
.pdf
Custom LLM Agent
Contents
Set up environment
Set up tool
Prompt Template
Output Parser
Set up LLM
Define the stop sequence
Set up the Agent
Use the Agent
Adding Memory
Custom LLM Agent#
This notebook goes through how to create your own custom LLM agent.
An LLM agent consists of three parts:
PromptTemplate... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html |
1db01f7cc7be-1 | from langchain.prompts import StringPromptTemplate
from langchain import OpenAI, SerpAPIWrapper, LLMChain
from typing import List, Union
from langchain.schema import AgentAction, AgentFinish
import re
Set up tool#
Set up any tools the agent may want to use. This may be necessary to put in the prompt (so that the agent ... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html |
1db01f7cc7be-2 | Question: {input}
{agent_scratchpad}"""
# Set up a prompt template
class CustomPromptTemplate(StringPromptTemplate):
# The template to use
template: str
# The list of tools available
tools: List[Tool]
def format(self, **kwargs) -> str:
# Get the intermediate steps (AgentAction, Observat... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html |
1db01f7cc7be-3 | class CustomOutputParser(AgentOutputParser):
def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]:
# Check if agent should finish
if "Final Answer:" in llm_output:
return AgentFinish(
# Return values is generally always a dictionary with a single `outp... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html |
1db01f7cc7be-4 | # LLM chain consisting of the LLM and a prompt
llm_chain = LLMChain(llm=llm, prompt=prompt)
tool_names = [tool.name for tool in tools]
agent = LLMSingleActionAgent(
llm_chain=llm_chain,
output_parser=output_parser,
stop=["\nObservation:"],
allowed_tools=tool_names
)
Use the Agent#
Now we can use it!
a... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html |
1db01f7cc7be-5 | Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html |
1db01f7cc7be-6 | Thought: I need to find out the population of Canada in 2023
Action: Search
Action Input: Population of Canada in 2023
Observation:The current population of Canada is 38,658,314 as of Wednesday, April 12, 2023, based on Worldometer elaboration of the latest United Nations data. I now know the final answer
Final Answer:... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html |
fcaf29d2aba5-0 | .ipynb
.pdf
Custom Agent with Tool Retrieval
Contents
Set up environment
Set up tools
Tool Retriever
Prompt Template
Output Parser
Set up LLM, stop sequence, and the agent
Use the Agent
Custom Agent with Tool Retrieval#
This notebook builds off of this notebook and assumes familiarity with how agents work.
The novel ... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html |
fcaf29d2aba5-1 | return "foo"
fake_tools = [
Tool(
name=f"foo-{i}",
func=fake_func,
description=f"a silly function that you can use to get more information about the number {i}"
)
for i in range(99)
]
ALL_TOOLS = [search_tool] + fake_tools
Tool Retriever#
We will use a vectorstore to create embedd... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html |
fcaf29d2aba5-2 | get_tools("whats the weather?")
[Tool(name='Search', description='useful for when you need to answer questions about current events', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<bound method SerpAPIWrapper.run of SerpAPIWrapper(sea... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html |
fcaf29d2aba5-3 | get_tools("whats the number 13?")
[Tool(name='foo-13', description='a silly function that you can use to get more information about the number 13', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<function fake_func at 0x15e5bd1f0>, cor... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html |
fcaf29d2aba5-4 | {tools}
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can r... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html |
fcaf29d2aba5-5 | # Create a list of tool names for the tools provided
kwargs["tool_names"] = ", ".join([tool.name for tool in tools])
return self.template.format(**kwargs)
prompt = CustomPromptTemplate(
template=template,
tools_getter=get_tools,
# This omits the `agent_scratchpad`, `tools`, and `tool_names` ... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html |
fcaf29d2aba5-6 | action_input = match.group(2)
# Return the action and action input
return AgentAction(tool=action, tool_input=action_input.strip(" ").strip('"'), log=llm_output)
output_parser = CustomOutputParser()
Set up LLM, stop sequence, and the agent#
Also the same as the previous notebook
llm = OpenAI(temperature... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html |
fcaf29d2aba5-7 | > Finished chain.
"'Arg, 'tis mostly cloudy skies early, then partly cloudy in the afternoon. High near 60F. ENE winds shiftin' to W at 10 to 15 mph. Humidity71%. UV Index6 of 10."
previous
Custom MultiAction Agent
next
Conversation Agent (for Chat Models)
Contents
Set up environment
Set up tools
Tool Retriever
Pro... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html |
3e5ec4722332-0 | .ipynb
.pdf
Custom Agent
Custom Agent#
This notebook goes through how to create your own custom agent.
An agent consists of three parts:
- Tools: The tools the agent has available to use.
- The agent class itself: this decides which action to take.
In this notebook we walk through how to create a custom agent.
from lan... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent.html |
3e5ec4722332-1 | Args:
intermediate_steps: Steps the LLM has taken to date,
along with observations
**kwargs: User inputs.
Returns:
Action specifying what tool to use.
"""
return AgentAction(tool="Search", tool_input=kwargs["input"], log="")
agent = FakeAgent()... | https://python.langchain.com/en/latest/modules/agents/agents/custom_agent.html |
1da50f2db355-0 | .ipynb
.pdf
Custom LLM Agent (with a ChatModel)
Contents
Set up environment
Set up tool
Prompt Template
Output Parser
Set up LLM
Define the stop sequence
Set up the Agent
Use the Agent
Custom LLM Agent (with a ChatModel)#
This notebook goes through how to create your own custom agent based on a chat model.
An LLM cha... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html |
1da50f2db355-1 | Set up environment#
Do necessary imports, etc.
from langchain.agents import Tool, AgentExecutor, LLMSingleActionAgent, AgentOutputParser
from langchain.prompts import BaseChatPromptTemplate
from langchain import SerpAPIWrapper, LLMChain
from langchain.chat_models import ChatOpenAI
from typing import List, Union
from la... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html |
1da50f2db355-2 | ... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin! Remember to speak as a pirate when giving your final answer. Use lots of "Arg"s
Question: {input}
{agent_scratchpad}"""
# Set up a prompt templa... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html |
1da50f2db355-3 | input_variables=["input", "intermediate_steps"]
)
Output Parser#
The output parser is responsible for parsing the LLM output into AgentAction and AgentFinish. This usually depends heavily on the prompt used.
This is where you can change the parsing to do retries, handle whitespace, etc
class CustomOutputParser(AgentOut... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html |
1da50f2db355-4 | Define the stop sequence#
This is important because it tells the LLM when to stop generation.
This depends heavily on the prompt and model you are using. Generally, you want this to be whatever token you use in the prompt to denote the start of an Observation (otherwise, the LLM may hallucinate an observation for you).... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html |
1da50f2db355-5 | Final Answer: Arrrr, thar be 38,649,283 scallywags in Canada as of 2023.
> Finished chain.
'Arrrr, thar be 38,649,283 scallywags in Canada as of 2023.'
previous
Custom LLM Agent
next
Custom MRKL Agent
Contents
Set up environment
Set up tool
Prompt Template
Output Parser
Set up LLM
Define the stop sequence
Set up th... | https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html |
a833166f3af6-0 | .md
.pdf
Agent Types
Contents
zero-shot-react-description
react-docstore
self-ask-with-search
conversational-react-description
Agent Types#
Agents use an LLM to determine which actions to take and in what order.
An action can either be using a tool and observing its output, or returning a response to the user.
Here a... | https://python.langchain.com/en/latest/modules/agents/agents/agent_types.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.