id stringlengths 14 16 | text stringlengths 36 2.73k | source stringlengths 49 117 |
|---|---|---|
501c426628e3-3 | sample_rows = connection.execute(command)
SELECT "Title" FROM "Album" WHERE "ArtistId" IN (SELECT "ArtistId" FROM "Artist" WHERE "Name" = 'Alanis Morissette') LIMIT 5;
SQLResult: [('Jagged Little Pill',)]
Answer: Alanis Morissette has the album Jagged Little Pill in the database.
> Finished chain.
Observation: Alanis... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html |
d58c819c7377-0 | .ipynb
.pdf
ReAct
ReAct#
This notebook showcases using an agent to implement the ReAct logic.
from langchain import OpenAI, Wikipedia
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType
from langchain.agents.react.base import DocstoreExplorer
docstore=DocstoreExplorer(Wikipedia())... | https://python.langchain.com/en/latest/modules/agents/agents/examples/react.html |
d58c819c7377-1 | Action: Search[David Chanoff]
Observation: David Chanoff is a noted author of non-fiction work. His work has typically involved collaborations with the principal protagonist of the work concerned. His collaborators have included; Augustus A. White, Joycelyn Elders, Đoàn Văn Toại, William J. Crowe, Ariel Sharon, Kenneth... | https://python.langchain.com/en/latest/modules/agents/agents/examples/react.html |
661b07d29e01-0 | .ipynb
.pdf
Conversation Agent (for Chat Models)
Conversation Agent (for Chat Models)#
This notebook walks through using an agent optimized for conversation, using ChatModels. Other agents are often optimized for using tools to figure out the best response, which is not ideal in a conversational setting where you may w... | https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html |
661b07d29e01-1 | > Entering new AgentExecutor chain...
{
"action": "Final Answer",
"action_input": "Hello Bob! How can I assist you today?"
}
> Finished chain.
'Hello Bob! How can I assist you today?'
agent_chain.run(input="what's my name?")
> Entering new AgentExecutor chain...
{
"action": "Final Answer",
"action_input... | https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html |
661b07d29e01-2 | > Entering new AgentExecutor chain...
{
"action": "Final Answer",
"action_input": "The last letter in your name is 'b'. Argentina won the World Cup in 1978."
}
> Finished chain.
"The last letter in your name is 'b'. Argentina won the World Cup in 1978."
agent_chain.run(input="whats the weather like in pomfret?"... | https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html |
a48062db5877-0 | .ipynb
.pdf
Structured Tool Chat Agent
Contents
Initialize Tools
Adding in memory
Structured Tool Chat Agent#
This notebook walks through using a chat agent capable of using multi-input tools.
Older agents are configured to specify an action input as a single string, but this agent can use the provided tools’ args_sc... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-1 | print(response)
> Entering new AgentExecutor chain...
Action:
```
{
"action": "Final Answer",
"action_input": "Hello Erica, how can I assist you today?"
}
```
> Finished chain.
Hello Erica, how can I assist you today?
response = await agent_chain.arun(input="Don't need help really just chatting.")
print(response)
>... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-2 | We recently open-sourced an auto-evaluator tool for grading LLM question-answer chains. We are now releasing an open source, free to use hosted app and API to expand usability. Below we discuss a few opportunities to further improve May 1, 2023 5 min read Callbacks Improvements TL;DR: We're announcing improvements to o... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-3 | read Improving Document Retrieval with Contextual Compression Note: This post assumes some familiarity with LangChain and is moderately technical. | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-4 | 💡 TL;DR: We’ve introduced a new abstraction and a new document Retriever to facilitate the post-processing of retrieved documents. Specifically, the new abstraction makes it easy to take a set of retrieved documents and extract from them Apr 20, 2023 3 min read Autonomous Agents & Agent Simulations Over the past two w... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-5 | Context
Originally we designed LangChain.js to run in Node.js, which is the Apr 11, 2023 3 min read LangChain x Supabase Supabase is holding an AI Hackathon this week. Here at LangChain we are big fans of both Supabase and hackathons, so we thought this would be a perfect time to highlight the multiple ways you can use... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-6 | The reason we like Supabase so much is that Apr 8, 2023 2 min read Announcing our $10M seed round led by Benchmark It was only six months ago that we released the first version of LangChain, but it seems like several years. When we launched, generative AI was starting to go mainstream: stable diffusion had just been re... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-7 | becoming a bigger and bigger issue. People are starting to try to tackle this, with OpenAI releasing OpenAI/evals - focused on evaluating OpenAI models. Mar 14, 2023 3 min read LLMs and SQL Francisco Ingham and Jon Luo are two of the community members leading the change on the SQL integrations. We’re really excited to ... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-8 | Authors: Parth Asawa (pgasawa@), Ayushi Batwara (ayushi.batwara@), Jason Mar 8, 2023 4 min read Prompt Selectors One common complaint we've heard is that the default prompt templates do not work equally well for all models. This became especially pronounced this past week when OpenAI released a ChatGPT API. This new AP... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-9 | What does this mean? It means that all your favorite prompts, chains, and agents are all recreatable in TypeScript natively. Both the Python version and TypeScript version utilize the same serializable format, meaning that artifacts can seamlessly be shared between languages. As an Feb 17, 2023 2 min read Streaming Sup... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-10 | "url": "https://xkcd.com/"
}
}
```
Observation: Navigating to https://xkcd.com/ returned status code 200
Thought:I can extract the latest comic title and alt text using CSS selectors.
Action:
```
{
"action": "get_elements",
"action_input": {
"selector": "#ctitle, #comic img",
"attributes": ["alt", "src"]
... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
a48062db5877-11 | Action:
```
{
"action": "Final Answer",
"action_input": "Hi Erica! How can I assist you today?"
}
```
> Finished chain.
Hi Erica! How can I assist you today?
response = await agent_chain.arun(input="whats my name?")
print(response)
> Entering new AgentExecutor chain...
Your name is Erica.
> Finished chain.
Your nam... | https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html |
9a135c7ee5a1-0 | .ipynb
.pdf
MRKL
MRKL#
This notebook showcases using an agent to replicate the MRKL chain.
This uses the example Chinook database.
To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at the root of this repository.
from langchain import L... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html |
9a135c7ee5a1-1 | > Entering new AgentExecutor chain...
I need to find out who Leo DiCaprio's girlfriend is and then calculate her age raised to the 0.43 power.
Action: Search
Action Input: "Who is Leo DiCaprio's girlfriend?"
Observation: DiCaprio met actor Camila Morrone in December 2017, when she was 20 and he was 43. They were spott... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html |
9a135c7ee5a1-2 | > Entering new AgentExecutor chain...
I need to find out the artist's full name and then search the FooBar database for their albums.
Action: Search
Action Input: "The Storm Before the Calm" artist
Observation: The Storm Before the Calm (stylized in all lowercase) is the tenth (and eighth international) studio album b... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html |
9a135c7ee5a1-3 | Thought: I now know the final answer.
Final Answer: The artist who released the album 'The Storm Before the Calm' is Alanis Morissette and the albums of hers in the FooBar database are Jagged Little Pill.
> Finished chain.
"The artist who released the album 'The Storm Before the Calm' is Alanis Morissette and the album... | https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html |
3ffa4eae876e-0 | .ipynb
.pdf
Self Ask With Search
Self Ask With Search#
This notebook showcases the Self Ask With Search chain.
from langchain import OpenAI, SerpAPIWrapper
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType
llm = OpenAI(temperature=0)
search = SerpAPIWrapper()
tools = [
Tool(... | https://python.langchain.com/en/latest/modules/agents/agents/examples/self_ask_with_search.html |
c87d4676b080-0 | .rst
.pdf
Text Embedding Models
Text Embedding Models#
Note
Conceptual Guide
This documentation goes over how to use the Embedding class in LangChain.
The Embedding class is a class designed for interfacing with embeddings. There are lots of Embedding providers (OpenAI, Cohere, Hugging Face, etc) - this class is design... | https://python.langchain.com/en/latest/modules/models/text_embedding.html |
6034ab79c307-0 | .ipynb
.pdf
Getting Started
Contents
Language Models
text -> text interface
messages -> message interface
Getting Started#
One of the core value props of LangChain is that it provides a standard interface to models. This allows you to swap easily between models. At a high level, there are two main types of models:
La... | https://python.langchain.com/en/latest/modules/models/getting_started.html |
6034ab79c307-1 | Language Models
text -> text interface
messages -> message interface
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/getting_started.html |
048018f2c8c9-0 | .rst
.pdf
Chat Models
Chat Models#
Note
Conceptual Guide
Chat models are a variation on language models.
While chat models use language models under the hood, the interface they expose is a bit different.
Rather than expose a “text in, text out” API, they expose an interface where “chat messages” are the inputs and out... | https://python.langchain.com/en/latest/modules/models/chat.html |
1f24f78ab49c-0 | .rst
.pdf
LLMs
LLMs#
Note
Conceptual Guide
Large Language Models (LLMs) are a core component of LangChain.
LangChain is not a provider of LLMs, but rather provides a standard interface through which
you can interact with a variety of LLMs.
The following sections of documentation are provided:
Getting Started: An overvi... | https://python.langchain.com/en/latest/modules/models/llms.html |
4127c6d996e4-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 ... | https://python.langchain.com/en/latest/modules/models/chat/how_to_guides.html |
62f35e37de3b-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... | https://python.langchain.com/en/latest/modules/models/chat/getting_started.html |
62f35e37de3b-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... | https://python.langchain.com/en/latest/modules/models/chat/getting_started.html |
62f35e37de3b-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... | https://python.langchain.com/en/latest/modules/models/chat/getting_started.html |
62f35e37de3b-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... | https://python.langchain.com/en/latest/modules/models/chat/getting_started.html |
8b6c5bc868ed-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... | https://python.langchain.com/en/latest/modules/models/chat/integrations.html |
81eb01c958f6-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... | https://python.langchain.com/en/latest/modules/models/chat/integrations/openai.html |
81eb01c958f6-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 11, 2023. | https://python.langchain.com/en/latest/modules/models/chat/integrations/openai.html |
f70596d57f6e-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... | https://python.langchain.com/en/latest/modules/models/chat/integrations/azure_chat_openai.html |
b084e3afdc09-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... | https://python.langchain.com/en/latest/modules/models/chat/integrations/promptlayer_chatopenai.html |
b084e3afdc09-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... | https://python.langchain.com/en/latest/modules/models/chat/integrations/promptlayer_chatopenai.html |
3e89088ce006-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... | https://python.langchain.com/en/latest/modules/models/chat/integrations/google_vertex_ai_palm.html |
3e89088ce006-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... | https://python.langchain.com/en/latest/modules/models/chat/integrations/google_vertex_ai_palm.html |
3e89088ce006-2 | previous
Azure
next
OpenAI
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/chat/integrations/google_vertex_ai_palm.html |
e471ff52bdba-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... | https://python.langchain.com/en/latest/modules/models/chat/integrations/anthropic.html |
e471ff52bdba-1 | next
Azure
Contents
ChatAnthropic also supports async and streaming functionality:
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/chat/integrations/anthropic.html |
5cfc1b12bdbf-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... | https://python.langchain.com/en/latest/modules/models/chat/examples/streaming.html |
5cfc1b12bdbf-1 | How to use few shot examples
next
Integrations
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/chat/examples/streaming.html |
858afc292d7e-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... | https://python.langchain.com/en/latest/modules/models/chat/examples/few_shot_examples.html |
858afc292d7e-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... | https://python.langchain.com/en/latest/modules/models/chat/examples/few_shot_examples.html |
c267f3c53ea0-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/self-hosted.html |
c267f3c53ea0-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[... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/self-hosted.html |
dc8f524aa8c9-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/llamacpp.html |
f2d0b0c04447-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/elasticsearch.html |
f2d0b0c04447-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/elasticsearch.html |
d8fff00fe48a-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/azureopenai.html |
9f225f40dd80-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/huggingface_hub.html |
4ab9b4a6b376-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 ... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/sentence_transformers.html |
5fbbc3cb637c-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 ... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/aleph_alpha.html |
6ce40c1043f9-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/fake.html |
d68751b652a5-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/cohere.html |
9b24d7989a8d-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/modelscope_hub.html |
1e6f14669720-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/deepinfra.html |
2a025d940b00-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/sagemaker-endpoint.html |
2a025d940b00-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 11, 2023. | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/sagemaker-endpoint.html |
0425700d926d-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/tensorflowhub.html |
adeb79cf4de3-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/jina.html |
4e24e16029c4-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/amazon_bedrock.html |
3d376ac66592-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/minimax.html |
1b2e4ff70728-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/openai.html |
26cfa4df4728-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/mosaicml.html |
db2ed77f58a1-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... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/huggingface_instruct.html |
5cc381798809-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 ... | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/google_vertex_ai_palm.html |
5cc381798809-1 | previous
Fake Embeddings
next
Hugging Face Hub
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/text_embedding/examples/google_vertex_ai_palm.html |
d9cfa10f7703-0 | .rst
.pdf
Generic Functionality
Generic Functionality#
The examples here all address certain “how-to” guides for working with LLMs.
How to use the async API for LLMs
How to write a custom LLM wrapper
How (and why) to use the fake LLM
How (and why) to use the human input LLM
How to cache LLM calls
How to serialize LLM c... | https://python.langchain.com/en/latest/modules/models/llms/how_to_guides.html |
2206b2cb1335-0 | .ipynb
.pdf
Getting Started
Getting Started#
This notebook goes over how to use the LLM class in LangChain.
The LLM class is a class designed for interfacing with LLMs. There are lots of LLM providers (OpenAI, Cohere, Hugging Face, etc) - this class is designed to provide a standard interface for all of them. In this p... | https://python.langchain.com/en/latest/modules/models/llms/getting_started.html |
2206b2cb1335-1 | llm_result.generations[-1]
[Generation(text="\n\nWhat if love neverspeech\n\nWhat if love never ended\n\nWhat if love was only a feeling\n\nI'll never know this love\n\nIt's not a feeling\n\nBut it's what we have for each other\n\nWe just know that love is something strong\n\nAnd we can't help but be happy\n\nWe just f... | https://python.langchain.com/en/latest/modules/models/llms/getting_started.html |
2206b2cb1335-2 | By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/getting_started.html |
f4a1de0cb212-0 | .rst
.pdf
Integrations
Integrations#
The examples here are all “how-to” guides for how to integrate with various LLM providers.
AI21
Aleph Alpha
Anyscale
Aviary
Azure OpenAI
Banana
Baseten
Setup
Single model call
Chained model calls
Beam
Bedrock
CerebriumAI
Cohere
C Transformers
Databricks
DeepInfra
ForefrontAI
Google ... | https://python.langchain.com/en/latest/modules/models/llms/integrations.html |
2f7fff41cdf4-0 | .ipynb
.pdf
PipelineAI
Contents
Install pipeline-ai
Imports
Set the Environment API Key
Create the PipelineAI instance
Create a Prompt Template
Initiate the LLMChain
Run the LLMChain
PipelineAI#
PipelineAI allows you to run your ML models at scale in the cloud. It also provides API access to several LLM models.
This ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/pipelineai_example.html |
2f7fff41cdf4-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
Petals
next
Prediction Guard
Contents
Install pipeline-ai
Imports
Set the Environment API Key
Create the PipelineAI instance
Create a Prompt T... | https://python.langchain.com/en/latest/modules/models/llms/integrations/pipelineai_example.html |
b3bf4caaee20-0 | .ipynb
.pdf
Llama-cpp
Contents
Installation
CPU only installation
Installation with OpenBLAS / cuBLAS / CLBlast
Usage
CPU
GPU
Llama-cpp#
llama-cpp is a Python binding for llama.cpp.
It supports several LLMs.
This notebook goes over how to run llama-cpp within LangChain.
Installation#
There is a banch of options how t... | https://python.langchain.com/en/latest/modules/models/llms/integrations/llamacpp.html |
b3bf4caaee20-1 | template = """Question: {question}
Answer: Let's work this out in a step by step way to be sure we have the right answer."""
prompt = PromptTemplate(template=template, input_variables=["question"])
# Callbacks support token-wise streaming
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
# Verbose ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/llamacpp.html |
b3bf4caaee20-2 | llama_print_timings: eval time = 23971.57 ms / 121 runs ( 198.11 ms per token)
llama_print_timings: total time = 28945.95 ms
'\n\n1. First, find out when Justin Bieber was born.\n2. We know that Justin Bieber was born on March 1, 1994.\n3. Next, we need to look up when the Super Bowl was played in tha... | https://python.langchain.com/en/latest/modules/models/llms/integrations/llamacpp.html |
b3bf4caaee20-3 | question = "What NFL team won the Super Bowl in the year Justin Bieber was born?"
llm_chain.run(question)
We are looking for an NFL team that won the Super Bowl when Justin Bieber (born March 1, 1994) was born.
First, let's look up which year is closest to when Justin Bieber was born:
* The year before he was born: 1... | https://python.langchain.com/en/latest/modules/models/llms/integrations/llamacpp.html |
b3bf4caaee20-4 | llama_print_timings: total time = 15664.80 ms
" We are looking for an NFL team that won the Super Bowl when Justin Bieber (born March 1, 1994) was born. \n\nFirst, let's look up which year is closest to when Justin Bieber was born:\n\n* The year before he was born: 1993\n* The year of his birth: 1994\n* The year ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/llamacpp.html |
241e5b07049f-0 | .ipynb
.pdf
Writer
Writer#
Writer is a platform to generate different language content.
This example goes over how to use LangChain to interact with Writer models.
You have to get the WRITER_API_KEY here.
from getpass import getpass
WRITER_API_KEY = getpass()
import os
os.environ["WRITER_API_KEY"] = WRITER_API_KEY
from... | https://python.langchain.com/en/latest/modules/models/llms/integrations/writer.html |
801c96a3a377-0 | .ipynb
.pdf
Manifest
Contents
Compare HF Models
Manifest#
This notebook goes over how to use Manifest and LangChain.
For more detailed information on manifest, and how to use it with local hugginface models like in this example, see https://github.com/HazyResearch/manifest
Another example of using Manifest with Langc... | https://python.langchain.com/en/latest/modules/models/llms/integrations/manifest.html |
801c96a3a377-1 | state_of_the_union = f.read()
mp_chain.run(state_of_the_union)
'President Obama delivered his annual State of the Union address on Tuesday night, laying out his priorities for the coming year. Obama said the government will provide free flu vaccines to all Americans, ending the government shutdown and allowing business... | https://python.langchain.com/en/latest/modules/models/llms/integrations/manifest.html |
801c96a3a377-2 | )
manifest3 = ManifestWrapper(
client=Manifest(
client_name="huggingface",
client_connection="http://127.0.0.1:5002"
),
llm_kwargs={"temperature": 0.01}
)
llms = [manifest1, manifest2, manifest3]
model_lab = ModelLaboratory(llms)
model_lab.compare("What color is a flamingo?")
Input:
What col... | https://python.langchain.com/en/latest/modules/models/llms/integrations/manifest.html |
f3c2d1ca2c9b-0 | .ipynb
.pdf
Bedrock
Contents
Using in a conversation chain
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.ll... | https://python.langchain.com/en/latest/modules/models/llms/integrations/bedrock.html |
dab19e2f0567-0 | .ipynb
.pdf
GPT4All
Contents
Specify Model
GPT4All#
GitHub:nomic-ai/gpt4all an ecosystem of open-source chatbots trained on a massive collections of clean assistant data including code, stories and dialogue.
This example goes over how to use LangChain to interact with GPT4All models.
%pip install gpt4all > /dev/null
... | https://python.langchain.com/en/latest/modules/models/llms/integrations/gpt4all.html |
dab19e2f0567-1 | # # send a GET request to the URL to download the file. Stream since it's large
# response = requests.get(url, stream=True)
# # open the file in binary mode and write the contents of the response to it in chunks
# # This is a large file, so be prepared to wait.
# with open(local_path, 'wb') as f:
# for chunk in tqd... | https://python.langchain.com/en/latest/modules/models/llms/integrations/gpt4all.html |
f6f49c02bf2f-0 | .ipynb
.pdf
DeepInfra
Contents
Imports
Set the Environment API Key
Create the DeepInfra instance
Create a Prompt Template
Initiate the LLMChain
Run the LLMChain
DeepInfra#
DeepInfra provides several LLMs.
This notebook goes over how to use Langchain with DeepInfra.
Imports#
import os
from langchain.llms import DeepIn... | https://python.langchain.com/en/latest/modules/models/llms/integrations/deepinfra_example.html |
f6f49c02bf2f-1 | llm_chain = LLMChain(prompt=prompt, llm=llm)
Run the LLMChain#
Provide a question and run the LLMChain.
question = "Can penguins reach the North pole?"
llm_chain.run(question)
"Penguins live in the Southern hemisphere.\nThe North pole is located in the Northern hemisphere.\nSo, first you need to turn the penguin South.... | https://python.langchain.com/en/latest/modules/models/llms/integrations/deepinfra_example.html |
786960932003-0 | .ipynb
.pdf
Hugging Face Hub
Contents
Examples
StableLM, by Stability AI
Dolly, by Databricks
Camel, by Writer
Hugging Face Hub#
The Hugging Face Hub is a platform with over 120k models, 20k datasets, and 50k demo apps (Spaces), all open source and publicly available, in an online platform where people can easily col... | https://python.langchain.com/en/latest/modules/models/llms/integrations/huggingface_hub.html |
786960932003-1 | StableLM, by Stability AI#
See Stability AI’s organization page for a list of available models.
repo_id = "stabilityai/stablelm-tuned-alpha-3b"
# Others include stabilityai/stablelm-base-alpha-3b
# as well as 7B parameter versions
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature":0, "max_length":64})
# ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/huggingface_hub.html |
786960932003-2 | Hugging Face Pipeline
Contents
Examples
StableLM, by Stability AI
Dolly, by Databricks
Camel, by Writer
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/integrations/huggingface_hub.html |
a22de56e80a3-0 | .ipynb
.pdf
PromptLayer OpenAI
Contents
Install PromptLayer
Imports
Set the Environment API Key
Use the PromptLayerOpenAI LLM like normal
Using PromptLayer Track
PromptLayer OpenAI#
PromptLayer is the first platform that allows you to track, manage, and share your GPT prompt engineering. PromptLayer acts a middleware... | https://python.langchain.com/en/latest/modules/models/llms/integrations/promptlayer_openai.html |
a22de56e80a3-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.
llm = PromptLayerOpenAI(return_pl_id=True)
llm_results... | https://python.langchain.com/en/latest/modules/models/llms/integrations/promptlayer_openai.html |
8f6ec67c12a4-0 | .ipynb
.pdf
Aleph Alpha
Aleph Alpha#
The Luminous series is a family of large language models.
This example goes over how to use LangChain to interact with Aleph Alpha models
# Install the package
!pip install aleph-alpha-client
# create a new token: https://docs.aleph-alpha.com/docs/account/#create-a-new-token
from ge... | https://python.langchain.com/en/latest/modules/models/llms/integrations/aleph_alpha.html |
ae4e672eea8e-0 | .ipynb
.pdf
StochasticAI
StochasticAI#
Stochastic Acceleration Platform aims to simplify the life cycle of a Deep Learning model. From uploading and versioning the model, through training, compression and acceleration to putting it into production.
This example goes over how to use LangChain to interact with Stochastic... | https://python.langchain.com/en/latest/modules/models/llms/integrations/stochasticai.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.