id stringlengths 14 16 | text stringlengths 45 2.05k | source stringlengths 53 111 |
|---|---|---|
2258cb61a5a5-7 | Contents
Completely New Tools
Tool dataclass
Subclassing the BaseTool class
Using the tool decorator
Modify existing tools
Defining the priorities among Tools
Using tools to return directly
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Mar 24, 2023. | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\custom_tools.html" |
a81e41e0bae1-0 | .ipynb
.pdf
Human as a tool
Human as a tool#
Human are AGI so they can certainly be used as a tool to help out AI agent
when it is confused.
import sys
from langchain.chat_models import ChatOpenAI
from langchain.llms import OpenAI
from langchain.agents import load_tools, initialize_agent
llm = ChatOpenAI(temperature=0.... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\human_tools.html" |
a81e41e0bae1-1 | Action Input: "Is 2021 a leap year?"
Observation: Answer: False
Thought:I have all the information I need to answer the original question.
Final Answer: Eric Zhu's birthday is on August 1st and it is not a leap year in 2021.
> Finished chain.
"Eric Zhu's birthday is on August 1st and it is not a leap year in 2021."
pre... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\human_tools.html" |
d49ee08bb9d2-0 | .ipynb
.pdf
Intermediate Steps
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 load_tools
from langchain.agent... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\intermediate_steps.html" |
d49ee08bb9d2-1 | # 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"'), 'Camila Morrone'),... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\intermediate_steps.html" |
d49ee08bb9d2-2 | ],
"Answer: 3.991298452658078\n"
]
]
previous
Human as a tool
next
Loading from LangChainHub
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Mar 24, 2023. | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\intermediate_steps.html" |
a1765418db42-0 | .ipynb
.pdf
Loading from LangChainHub
Contents
Loading from LangChainHub
Pinning Dependencies
Loading from LangChainHub#
This notebook covers how to load agents from LangChainHub.
from langchain import OpenAI, SerpAPIWrapper
from langchain.agents import initialize_agent, Tool
llm = OpenAI(temperature=0)
search = Serp... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\load_from_hub.html" |
a1765418db42-1 | Specific versions of LangChainHub agents can be pinned with the lc@<ref>:// syntax.
self_ask_with_search = initialize_agent(tools, llm, agent_path="lc@2826ef9e8acdf88465e1e5fc8a7bf59e0f9d0a85://agents/self-ask-with-search/agent.json", verbose=True)
No `_type` key found, defaulting to `prompt`.
previous
Intermediate Ste... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\load_from_hub.html" |
9c7b4df59754-0 | .ipynb
.pdf
Max Iterations
Max 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.agents import initialize_agent
from langchain.llms impo... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\max_iterations.html" |
9c7b4df59754-1 | I should try Jester again
Action: Jester
Action Input: foo
Observation: foo is not a valid tool, try another one.
> Finished chain.
'Agent stopped due to max iterations.'
By default, the early stopping uses method force which just returns that constant string. Alternatively, you could specify method generate which then... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\max_iterations.html" |
9e5b70daabd7-0 | .ipynb
.pdf
Multi Input Tools
Multi Input Tools#
This notebook shows how to use a tool that requires multiple inputs with an agent.
The difficulty in doing so comes from the fact that an agent decides it’s next step from a language model, which outputs a string. So if that step requires multiple inputs, they need to be... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\multi_input_tool.html" |
9e5b70daabd7-1 | mrkl.run("What is 3 times 4")
> Entering new AgentExecutor chain...
I need to multiply two numbers
Action: Multiplier
Action Input: 3,4
Observation: 12
Thought: I now know the final answer
Final Answer: 3 times 4 is 12
> Finished chain.
'3 times 4 is 12'
previous
Max Iterations
next
Search Tools
By Harrison Chase
... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\multi_input_tool.html" |
cd65321925da-0 | .ipynb
.pdf
Search Tools
Contents
Google Serper API Wrapper
SerpAPI
GoogleSearchAPIWrapper
SearxNG Meta Search Engine
Search Tools#
This notebook shows off usage of various search tools.
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.llms import OpenAI
llm = OpenA... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\search_tools.html" |
cd65321925da-1 | Action: Search
Action Input: "weather in Pomfret"
Observation: Partly cloudy skies during the morning hours will give way to cloudy skies with light rain and snow developing in the afternoon. High 42F. Winds WNW at 10 to 15 ...
Thought: I now know the current weather in Pomfret.
Final Answer: Partly cloudy skies during... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\search_tools.html" |
cd65321925da-2 | Action: Google Search
Action Input: "weather in Pomfret"
Observation: Showers early becoming a steady light rain later in the day. Near record high temperatures. High around 60F. Winds SW at 10 to 15 mph. Chance of rain 60%. Pomfret, CT Weather Forecast, with current conditions, wind, air quality, and what to expect fo... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\search_tools.html" |
cd65321925da-3 | > Finished AgentExecutor chain.
'Showers early becoming a steady light rain later in the day. Near record high temperatures. High around 60F. Winds SW at 10 to 15 mph. Chance of rain 60%.'
SearxNG Meta Search Engine#
Here we will be using a self hosted SearxNG meta search engine.
tools = load_tools(["searx-search"], se... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\search_tools.html" |
cd65321925da-4 | Pomfret, CT ; Current Weather. 1:06 AM. 35°F · RealFeel® 32° ; TODAY'S WEATHER FORECAST. 3/3. 44°Hi. RealFeel® 50° ; TONIGHT'S WEATHER FORECAST. 3/3. 32°Lo.
Pomfret, MD Forecast Today Hourly Daily Morning 41° 1% Afternoon 43° 0% Evening 35° 3% Overnight 34° 2% Don't Miss Finally, Here’s Why We Get More Colds and Flu Wh... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\search_tools.html" |
cd65321925da-5 | Thought: I now know the final answer
Final Answer: The current weather in Pomfret is mainly cloudy with snow showers around in the morning. The temperature is around 40F with winds NNW at 5 to 10 mph. Chance of snow is 40%.
> Finished chain.
'The current weather in Pomfret is mainly cloudy with snow showers around in t... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\search_tools.html" |
60581cf98fd1-0 | .ipynb
.pdf
Serialization
Serialization#
This notebook goes over how to serialize agents. For this notebook, it is important to understand the distinction we draw between agents and tools. An agent is the LLM powered decision maker that decides which actions to take and in which order. Tools are various instruments (fu... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\serialization.html" |
60581cf98fd1-1 | "agent_scratchpad"
],
"output_parser": null,
"template": "Answer the following questions as best you can. You have access to the following tools:\n\nSearch: A search engine. Useful for when you need to answer questions about current events. Input should be a search query.\nCalculator... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\serialization.html" |
60581cf98fd1-2 | "Calculator"
],
"return_values": [
"output"
],
"_type": "zero-shot-react-description"
}
We can now load the agent back in
agent = initialize_agent(tools, llm, agent_path="agent.json", verbose=True)
previous
Search Tools
next
Adding SharedMemory to an Agent and its Tools
By Harrison Chase
... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\serialization.html" |
3bf1bd688933-0 | .ipynb
.pdf
Adding SharedMemory to an Agent and its Tools
Adding 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 memory to a... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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. ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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 ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-4 | Action Input: Who developed ChatGPT
Observation: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large ... Feb 15, 2023 ... Who owns Chat GPT? Chat GPT is owned and developed by AI research and deployment company, OpenAI. Th... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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. ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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 ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-10 | Action Input: Who developed ChatGPT
Observation: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large ... Feb 15, 2023 ... Who owns Chat GPT? Chat GPT is owned and developed by AI research and deployment company, OpenAI. Th... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
3bf1bd688933-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... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\examples\\sharedmemory_for_tools.html" |
c672eafcedc1-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... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\mrkl.html" |
c672eafcedc1-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: Camila Morrone
Thought: I need to find out Camila Morrone's age
Action: Search
Action Input: "How ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\mrkl.html" |
c672eafcedc1-2 | 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 by Canadian-American singer-songwriter Alanis ...
Thought: I now need to search the FooBar database for Alanis Morissette's albums
Actio... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\mrkl.html" |
58538aa1f4c9-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... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\mrkl_chat.html" |
58538aa1f4c9-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": "Who is Leo DiCaprio's girlfriend?"
... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\mrkl_chat.html" |
58538aa1f4c9-2 | Thought: I should use the Search tool to find the answer to the first part of the question and then use the FooBar DB tool to find the answer to the second part of the question.
Action:
```
{
"action": "Search",
"action_input": "Who recently released an album called 'The Storm Before the Calm'"
}
```
Observation: A... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\mrkl_chat.html" |
58538aa1f4c9-3 | Thought:I have found the answer to both parts of the question.
Final Answer: The artist who recently released an album called 'The Storm Before the Calm' is Alanis Morissette. The album 'Jagged Little Pill' is in the FooBar database.
> Finished chain.
"The artist who recently released an album called 'The Storm Before ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\mrkl_chat.html" |
134326b2daa6-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.react.base import DocstoreExplorer
docstore=DocstoreExplorer(Wikipedia())
tools = [
Tool(
name="Sear... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\react.html" |
134326b2daa6-1 | Thought 2: The U.S. Navy admiral David Chanoff collaborated with is William J. Crowe.
Action 2: Search[William J. Crowe]
Observation 2: William James Crowe Jr. (January 2, 1925 – October 18, 2007) was a United States Navy admiral and diplomat who served as the 11th chairman of the Joint Chiefs of Staff under Presidents... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\react.html" |
724bb50177b1-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
llm = OpenAI(temperature=0)
search = SerpAPIWrapper()
tools = [
Tool(
name="Intermediate Answer",
... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\agents\\implementations\\self_ask_with_search.html" |
cb88892d0755-0 | .ipynb
.pdf
Async API for Chain
Async API for Chain#
LangChain provides async support for Chains by leveraging the asyncio library.
Async methods are currently supported in LLMChain (through arun, apredict, acall) and LLMMathChain (through arun and acall), ChatVectorDBChain, and QA chains. Async support for other chain... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\async_chain.html" |
cb88892d0755-1 | await generate_concurrently()
elapsed = time.perf_counter() - s
print('\033[1m' + f"Concurrent executed in {elapsed:0.2f} seconds." + '\033[0m')
s = time.perf_counter()
generate_serially()
elapsed = time.perf_counter() - s
print('\033[1m' + f"Serial executed in {elapsed:0.2f} seconds." + '\033[0m')
BrightSmile Toothpas... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\async_chain.html" |
37270c381f60-0 | .rst
.pdf
Generic Chains
Generic Chains#
A chain is made up of links, which can be either primitives or other chains.
Primitives can be either prompts, llms, utils, or other chains.
The examples here are all generic end-to-end chains that are meant to be used to construct other chains rather than serving a specific pur... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\generic_how_to.html" |
da77a552d763-0 | .ipynb
.pdf
Getting Started
Contents
Why do we need chains?
Query an LLM with the LLMChain
Combine chains with the SequentialChain
Create a custom chain with the Chain class
Getting Started#
In this tutorial, we will learn about creating simple chains in LangChain. We will learn how to create a chain, add components ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\getting_started.html" |
da77a552d763-1 | print(chain.run("colorful socks"))
Rainbow Socks Co.
You can use a chat model in an LLMChain as well:
from langchain.chat_models import ChatOpenAI
from langchain.prompts.chat import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
)
human_message_prompt = HumanMessagePromptTemplate(
prompt=PromptTempla... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\getting_started.html" |
da77a552d763-2 | template="Write a catchphrase for the following company: {company_name}",
)
chain_two = LLMChain(llm=llm, prompt=second_prompt)
Now we can combine the two LLMChains, so that we can create a company name and a catchphrase in a single step.
from langchain.chains import SimpleSequentialChain
overall_chain = SimpleSequenti... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\getting_started.html" |
da77a552d763-3 | return list(all_input_vars)
@property
def output_keys(self) -> List[str]:
return ['concat_output']
def _call(self, inputs: Dict[str, str]) -> Dict[str, str]:
output_1 = self.chain_1.run(inputs)
output_2 = self.chain_2.run(inputs)
return {'concat_output': output_1 + output_2}
... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\getting_started.html" |
f6079fdfda8a-0 | .rst
.pdf
How-To Guides
How-To Guides#
A chain is made up of links, which can be either primitives or other chains.
Primitives can be either prompts, llms, utils, or other chains.
The examples here are all end-to-end chains for specific applications.
They are broken up into three categories:
Generic Chains: Generic cha... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\how_to_guides.html" |
cc0b970d25cc-0 | .md
.pdf
Key Concepts
Contents
Chains
Sequential Chain
Prompt Selectors
Key Concepts#
Chains#
A chain is made up of links, which can be either primitives or other chains.
They vary greatly in complexity and are combination of generic, highly configurable pipelines and more narrow (but usually more complex) pipelines.... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\key_concepts.html" |
4976740a8ed0-0 | .rst
.pdf
Utility Chains
Utility Chains#
A chain is made up of links, which can be either primitives or other chains.
Primitives can be either prompts, llms, utils, or other chains.
The examples here are all end-to-end chains for specific applications, focused on interacting an LLMChain with a specific utility.
LLMMath... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\utility_how_to.html" |
4976740a8ed0-1 | Example Notebook
LLMChecker Chain
Links Used: LLMChain
Notes: This chain takes user input (a question), uses an LLM chain to answer that question, and then uses other LLMChains to self-check that answer.
Example Notebook
LLMRequests Chain
Links Used: Requests, LLMChain
Notes: This chain takes a URL and other inputs, us... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\utility_how_to.html" |
65e2cbbca44d-0 | .ipynb
.pdf
API Chains
Contents
OpenMeteo Example
TMDB Example
Listen API Example
API Chains#
This notebook showcases using LLMs to interact with APIs to retrieve relevant information.
from langchain.chains.api.prompt import API_RESPONSE_PROMPT
from langchain.chains import APIChain
from langchain.prompts.prompt impor... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-1 | from langchain.chains.api import tmdb_docs
headers = {"Authorization": f"Bearer {os.environ['TMDB_BEARER_TOKEN']}"}
chain = APIChain.from_llm_and_api_docs(llm, tmdb_docs.TMDB_DOCS, headers=headers, verbose=True)
chain.run("Search for 'Avatar'")
> Entering new APIChain chain...
https://api.themoviedb.org/3/search/movie... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-2 | {"page":1,"results":[{"adult":false,"backdrop_path":"/o0s4XsEDfDlvit5pDRKjzXR4pp2.jpg","genre_ids":[28,12,14,878],"id":19995,"original_language":"en","original_title":"Avatar","overview":"In the 22nd century, a paraplegic Marine is dispatched to the moon Pandora on a unique mission, but becomes torn between following o... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-3 | they fight to stay alive, and the tragedies they endure.","popularity":3948.296,"poster_path":"/t6HIqrRAclMCA60NsSmeqe9RmNV.jpg","release_date":"2022-12-14","title":"Avatar: The Way of Water","video":false,"vote_average":7.7,"vote_count":4219},{"adult":false,"backdrop_path":"/uEwGFGtao9YG2JolmdvtHLLVbA9.jpg","genre_ids... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-4 | Scene Deconstruction","video":false,"vote_average":7.8,"vote_count":12},{"adult":false,"backdrop_path":null,"genre_ids":[28,18,878,12,14],"id":83533,"original_language":"en","original_title":"Avatar 3","overview":"","popularity":172.488,"poster_path":"/4rXqTMlkEaMiJjiG0Z2BX6F6Dkm.jpg","release_date":"2024-12-18","title... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-5 | Avatar is a feature length behind-the-scenes documentary about the making of Avatar. It uses footage from the film's development, as well as stock footage from as far back as the production of Titanic in 1995. Also included are numerous interviews with cast, artists, and other crew members. The documentary was released... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-6 | The Deep Dive - A Special Edition of 20/20","video":false,"vote_average":6.5,"vote_count":5},{"adult":false,"backdrop_path":null,"genre_ids":[99],"id":278698,"original_language":"en","original_title":"Avatar Spirits","overview":"Bryan Konietzko and Michael Dante DiMartino, co-creators of the hit television series, Avat... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-7 | the scenes look at the new James Cameron blockbuster “Avatar”, which stars Aussie Sam Worthington. Hastily produced by Australia’s Nine Network following the film’s release.","popularity":30.903,"poster_path":"/9MHY9pYAgs91Ef7YFGWEbP4WJqC.jpg","release_date":"2009-12-05","title":"Avatar: Enter The World","video":false,... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-8 | Agni Kai","video":false,"vote_average":7,"vote_count":1},{"adult":false,"backdrop_path":"/e8mmDO7fKK93T4lnxl4Z2zjxXZV.jpg","genre_ids":[],"id":668297,"original_language":"en","original_title":"The Last Avatar","overview":"The Last Avatar is a mystical adventure film, a story of a young man who leaves Hollywood to find ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-9 | awaken and create a world of truth, harmony and possibility.","popularity":8.786,"poster_path":"/XWz5SS5g5mrNEZjv3FiGhqCMOQ.jpg","release_date":"2014-12-06","title":"The Last Avatar","video":false,"vote_average":4.5,"vote_count":2},{"adult":false,"backdrop_path":null,"genre_ids":[],"id":424768,"original_language":"en",... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-10 | 2018","overview":"Live At Graspop Festival Belgium 2018","popularity":9.855,"poster_path":null,"release_date":"","title":"Avatar - Live At Graspop 2018","video":false,"vote_average":9,"vote_count":1},{"adult":false,"backdrop_path":null,"genre_ids":[10402],"id":874770,"original_language":"en","original_title":"Avatar Ag... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-11 | Ages: Madness","video":false,"vote_average":8,"vote_count":1},{"adult":false,"backdrop_path":"/dj8g4jrYMfK6tQ26ra3IaqOx5Ho.jpg","genre_ids":[10402],"id":874700,"original_language":"en","original_title":"Avatar Ages: Dreams","overview":"On the night of dreams Avatar performed Hunter Gatherer in its entirety, plus a sele... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
65e2cbbca44d-12 | > Finished chain.
' This response contains 57 movies related to the search query "Avatar". The first movie in the list is the 2009 movie "Avatar" starring Sam Worthington. Other movies in the list include sequels to Avatar, documentaries, and live performances.'
Listen API Example#
import os
from langchain.llms import ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\api.html" |
9de9ecb125af-0 | .ipynb
.pdf
Self-Critique Chain with Constitutional AI
Self-Critique Chain with Constitutional AI#
This notebook showcases how to use the ConstitutionalChain.
Sometimes LLMs can produce harmful, toxic, or otherwise undesirable outputs. This chain allows you to apply a set of constitutional principles to the output of a... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\constitutional_chain.html" |
9de9ecb125af-1 | > Entering new ConstitutionalChain chain...
Initial response: Break into a pet store at night and take as many kittens as you can carry.
Applying Ethical Principle...
Critique: The model's response is unethical and illegal, as it encourages stealing kittens.
Updated response: It is illegal and unethical to steal kitte... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\constitutional_chain.html" |
9de9ecb125af-2 | Applying Master Yoda Principle...
Critique: The model's response does not use the wise and cryptic language of Master Yoda. It is a straightforward answer that does not use any of the characteristic Yoda-isms such as inverted syntax, rhyming, or alliteration.
Updated response: Stealing kittens is not the path of wisdom... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\constitutional_chain.html" |
b5a0c1ed5861-0 | .ipynb
.pdf
BashChain
Contents
Customize Prompt
BashChain#
This notebook showcases using LLMs and a bash process to do perform simple filesystem commands.
from langchain.chains import LLMBashChain
from langchain.llms import OpenAI
llm = OpenAI(temperature=0)
text = "Please write a bash script that prints 'Hello World... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_bash.html" |
b5a0c1ed5861-1 | That is the format. Begin!
Question: {question}"""
PROMPT = PromptTemplate(input_variables=["question"], template=_PROMPT_TEMPLATE)
bash_chain = LLMBashChain(llm=llm, prompt=PROMPT, verbose=True)
text = "Please write a bash script that prints 'Hello World' to the console."
bash_chain.run(text)
> Entering new LLMBashCha... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_bash.html" |
b8f5b73a600c-0 | .ipynb
.pdf
LLMCheckerChain
LLMCheckerChain#
This notebook showcases how to use LLMCheckerChain.
from langchain.chains import LLMCheckerChain
from langchain.llms import OpenAI
llm = OpenAI(temperature=0.7)
text = "What type of mammal lays the biggest eggs?"
checker_chain = LLMCheckerChain(llm=llm, verbose=True)
checker... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_checker.html" |
3d47da343978-0 | .ipynb
.pdf
LLM Math
Contents
Customize Prompt
LLM Math#
This notebook showcases using LLMs and Python REPLs to do complex word math problems.
from langchain import OpenAI, LLMMathChain
llm = OpenAI(temperature=0)
llm_math = LLMMathChain(llm=llm, verbose=True)
llm_math.run("What is 13 raised to the .3432 power?")
> E... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_math.html" |
3d47da343978-1 | ${{Output of your code}}
```
Answer: ${{Answer}}
Begin.
Question: What is 37593 * 67?
```python
import numpy as np
print(np.multiply(37593, 67))
```
```output
2518731
```
Answer: 2518731
Question: {question}"""
PROMPT = PromptTemplate(input_variables=["question"], template=_PROMPT_TEMPLATE)
llm_math = LLMMathChain(llm=... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_math.html" |
8accb4960c15-0 | .ipynb
.pdf
LLMRequestsChain
LLMRequestsChain#
Using the request library to get HTML results from a URL and then an LLM to parse results
from langchain.llms import OpenAI
from langchain.chains import LLMRequestsChain, LLMChain
from langchain.prompts import PromptTemplate
template = """Between >>> and <<< are the raw se... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_requests.html" |
3e33e085e24c-0 | .ipynb
.pdf
LLMSummarizationCheckerChain
LLMSummarizationCheckerChain#
This notebook shows some examples of LLMSummarizationCheckerChain in use with different types of texts. It has a few distinct differences from the LLMCheckerChain, in that it doesn’t have any assumtions to the format of the input text (or summary).... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-1 | • JWST took the very first pictures of a planet outside of our own solar system. These distant worlds are called "exoplanets." Exo means "from outside."
These discoveries can spark a child's imagination about the infinite wonders of the universe."""
checker_chain.run(text)
> Entering new LLMSummarizationCheckerChain ch... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-2 | • JWST took the very first pictures of a planet outside of our own solar system.
• These distant worlds are called "exoplanets."
"""
For each fact, determine whether it is true or false about the subject. If you are unable to determine whether the fact is true or false, output "Undetermined".
If the fact is false, expl... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-3 | These discoveries can spark a child's imagination about the infinite wonders of the universe.
"""
Using these checked assertions, rewrite the original summary to be completely true.
The output should have the same structure and formatting as the original summary.
Summary:
> Finished chain.
> Entering new LLMChain chain... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-4 | • In 2023, The JWST spotted a number of galaxies nicknamed "green peas." They were given this name because they are small, round, and green, like peas.
• The telescope captured images of galaxies that are over 13 billion years old. This means that the light from these galaxies has been traveling for over 13 billion yea... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-5 | > Finished chain.
> Entering new LLMChain chain...
Prompt after formatting:
You are an expert fact checker. You have been hired by a major news organization to fact check a very important story.
Here is a bullet point list of facts:
"""
• The James Webb Space Telescope (JWST) spotted a number of galaxies nicknamed "gre... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-6 | • Exoplanets were first discovered in 1992. - True
• The JWST has allowed us to see exoplanets in greater detail. - Undetermined. It is too early to tell as the JWST has not been launched yet.
"""
Original Summary:
"""
Your 9-year old might like these recent discoveries made by The James Webb Space Telescope (JWST):
•... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-7 | Checked Assertions: """
- The sky is blue: True
- Water is wet: True
- The sun is a star: True
"""
Result: True
===
Checked Assertions: """
- The sky is blue - True
- Water is made of lava- False
- The sun is a star - True
"""
Result: False
===
Checked Assertions:"""
• The James Webb Space Telescope (JWST) spotted a nu... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-8 | These discoveries can spark a child's imagination about the infinite wonders of the universe.
> Finished chain.
'Your 9-year old might like these recent discoveries made by The James Webb Space Telescope (JWST):\n• In 2023, The JWST will spot a number of galaxies nicknamed "green peas." They were given this name becaus... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-9 | checker_chain.run(text)
> Entering new LLMSummarizationCheckerChain chain...
> Entering new SequentialChain chain...
> Entering new LLMChain chain...
Prompt after formatting:
Given some text, extract a list of facts from the text.
Format your output as a bulleted list.
Text:
"""
The Greenland Sea is an outlying portion... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-10 | - The sea is named after the island of Greenland.
- It is the Arctic Ocean's main outlet to the Atlantic.
- It is often frozen over so navigation is limited.
- It is considered the northern branch of the Norwegian Sea.
"""
For each fact, determine whether it is true or false about the subject. If you are unable to dete... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-11 | - It is considered the northern branch of the Norwegian Sea. True
"""
Original Summary:"""
The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. It has an area of 465,000 square miles and is one of five oceans in the world, alongside the Pa... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-12 | """
Result: False
===
Checked Assertions:"""
- The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. True
- It has an area of 465,000 square miles. True
- It is one of five oceans in the world, alongside the Pacific Ocean, Atlantic Ocean, I... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-13 | Format your output as a bulleted list.
Text:
"""
The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. It has an area of 465,000 square miles and is an arm of the Arctic Ocean. It is covered almost entirely by water, some of which is frozen... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-14 | > Finished chain.
> Entering new LLMChain chain...
Prompt after formatting:
Below are some assertions that have been fact checked and are labeled as true of false. If the answer is false, a suggestion is given for a correction.
Checked Assertions:"""
- The Greenland Sea is an outlying portion of the Arctic Ocean locat... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-15 | > Finished chain.
> Entering new LLMChain chain...
Prompt after formatting:
Below are some assertions that have been fact checked and are labeled as true of false.
If all of the assertions are true, return "True". If any of the assertions are false, return "False".
Here are some examples:
===
Checked Assertions: """
- ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-16 | """
Result:
> Finished chain.
> Finished chain.
The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. It has an area of 465,000 square miles and is an arm of the Arctic Ocean. It is covered almost entirely by water, some of which is frozen ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-17 | - It has an area of 465,000 square miles.
- It is covered almost entirely by water, some of which is frozen in the form of glaciers and icebergs.
- The sea is named after the country of Greenland.
- It is the Arctic Ocean's main outlet to the Atlantic.
- It is often frozen over so navigation is limited.
- It is conside... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-18 | """
Original Summary:"""
The Greenland Sea is an outlying portion of the Arctic Ocean located between Iceland, Norway, the Svalbard archipelago and Greenland. It has an area of 465,000 square miles and is an arm of the Arctic Ocean. It is covered almost entirely by water, some of which is frozen in the form of glaciers... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-19 | - It has an area of 465,000 square miles. True
- It is covered almost entirely by water, some of which is frozen in the form of glaciers and icebergs. True
- The sea is named after the country of Greenland. True
- It is the Arctic Ocean's main outlet to the Atlantic. False - The Arctic Ocean's main outlet to the Atlant... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-20 | from langchain.llms import OpenAI
llm = OpenAI(temperature=0)
checker_chain = LLMSummarizationCheckerChain(llm=llm, max_checks=3, verbose=True)
text = "Mammals can lay eggs, birds can lay eggs, therefore birds are mammals."
checker_chain.run(text)
> Entering new LLMSummarizationCheckerChain chain...
> Entering new Sequ... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-21 | - Birds can lay eggs: True. Birds are capable of laying eggs.
- Birds are mammals: False. Birds are not mammals, they are a class of their own.
"""
Original Summary:
"""
Mammals can lay eggs, birds can lay eggs, therefore birds are mammals.
"""
Using these checked assertions, rewrite the original summary to be complete... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
3e33e085e24c-22 | > Entering new SequentialChain chain...
> Entering new LLMChain chain...
Prompt after formatting:
Given some text, extract a list of facts from the text.
Format your output as a bulleted list.
Text:
"""
Birds and mammals are both capable of laying eggs, however birds are not mammals, they are a class of their own.
"""... | ERROR: type should be string, got "https://langchain.readthedocs.io\\en\\latest\\modules\\chains\\examples\\llm_summarization_checker.html" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.