id stringlengths 14 16 | text stringlengths 36 2.73k | source stringlengths 59 127 |
|---|---|---|
67d5164aeffc-1 | Run the LLMChain#
Provide a question and run the LLMChain.
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.run(question)
previous
OpenLM
next
PipelineAI
Contents
Install petals
Imports
Set the Environment API Key
Create the Petals instance
Create a Prompt Template
Initiat... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/petals_example.html |
9386da21ec7c-0 | .ipynb
.pdf
DeepInfra
DeepInfra#
DeepInfra is a serverless inference as a service that provides access to a variety of LLMs and embeddings models. This notebook goes over how to use LangChain with DeepInfra for text embeddings.
# sign up for an account: https://deepinfra.com/login?utm_source=langchain
from getpass impo... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/deepinfra.html |
642a86539da2-0 | .ipynb
.pdf
MosaicML
MosaicML#
MosaicML offers a managed inference service. You can either use a variety of open source models, or deploy your own.
This example goes over how to use LangChain to interact with MosaicML Inference for text embedding.
# sign up for an account: https://forms.mosaicml.com/demo?utm_source=lan... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/mosaicml.html |
1c497848ecea-0 | .ipynb
.pdf
Embaas
Contents
Prerequisites
Embaas#
embaas is a fully managed NLP API service that offers features like embedding generation, document text extraction, document to embeddings and more. You can choose a variety of pre-trained models.
In this tutorial, we will show you how to use the embaas Embeddings API... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/embaas.html |
68c95a437309-0 | .ipynb
.pdf
Elasticsearch
Contents
Testing with from_credentials
Testing with Existing Elasticsearch client connection
Elasticsearch#
Walkthrough of how to generate embeddings using a hosted embedding model in Elasticsearch
The easiest way to instantiate the ElasticsearchEmebddings class it either
using the from_cred... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/elasticsearch.html |
68c95a437309-1 | model_id,
es_connection,
)
# Create embeddings for multiple documents
documents = [
'This is an example document.',
'Another example document to generate embeddings for.'
]
document_embeddings = embeddings.embed_documents(documents)
# Print document embeddings
for i, embedding in enumerate(document_embedding... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/elasticsearch.html |
7f23961ecb0d-0 | .ipynb
.pdf
Hugging Face Hub
Hugging Face Hub#
Let’s load the Hugging Face Embedding class.
from langchain.embeddings import HuggingFaceEmbeddings
embeddings = HuggingFaceEmbeddings()
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([text])
previous
G... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/huggingface_hub.html |
64949d0198ef-0 | .ipynb
.pdf
Google Vertex AI PaLM
Google Vertex AI PaLM#
Note: This is seperate from the Google PaLM integration. Google has chosen to offer an enterprise version of PaLM through GCP, and this supports the models made available through there.
PaLM API on Vertex AI is a Preview offering, subject to the Pre-GA Offerings ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/google_vertex_ai_palm.html |
64949d0198ef-1 | previous
Fake Embeddings
next
Hugging Face Hub
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/google_vertex_ai_palm.html |
40820654e718-0 | .ipynb
.pdf
OpenAI
OpenAI#
Let’s load the OpenAI Embedding class.
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([text])
Let’s load the OpenAI Embedding class with fir... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/openai.html |
d3cb35c4f73e-0 | .ipynb
.pdf
Cohere
Cohere#
Let’s load the Cohere Embedding class.
from langchain.embeddings import CohereEmbeddings
embeddings = CohereEmbeddings(cohere_api_key=cohere_api_key)
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([text])
previous
Azure Op... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/cohere.html |
9186494c5fff-0 | .ipynb
.pdf
Jina
Jina#
Let’s load the Jina Embedding class.
from langchain.embeddings import JinaEmbeddings
embeddings = JinaEmbeddings(jina_auth_token=jina_auth_token, model_name="ViT-B-32::openai")
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([t... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/jina.html |
74737191062f-0 | .ipynb
.pdf
Sentence Transformers
Sentence Transformers#
Sentence Transformers embeddings are called using the HuggingFaceEmbeddings integration. We have also added an alias for SentenceTransformerEmbeddings for users who are more familiar with directly using that package.
SentenceTransformers is a python package that ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/sentence_transformers.html |
850b7d0ec704-0 | .ipynb
.pdf
Fake Embeddings
Fake Embeddings#
LangChain also provides a fake embedding class. You can use this to test your pipelines.
from langchain.embeddings import FakeEmbeddings
embeddings = FakeEmbeddings(size=1352)
query_result = embeddings.embed_query("foo")
doc_results = embeddings.embed_documents(["foo"])
prev... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/fake.html |
fef7097fd556-0 | .ipynb
.pdf
Llama-cpp
Llama-cpp#
This notebook goes over how to use Llama-cpp embeddings within LangChain
!pip install llama-cpp-python
from langchain.embeddings import LlamaCppEmbeddings
llama = LlamaCppEmbeddings(model_path="/path/to/model/ggml-model-q4_0.bin")
text = "This is a test document."
query_result = llama.e... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/llamacpp.html |
7a5abbfe5867-0 | .ipynb
.pdf
ModelScope
ModelScope#
Let’s load the ModelScope Embedding class.
from langchain.embeddings import ModelScopeEmbeddings
model_id = "damo/nlp_corom_sentence-embedding_english-base"
embeddings = ModelScopeEmbeddings(model_id=model_id)
text = "This is a test document."
query_result = embeddings.embed_query(tex... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/modelscope_hub.html |
384e546c1936-0 | .ipynb
.pdf
Amazon Bedrock
Amazon Bedrock#
Amazon Bedrock is a fully managed service that makes FMs from leading AI startups and Amazon available via an API, so you can choose from a wide range of FMs to find the model that is best suited for your use case.
%pip install boto3
from langchain.embeddings import BedrockEmb... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/amazon_bedrock.html |
08d1c2d9d83b-0 | .ipynb
.pdf
Tensorflow Hub
Tensorflow Hub#
TensorFlow Hub is a repository of trained machine learning models ready for fine-tuning and deployable anywhere.
TensorFlow Hub lets you search and discover hundreds of trained, ready-to-deploy machine learning models in one place.
from langchain.embeddings import TensorflowHu... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/tensorflowhub.html |
f4bebc6cf2c9-0 | .ipynb
.pdf
SageMaker Endpoint
SageMaker Endpoint#
Let’s load the SageMaker Endpoints Embeddings class. The class can be used if you host, e.g. your own Hugging Face model on SageMaker.
For instructions on how to do this, please see here. Note: In order to handle batched requests, you will need to adjust the return lin... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/sagemaker-endpoint.html |
f4bebc6cf2c9-1 | doc_results = embeddings.embed_documents(["foo"])
doc_results
previous
OpenAI
next
Self Hosted Embeddings
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/sagemaker-endpoint.html |
97c837944dc0-0 | .ipynb
.pdf
MiniMax
MiniMax#
MiniMax offers an embeddings service.
This example goes over how to use LangChain to interact with MiniMax Inference for text embedding.
import os
os.environ["MINIMAX_GROUP_ID"] = "MINIMAX_GROUP_ID"
os.environ["MINIMAX_API_KEY"] = "MINIMAX_API_KEY"
from langchain.embeddings import MiniMaxEm... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/minimax.html |
2b528908403b-0 | .ipynb
.pdf
HuggingFace Instruct
HuggingFace Instruct#
Let’s load the HuggingFace instruct Embeddings class.
from langchain.embeddings import HuggingFaceInstructEmbeddings
embeddings = HuggingFaceInstructEmbeddings(
query_instruction="Represent the query for retrieval: "
)
load INSTRUCTOR_Transformer
max_seq_length... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/huggingface_instruct.html |
fdac9eca4e09-0 | .ipynb
.pdf
Azure OpenAI
Azure OpenAI#
Let’s load the OpenAI Embedding class with environment variables set to indicate to use Azure endpoints.
# set the environment variables needed for openai package to know to reach out to azure
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_BASE"] = "https... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/azureopenai.html |
6ec81217b6f6-0 | .ipynb
.pdf
Self Hosted Embeddings
Self Hosted Embeddings#
Let’s load the SelfHostedEmbeddings, SelfHostedHuggingFaceEmbeddings, and SelfHostedHuggingFaceInstructEmbeddings classes.
from langchain.embeddings import (
SelfHostedEmbeddings,
SelfHostedHuggingFaceEmbeddings,
SelfHostedHuggingFaceInstructEmbeddi... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/self-hosted.html |
6ec81217b6f6-1 | tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
return pipeline("feature-extraction", model=model, tokenizer=tokenizer)
def inference_fn(pipeline, prompt):
# Return last hidden state of the model
if isinstance(prompt, list):
return [emb[... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/self-hosted.html |
8d8e660261c2-0 | .ipynb
.pdf
Aleph Alpha
Contents
Asymmetric
Symmetric
Aleph Alpha#
There are two possible ways to use Aleph Alpha’s semantic embeddings. If you have texts with a dissimilar structure (e.g. a Document and a Query) you would want to use asymmetric embeddings. Conversely, for texts with comparable structures, symmetric ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/aleph_alpha.html |
f3bfccb018ff-0 | .ipynb
.pdf
DashScope
DashScope#
Let’s load the DashScope Embedding class.
from langchain.embeddings import DashScopeEmbeddings
embeddings = DashScopeEmbeddings(model='text-embedding-v1', dashscope_api_key='your-dashscope-api-key')
text = "This is a test document."
query_result = embeddings.embed_query(text)
print(quer... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/text_embedding/examples/dashscope.html |
7685d96e1887-0 | .rst
.pdf
How-To Guides
How-To Guides#
The examples here all address certain “how-to” guides for working with chat models.
How to use few shot examples
How to stream responses
previous
Getting Started
next
How to use few shot examples
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/how_to_guides.html |
d8f7f4f95a55-0 | .rst
.pdf
Integrations
Integrations#
The examples here all highlight how to integrate with different chat models.
Anthropic
Azure
Google Vertex AI PaLM
OpenAI
PromptLayer ChatOpenAI
previous
How to stream responses
next
Anthropic
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Ju... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations.html |
fd9046c51704-0 | .ipynb
.pdf
Getting Started
Contents
PromptTemplates
LLMChain
Streaming
Getting Started#
This notebook covers how to get started with chat models. The interface is based around messages rather than raw text.
from langchain.chat_models import ChatOpenAI
from langchain import PromptTemplate, LLMChain
from langchain.pro... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/getting_started.html |
fd9046c51704-1 | [
SystemMessage(content="You are a helpful assistant that translates English to French."),
HumanMessage(content="I love programming.")
],
[
SystemMessage(content="You are a helpful assistant that translates English to French."),
HumanMessage(content="I love artificial intelligenc... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/getting_started.html |
fd9046c51704-2 | system_message_prompt = SystemMessagePromptTemplate.from_template(template)
human_template="{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
# get a chat completion from the formatted mes... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/getting_started.html |
fd9046c51704-3 | A drink that's always on my mind
With every sip, I feel alive
Sparkling water, you're my vibe
Verse 2:
No sugar, no calories, just pure bliss
A drink that's hard to resist
It's the perfect way to quench my thirst
A drink that always comes first
Chorus:
Sparkling water, oh so fine
A drink that's always on my mind
With e... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/getting_started.html |
8082146b6861-0 | .ipynb
.pdf
How to use few shot examples
Contents
Alternating Human/AI messages
System Messages
How to use few shot examples#
This notebook covers how to use few shot examples in chat models.
There does not appear to be solid consensus on how best to do few shot prompting. As a result, we are not solidifying any abst... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/examples/few_shot_examples.html |
8082146b6861-1 | template="You are a helpful assistant that translates english to pirate."
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
example_human = SystemMessagePromptTemplate.from_template("Hi", additional_kwargs={"name": "example_user"})
example_ai = SystemMessagePromptTemplate.from_template("Argh m... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/examples/few_shot_examples.html |
7c4d9b951887-0 | .ipynb
.pdf
How to stream responses
How to stream responses#
This notebook goes over how to use streaming with a chat model.
from langchain.chat_models import ChatOpenAI
from langchain.schema import (
HumanMessage,
)
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
chat = ChatOpenAI(s... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/examples/streaming.html |
7c4d9b951887-1 | How to use few shot examples
next
Integrations
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/examples/streaming.html |
bcf9d56ff3c9-0 | .ipynb
.pdf
Google Vertex AI PaLM
Google Vertex AI PaLM#
Vertex AI is a machine learning (ML)
platform that lets you train and deploy ML models and AI applications.
Vertex AI combines data engineering, data science, and ML engineering workflows, enabling your teams to
collaborate using a common toolset.
Note: This is s... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/google_vertex_ai_palm.html |
bcf9d56ff3c9-1 | from langchain.chat_models import ChatVertexAI
from langchain.prompts.chat import (
ChatPromptTemplate,
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
)
from langchain.schema import (
HumanMessage,
SystemMessage
)
chat = ChatVertexAI()
messages = [
SystemMessage(content="You are a help... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/google_vertex_ai_palm.html |
bcf9d56ff3c9-2 | previous
Azure
next
OpenAI
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/google_vertex_ai_palm.html |
6bbb22a8d636-0 | .ipynb
.pdf
OpenAI
OpenAI#
This notebook covers how to get started with OpenAI chat models.
from langchain.chat_models import ChatOpenAI
from langchain.prompts.chat import (
ChatPromptTemplate,
SystemMessagePromptTemplate,
AIMessagePromptTemplate,
HumanMessagePromptTemplate,
)
from langchain.schema impo... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/openai.html |
6bbb22a8d636-1 | AIMessage(content="J'adore la programmation.", additional_kwargs={})
previous
Google Vertex AI PaLM
next
PromptLayer ChatOpenAI
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/openai.html |
9cbe44a3ed91-0 | .ipynb
.pdf
Azure
Azure#
This notebook goes over how to connect to an Azure hosted OpenAI endpoint
from langchain.chat_models import AzureChatOpenAI
from langchain.schema import HumanMessage
BASE_URL = "https://${TODO}.openai.azure.com"
API_KEY = "..."
DEPLOYMENT_NAME = "chat"
model = AzureChatOpenAI(
openai_api_ba... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/azure_chat_openai.html |
122182d7f8a0-0 | .ipynb
.pdf
Anthropic
Contents
ChatAnthropic also supports async and streaming functionality:
Anthropic#
Anthropic is an American artificial intelligence (AI) startup and
public-benefit corporation, founded by former members of OpenAI. Anthropic specializes in developing general AI
systems and language models, with a... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/anthropic.html |
122182d7f8a0-1 | next
Azure
Contents
ChatAnthropic also supports async and streaming functionality:
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/anthropic.html |
ac448989f9c5-0 | .ipynb
.pdf
PromptLayer ChatOpenAI
Contents
Install PromptLayer
Imports
Set the Environment API Key
Use the PromptLayerOpenAI LLM like normal
Using PromptLayer Track
PromptLayer ChatOpenAI#
PromptLayer
is a devtool that allows you to track, manage, and share your GPT prompt engineering.
It acts as a middleware betwee... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/promptlayer_chatopenai.html |
ac448989f9c5-1 | The above request should now appear on your PromptLayer dashboard.
Using PromptLayer Track#
If you would like to use any of the PromptLayer tracking features, you need to pass the argument return_pl_id when instantializing the PromptLayer LLM to get the request id.
chat = PromptLayerChatOpenAI(return_pl_id=True)
chat_r... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/chat/integrations/promptlayer_chatopenai.html |
d7a415231675-0 | .rst
.pdf
Toolkits
Toolkits#
Note
Conceptual Guide
This section of documentation covers agents with toolkits - eg an agent applied to a particular use case.
See below for a full list of agent toolkits
Azure Cognitive Services Toolkit
CSV Agent
Gmail Toolkit
Jira
JSON Agent
OpenAPI agents
Natural Language APIs
Pandas Da... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/toolkits.html |
68443427c332-0 | .rst
.pdf
Agents
Agents#
Note
Conceptual Guide
In this part of the documentation we cover the different types of agents, disregarding which specific tools they are used with.
For a high level overview of the different types of agents, see the below documentation.
Agent Types
For documentation on how to create a custom ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agents.html |
3dd54032348a-0 | .rst
.pdf
Tools
Tools#
Note
Conceptual Guide
Tools are ways that an agent can use to interact with the outside world.
For an overview of what a tool is, how to use them, and a full list of examples, please see the getting started documentation
Getting Started
Next, we have some examples of customizing and generically w... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/tools.html |
2277d2ae8316-0 | .rst
.pdf
Agent Executors
Agent Executors#
Note
Conceptual Guide
Agent executors take an agent and tools and use the agent to decide which tools to call and in what order.
In this part of the documentation we cover other related functionality to agent executors
How to combine agents and vectorstores
How to use the asyn... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors.html |
b3fcbb0000cc-0 | .ipynb
.pdf
Getting Started
Getting Started#
Agents use an LLM to determine which actions to take and in what order.
An action can either be using a tool and observing its output, or returning to the user.
When used correctly agents can be extremely powerful. The purpose of this notebook is to show you how to easily us... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/getting_started.html |
b3fcbb0000cc-1 | agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
Now let’s test it out!
agent.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?")
> Entering new AgentExecutor chain...
I need to find out who Leo DiCaprio's girlfriend is and then calc... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/getting_started.html |
0af52c06d29e-0 | .ipynb
.pdf
Plan and Execute
Contents
Plan and Execute
Imports
Tools
Planner, Executor, and Agent
Run Example
Plan and Execute#
Plan and execute agents accomplish an objective by first planning what to do, then executing the sub tasks. This idea is largely inspired by BabyAGI and then the “Plan-and-Solve” paper.
The ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/plan_and_execute.html |
0af52c06d29e-1 | > Entering new PlanAndExecute chain...
steps=[Step(value="Search for Leo DiCaprio's girlfriend on the internet."), Step(value='Find her current age.'), Step(value='Raise her current age to the 0.43 power using a calculator or programming language.'), Step(value='Output the result.'), Step(value="Given the above steps t... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/plan_and_execute.html |
0af52c06d29e-2 | Current objective: value='Find her current age.'
Action:
```
{
"action": "Search",
"action_input": "What is Gigi Hadid's current age?"
}
```
Observation: 28 years
Thought:Previous steps: steps=[(Step(value="Search for Leo DiCaprio's girlfriend on the internet."), StepResponse(response='Leo DiCaprio is currently lin... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/plan_and_execute.html |
0af52c06d29e-3 | Response: Gigi Hadid's current age raised to the 0.43 power is approximately 4.19.
> Entering new AgentExecutor chain...
Action:
```
{
"action": "Final Answer",
"action_input": "The result is approximately 4.19."
}
```
> Finished chain.
*****
Step: Output the result.
Response: The result is approximately 4.19.
> En... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/plan_and_execute.html |
e2d0363b0bb5-0 | .ipynb
.pdf
How to use a timeout for the agent
How to use a timeout for the agent#
This notebook walks through how to cap an agent executor after a certain amount of time. This can be useful for safeguarding against long running agent runs.
from langchain.agents import load_tools
from langchain.agents import initialize... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/max_time_limit.html |
e2d0363b0bb5-1 | Final Answer: foo
> Finished chain.
'foo'
Now let’s try it again with the max_execution_time=1 keyword argument. It now stops nicely after 1 second (only one iteration usually)
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, max_execution_time=1)
agent.run(adversarial_pro... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/max_time_limit.html |
5668d84cc6bc-0 | .ipynb
.pdf
How to combine agents and vectorstores
Contents
Create the Vectorstore
Create the Agent
Use the Agent solely as a router
Multi-Hop vectorstore reasoning
How to combine agents and vectorstores#
This notebook covers how to combine agents and vectorstores. The use case for this is that you’ve ingested your d... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/agent_vectorstore.html |
5668d84cc6bc-1 | texts = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
docsearch = Chroma.from_documents(texts, embeddings, collection_name="state-of-union")
Running Chroma using direct local API.
Using DuckDB in-memory for database. Data will be transient.
state_of_union = RetrievalQA.from_chain_type(llm=llm... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/agent_vectorstore.html |
5668d84cc6bc-2 | ),
]
# Construct the agent. We will use the default agent type here.
# See documentation for a full list of options.
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
agent.run("What did biden say about ketanji brown jackson in the state of the union address?")
> Entering n... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/agent_vectorstore.html |
5668d84cc6bc-3 | Action Input: What are the advantages of using ruff over flake8?
Observation: Ruff can be used as a drop-in replacement for Flake8 when used (1) without or with a small number of plugins, (2) alongside Black, and (3) on Python 3 code. It also re-implements some of the most popular Flake8 plugins and related code quali... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/agent_vectorstore.html |
5668d84cc6bc-4 | Notice that in the above examples the agent did some extra work after querying the RetrievalQAChain. You can avoid that and just return the result directly.
tools = [
Tool(
name = "State of Union QA System",
func=state_of_union.run,
description="useful for when you need to answer questions a... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/agent_vectorstore.html |
5668d84cc6bc-5 | Action: Ruff QA System
Action Input: What are the advantages of using ruff over flake8?
Observation: Ruff can be used as a drop-in replacement for Flake8 when used (1) without or with a small number of plugins, (2) alongside Black, and (3) on Python 3 code. It also re-implements some of the most popular Flake8 plugins... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/agent_vectorstore.html |
5668d84cc6bc-6 | name = "Ruff QA System",
func=ruff.run,
description="useful for when you need to answer questions about ruff (a python linter). Input should be a fully formed question, not referencing any obscure pronouns from the conversation before."
),
]
# Construct the agent. We will use the default agent type ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/agent_vectorstore.html |
5668d84cc6bc-7 | previous
Agent Executors
next
How to use the async API for Agents
Contents
Create the Vectorstore
Create the Agent
Use the Agent solely as a router
Multi-Hop vectorstore reasoning
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/agent_vectorstore.html |
fa22da745ab3-0 | .ipynb
.pdf
Handle Parsing Errors
Contents
Setup
Error
Default error handling
Custom Error Message
Custom Error Function
Handle Parsing Errors#
Occasionally the LLM cannot determine what step to take because it outputs format in incorrect form to be handled by the output parser. In this case, by default the agent err... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/handle_parsing_errors.html |
fa22da745ab3-1 | IndexError: list index out of range
During handling of the above exception, another exception occurred:
OutputParserException Traceback (most recent call last)
Cell In[4], line 1
----> 1 mrkl.run("Who is Leo DiCaprio's girlfriend? No need to add Action")
File ~/workplace/langchain/langchain/chains/b... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/handle_parsing_errors.html |
fa22da745ab3-2 | 136 else self._call(inputs)
137 )
138 except (KeyboardInterrupt, Exception) as e:
139 run_manager.on_chain_error(e)
File ~/workplace/langchain/langchain/agents/agent.py:947, in AgentExecutor._call(self, inputs, run_manager)
945 # We now enter the agent loop (until it returns something).
... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/handle_parsing_errors.html |
fa22da745ab3-3 | 759 """
760 try:
761 # Call the LLM to see what to do.
--> 762 output = self.agent.plan(
763 intermediate_steps,
764 callbacks=run_manager.get_child() if run_manager else None,
765 **inputs,
766 )
767 except OutputParserException as e:
768 if isins... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/handle_parsing_errors.html |
fa22da745ab3-4 | > Entering new AgentExecutor chain...
Observation: Invalid or incomplete response
Thought:
Observation: Invalid or incomplete response
Thought:Search for Leo DiCaprio's current girlfriend
Action:
```
{
"action": "Search",
"action_input": "Leo DiCaprio current girlfriend"
}
```
Observation: Just Jared on Instagram: ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/handle_parsing_errors.html |
fa22da745ab3-5 | Thought:The answer to the question is that Leo DiCaprio's current girlfriend is Gigi Hadid.
Final Answer: Gigi Hadid.
> Finished chain.
'Gigi Hadid.'
Custom Error Function#
You can also customize the error to be a function that takes the error in and outputs a string.
def _handle_error(error) -> str:
return str(er... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/handle_parsing_errors.html |
fa22da745ab3-6 | Error
Default error handling
Custom Error Message
Custom Error Function
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/handle_parsing_errors.html |
e1e167e104b2-0 | .ipynb
.pdf
How to use the async API for Agents
Contents
Serial vs. Concurrent Execution
How to use the async API for Agents#
LangChain provides async support for Agents by leveraging the asyncio library.
Async methods are currently supported for the following Tools: GoogleSerperAPIWrapper, SerpAPIWrapper and LLMMath... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-1 | ]
llm = OpenAI(temperature=0)
tools = load_tools(["google-serper", "llm-math"], llm=llm)
agent = initialize_agent(
tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
s = time.perf_counter()
for q in questions:
agent.run(q)
elapsed = time.perf_counter() - s
print(f"Serial executed in {elapse... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-2 | Observation: Rafael Nadal defeated Daniil Medvedev in the final, 7–5, 6–3, 5–7, 4–6, 6–4 to win the men's singles tennis title at the 2019 US Open. It was his fourth US ... Draw: 128 (16 Q / 8 WC). Champion: Rafael Nadal. Runner-up: Daniil Medvedev. Score: 7–5, 6–3, 5–7, 4–6, 6–4. Bianca Andreescu won the women's singl... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-3 | “super happy to be back in the ... Watch the full match between Daniil Medvedev and Rafael ... Duration: 4:47:32. Posted: Mar 20, 2020. US Open 2019: Rafael Nadal beats Daniil Medvedev · Updated: Sep. 08, 2019, 11:11 p.m. |; Published: Sep · Published: Sep. 08, 2019, 10:06 p.m.. 26. US Open ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-4 | Thought: I now know that Rafael Nadal won the US Open men's final in 2019 and he is 33 years old.
Action: Calculator
Action Input: 33^0.334
Observation: Answer: 3.215019829667466
Thought: I now know the final answer.
Final Answer: Rafael Nadal won the US Open men's final in 2019 and his age raised to the 0.334 power is... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-5 | Action: Google Serper
Action Input: "who won the most recent formula 1 grand prix"
Observation: Max Verstappen won his first Formula 1 world title on Sunday after the championship was decided by a last-lap overtake of his rival Lewis Hamilton in the Abu Dhabi Grand Prix. Dec 12, 2021
Thought: I need to find out Max Ver... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-6 | Observation: Answer: 2.7212987634680084
Thought: I now know the final answer.
Final Answer: Nineteen-year-old Canadian Bianca Andreescu won the US Open women's final in 2019 and her age raised to the 0.34 power is 2.7212987634680084.
> Finished chain.
> Entering new AgentExecutor chain...
I need to find out who Beyonc... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-7 | await asyncio.gather(*tasks)
elapsed = time.perf_counter() - s
print(f"Concurrent executed in {elapsed:0.2f} seconds.")
> Entering new AgentExecutor chain...
> Entering new AgentExecutor chain...
> Entering new AgentExecutor chain...
> Entering new AgentExecutor chain...
> Entering new AgentExecutor chain...
I need to... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-8 | Thought:
Observation: Jay-Z
Thought: | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-9 | Observation: Rafael Nadal defeated Daniil Medvedev in the final, 7–5, 6–3, 5–7, 4–6, 6–4 to win the men's singles tennis title at the 2019 US Open. It was his fourth US ... Draw: 128 (16 Q / 8 WC). Champion: Rafael Nadal. Runner-up: Daniil Medvedev. Score: 7–5, 6–3, 5–7, 4–6, 6–4. Bianca Andreescu won the women's singl... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-10 | “super happy to be back in the ... Watch the full match between Daniil Medvedev and Rafael ... Duration: 4:47:32. Posted: Mar 20, 2020. US Open 2019: Rafael Nadal beats Daniil Medvedev · Updated: Sep. 08, 2019, 11:11 p.m. |; Published: Sep · Published: Sep. 08, 2019, 10:06 p.m.. 26. US Open ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-11 | Thought:
Observation: WHAT HAPPENED: #SheTheNorth? She the champion. Nineteen-year-old Canadian Bianca Andreescu sealed her first Grand Slam title on Saturday, downing 23-time major champion Serena Williams in the 2019 US Open women's singles final, 6-3, 7-5. Sep 7, 2019
Thought: | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-12 | Thought:
Observation: Lewis Hamilton holds the record for the most race wins in Formula One history, with 103 wins to date. Michael Schumacher, the previous record holder, ... Michael Schumacher (top left) and Lewis Hamilton (top right) have each won the championship a record seven times during their careers, while Seb... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-13 | Action Input: "Harry Styles age" I need to find out Jay-Z's age
Action: Google Serper
Action Input: "How old is Jay-Z?" I now know that Rafael Nadal won the US Open men's final in 2019 and he is 33 years old.
Action: Calculator
Action Input: 33^0.334 I now need to calculate her age raised to the 0.34 power.
Action: Cal... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
e1e167e104b2-14 | By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/async_agent.html |
fd753cfa7acd-0 | .ipynb
.pdf
How to create ChatGPT Clone
How to create ChatGPT Clone#
This chain replicates ChatGPT by combining (1) a specific prompt, and (2) the concept of memory.
Shows off the example as in https://www.engraved.blog/building-a-virtual-machine-inside/
from langchain import OpenAI, ConversationChain, LLMChain, Prompt... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-1 | llm=OpenAI(temperature=0),
prompt=prompt,
verbose=True,
memory=ConversationBufferWindowMemory(k=2),
)
output = chatgpt_chain.predict(human_input="I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal o... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-2 | Human: I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-3 | Human: I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-4 | Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
Human: I want you to act as a ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-5 | Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-6 | Prompt after formatting:
Assistant is a large language model trained by OpenAI.
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-li... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-7 | Assistant:
> Finished LLMChain chain.
```
$ echo -e "x=lambda y:y*5+3;print('Result:' + str(x(6)))" > run.py
$ python3 run.py
Result: 33
```
output = chatgpt_chain.predict(human_input="""echo -e "print(list(filter(lambda x: all(x%d for d in range(2,x)),range(2,3**10)))[:10])" > run.py && python3 run.py""")
print(output... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-8 | AI:
```
$ touch jokes.txt
$ echo "Why did the chicken cross the road? To get to the other side!" >> jokes.txt
$ echo "What did the fish say when it hit the wall? Dam!" >> jokes.txt
$ echo "Why did the scarecrow win the Nobel Prize? Because he was outstanding in his field!" >> jokes.txt
```
Human: echo -e "x=lambda y:y... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-9 | output = chatgpt_chain.predict(human_input=docker_input)
print(output)
> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanation... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
fd753cfa7acd-10 | AI:
```
$ echo -e "print(list(filter(lambda x: all(x%d for d in range(2,x)),range(2,3**10)))[:10])" > run.py
$ python3 run.py
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
```
Human: echo -e "echo 'Hello from Docker" > entrypoint.sh && echo -e "FROM ubuntu:20.04
COPY entrypoint.sh entrypoint.sh
ENTRYPOINT ["/bin/sh","entrypoin... | rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/chatgpt_clone.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.