id stringlengths 14 16 | text stringlengths 36 2.73k | source stringlengths 59 127 |
|---|---|---|
fe592c586d48-1 | print(f"Total Tokens: {cb.total_tokens}")
print(f"Prompt Tokens: {cb.prompt_tokens}")
print(f"Completion Tokens: {cb.completion_tokens}")
print(f"Total Cost (USD): ${cb.total_cost}")
> Entering new AgentExecutor chain...
I need to find out who Olivia Wilde's boyfriend is and then calculate his age raised t... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/token_usage_tracking.html |
fdc5554cb4ec-0 | .ipynb
.pdf
How to cache LLM calls
Contents
In Memory Cache
SQLite Cache
Redis Cache
Standard Cache
Semantic Cache
GPTCache
Momento Cache
SQLAlchemy Cache
Custom SQLAlchemy Schemas
Optional Caching
Optional Caching in Chains
How to cache LLM calls#
This notebook covers how to cache results of individual LLM calls.
im... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
fdc5554cb4ec-1 | llm("Tell me a joke")
CPU times: user 17 ms, sys: 9.76 ms, total: 26.7 ms
Wall time: 825 ms
'\n\nWhy did the chicken cross the road?\n\nTo get to the other side.'
%%time
# The second time it is, so it goes faster
llm("Tell me a joke")
CPU times: user 2.46 ms, sys: 1.23 ms, total: 3.7 ms
Wall time: 2.67 ms
'\n\nWhy did ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
fdc5554cb4ec-2 | Semantic Cache#
Use Redis to cache prompts and responses and evaluate hits based on semantic similarity.
from langchain.embeddings import OpenAIEmbeddings
from langchain.cache import RedisSemanticCache
langchain.llm_cache = RedisSemanticCache(
redis_url="redis://localhost:6379",
embedding=OpenAIEmbeddings()
)
%... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
fdc5554cb4ec-3 | cache_obj.init(
pre_embedding_func=get_prompt,
data_manager=manager_factory(manager="map", data_dir=f"map_cache_{hashed_llm}"),
)
langchain.llm_cache = GPTCache(init_gptcache)
%%time
# The first time, it is not yet in cache, so it should take longer
llm("Tell me a joke")
CPU times: user 21.5 ms, sys... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
fdc5554cb4ec-4 | Wall time: 8.44 s
'\n\nWhy did the chicken cross the road?\n\nTo get to the other side.'
%%time
# This is an exact match, so it finds it in the cache
llm("Tell me a joke")
CPU times: user 866 ms, sys: 20 ms, total: 886 ms
Wall time: 226 ms
'\n\nWhy did the chicken cross the road?\n\nTo get to the other side.'
%%time
# ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
fdc5554cb4ec-5 | Wall time: 1.73 s
'\n\nWhy did the chicken cross the road?\n\nTo get to the other side!'
%%time
# The second time it is, so it goes faster
# When run in the same region as the cache, latencies are single digit ms
llm("Tell me a joke")
CPU times: user 3.16 ms, sys: 2.98 ms, total: 6.14 ms
Wall time: 57.9 ms
'\n\nWhy did... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
fdc5554cb4ec-6 | idx = Column(Integer)
response = Column(String)
prompt_tsv = Column(TSVectorType(), Computed("to_tsvector('english', llm || ' ' || prompt)", persisted=True))
__table_args__ = (
Index("idx_fulltext_prompt_tsv", prompt_tsv, postgresql_using="gin"),
)
engine = create_engine("postgresql://postgres:p... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
fdc5554cb4ec-7 | llm = OpenAI(model_name="text-davinci-002")
no_cache_llm = OpenAI(model_name="text-davinci-002", cache=False)
from langchain.text_splitter import CharacterTextSplitter
from langchain.chains.mapreduce import MapReduceChain
text_splitter = CharacterTextSplitter()
with open('../../../state_of_the_union.txt') as f:
sta... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
fdc5554cb4ec-8 | %%time
chain.run(docs)
CPU times: user 11.5 ms, sys: 4.33 ms, total: 15.8 ms
Wall time: 1.04 s
'\n\nPresident Biden is discussing the American Rescue Plan and the Bipartisan Infrastructure Law, which will create jobs and help Americans. He also talks about his vision for America, which includes investing in education a... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/llm_caching.html |
9f09f64ce6f1-0 | .ipynb
.pdf
How to stream LLM and Chat Model responses
How to stream LLM and Chat Model responses#
LangChain provides streaming support for LLMs. Currently, we support streaming for the OpenAI, ChatOpenAI, and ChatAnthropic implementations, but streaming support for other LLM implementations is on the roadmap. To utili... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/streaming_llm.html |
9f09f64ce6f1-1 | On a hot summer night.
Chorus
Sparkling water, sparkling water,
It's the best way to stay hydrated,
It's so crisp and so clean,
It's the perfect way to stay refreshed.
We still have access to the end LLMResult if using generate. However, token_usage is not currently supported for streaming.
llm.generate(["Tell me a jok... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/streaming_llm.html |
9f09f64ce6f1-2 | You quench my thirst, you make me feel alive
Sparkling water, you're my favorite vibe
Bridge:
You're my go-to drink, day or night
You make me feel so light
I'll never give you up, you're my true love
Sparkling water, you're sent from above
Chorus:
Sparkling water, oh how you shine
A taste so clean, it's simply divine
Y... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/streaming_llm.html |
f5039252785b-0 | .ipynb
.pdf
How to use the async API for LLMs
How to use the async API for LLMs#
LangChain provides async support for LLMs by leveraging the asyncio library.
Async support is particularly useful for calling multiple LLMs concurrently, as these calls are network-bound. Currently, OpenAI, PromptLayerOpenAI, ChatOpenAI an... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/async_llm.html |
f5039252785b-1 | I'm doing well, thank you. How about you?
I'm doing well, thank you. How about you?
I'm doing well, how about you?
I'm doing well, thank you. How about you?
I'm doing well, thank you. How about you?
I'm doing well, thank you. How about yourself?
I'm doing well, thank you! How about you?
I'm doing well, thank you. How a... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/async_llm.html |
ad96b1d3de75-0 | .ipynb
.pdf
How (and why) to use the human input LLM
How (and why) to use the human input LLM#
Similar to the fake LLM, LangChain provides a pseudo LLM class that can be used for testing, debugging, or educational purposes. This allows you to mock out calls to the LLM and simulate how a human would respond if they rece... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/human_input_llm.html |
ad96b1d3de75-1 | Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
Question: What is 'Bocchi the Rock!'?
Thought:
=====END OF PROMPT===... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/human_input_llm.html |
ad96b1d3de75-2 | Page: Manga Time Kirara Max
Summary: Manga Time Kirara Max (まんがタイムきららMAX) is a Japanese four-panel seinen manga magazine published by Houbunsha. It is the third magazine of the "Kirara" series, after "Manga Time Kirara" and "Manga Time Kirara Carat". The first issue was released on September 29, 2004. Currently the mag... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/human_input_llm.html |
ad96b1d3de75-3 | Observation: Page: Bocchi the Rock!
Summary: Bocchi the Rock! (ぼっち・ざ・ろっく!, Bocchi Za Rokku!) is a Japanese four-panel manga series written and illustrated by Aki Hamaji. It has been serialized in Houbunsha's seinen manga magazine Manga Time Kirara Max since December 2017. Its chapters have been collected in five tankōb... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/human_input_llm.html |
ad96b1d3de75-4 | =====END OF PROMPT======
These are not relevant articles.
Action: Wikipedia
Action Input: Bocchi the Rock!, Japanese four-panel manga series written and illustrated by Aki Hamaji.
Observation: Page: Bocchi the Rock!
Summary: Bocchi the Rock! (ぼっち・ざ・ろっく!, Bocchi Za Rokku!) is a Japanese four-panel manga series written a... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/human_input_llm.html |
ad96b1d3de75-5 | Action Input: Bocchi the Rock!, Japanese four-panel manga and anime series.
Observation: Page: Bocchi the Rock!
Summary: Bocchi the Rock! (ぼっち・ざ・ろっく!, Bocchi Za Rokku!) is a Japanese four-panel manga series written and illustrated by Aki Hamaji. It has been serialized in Houbunsha's seinen manga magazine Manga Time Kir... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/human_input_llm.html |
ad96b1d3de75-6 | Thought:These are not relevant articles.
Action: Wikipedia
Action Input: Bocchi the Rock!, Japanese four-panel manga series written and illustrated by Aki Hamaji.
Observation: Page: Bocchi the Rock!
Summary: Bocchi the Rock! (ぼっち・ざ・ろっく!, Bocchi Za Rokku!) is a Japanese four-panel manga series written and illustrated by... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/examples/human_input_llm.html |
38869c51ad3f-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/writer.html |
d5f5bdd85d04-0 | .ipynb
.pdf
ReLLM
Contents
Hugging Face Baseline
RELLM LLM Wrapper
ReLLM#
ReLLM is a library that wraps local Hugging Face pipeline models for structured decoding.
It works by generating tokens one at a time. At each step, it masks tokens that don’t conform to the provided partial regular expression.
Warning - this m... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/rellm_experimental.html |
d5f5bdd85d04-1 | Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
generations=[[Generation(text=' "What\'s the capital of Maryland?"\n', generation_info=None)]] llm_output=None
That’s not so impressive, is it? It didn’t answer the question and it didn’t follow the JSON format at all! Let’s try with the structured... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/rellm_experimental.html |
642f59c57f05-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 completion.
# sign up for an account: https://forms.mosaicml.com/demo?utm_source=la... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/mosaicml.html |
619b5dd43a73-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/manifest.html |
619b5dd43a73-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/manifest.html |
619b5dd43a73-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/manifest.html |
cd8b049fa089-0 | .ipynb
.pdf
Replicate
Contents
Setup
Calling a model
Chaining Calls
Replicate#
Replicate runs machine learning models in the cloud. We have a library of open-source models that you can run with a few lines of code. If you’re building your own machine learning models, Replicate makes it easy to deploy them at scale.
T... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/replicate.html |
cd8b049fa089-1 | Note that only the first output of a model will be returned.
llm = Replicate(model="replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5")
prompt = """
Answer the following yes/no question by reasoning step by step.
Can a dog drive a car?
"""
llm(prompt)
'The legal driving age of dog... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/replicate.html |
cd8b049fa089-2 | from langchain.chains import SimpleSequentialChain
First, let’s define the LLM for this model as a flan-5, and text2image as a stable diffusion model.
dolly_llm = Replicate(model="replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5")
text2image = Replicate(model="stability-ai/stable-... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/replicate.html |
cd8b049fa089-3 | catchphrase = overall_chain.run("colorful socks")
print(catchphrase)
> Entering new SimpleSequentialChain chain...
novelty socks
todd & co.
https://replicate.delivery/pbxt/BedAP1PPBwXFfkmeD7xDygXO4BcvApp1uvWOwUdHM4tcQfvCB/out-0.png
> Finished chain.
https://replicate.delivery/pbxt/BedAP1PPBwXFfkmeD7xDygXO4BcvApp1uvWOwU... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/replicate.html |
6f26158fbb92-0 | .ipynb
.pdf
Runhouse
Runhouse#
The Runhouse allows remote compute and data across environments and users. See the Runhouse docs.
This example goes over how to use LangChain and Runhouse to interact with models hosted on your own GPU, or on-demand GPUs on AWS, GCP, AWS, or Lambda.
Note: Code uses SelfHosted name instead... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/runhouse.html |
6f26158fbb92-1 | llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.run(question)
INFO | 2023-02-17 05:42:23,537 | Running _generate_text via gRPC
INFO | 2023-02-17 05:42:24,016 | Time to send message: 0.48 seconds
"\n\nLet's say we're talking sports ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/runhouse.html |
6f26158fbb92-2 | )
return pipe
def inference_fn(pipeline, prompt, stop = None):
return pipeline(prompt)[0]["generated_text"][len(prompt):]
llm = SelfHostedHuggingFaceLLM(model_load_fn=load_pipeline, hardware=gpu, inference_fn=inference_fn)
llm("Who is the current US president?")
INFO | 2023-02-17 05:42:59,219 | Running _generat... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/runhouse.html |
20feac3ee63a-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/stochasticai.html |
533c3eb82ce0-0 | .ipynb
.pdf
Beam
Beam#
Beam makes it easy to run code on GPUs, deploy scalable web APIs,
schedule cron jobs, and run massively parallel workloads — without managing any infrastructure.
Calls the Beam API wrapper to deploy and make subsequent calls to an instance of the gpt2 LLM in a cloud deployment. Requires installat... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/beam.html |
533c3eb82ce0-1 | python_version="python3.8",
python_packages=[
"diffusers[torch]>=0.10",
"transformers",
"torch",
"pillow",
"accelerate",
"safetensors",
"xformers",],
max_length="50",
verbose=False)
... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/beam.html |
5d18064f07d3-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/huggingface_hub.html |
5d18064f07d3-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})
# ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/huggingface_hub.html |
5d18064f07d3-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 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/huggingface_hub.html |
48570c117743-0 | .ipynb
.pdf
Google Cloud Platform Vertex AI PaLM
Google Cloud Platform 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, su... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/google_vertex_ai_palm.html |
48570c117743-1 | llm = VertexAI()
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.run(question)
'Justin Bieber was born on March 1, 1994. The Super Bowl in 1994 was won by the San Francisco 49ers.\nThe final answer: San Francisco 49ers.'
previous
F... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/google_vertex_ai_palm.html |
b5e9ff09af29-0 | .ipynb
.pdf
Baseten
Contents
Baseten
Setup
Single model call
Chained model calls
Baseten#
Baseten provides all the infrastructure you need to deploy and serve ML models performantly, scalably, and cost-efficiently.
This example demonstrates using Langchain with models deployed on Baseten.
Setup#
To run this notebook,... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/baseten.html |
b5e9ff09af29-1 | )
link_one = LLMChain(llm=wizardlm, prompt=prompt)
# Build the second link in the chain
prompt = PromptTemplate(
input_variables=["entree"],
template="What are three sides that would go with {entree}. Respond with only a list of the sides.",
)
link_two = LLMChain(llm=wizardlm, prompt=prompt)
# Build the third l... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/baseten.html |
6ba577c54f25-0 | .ipynb
.pdf
OpenAI
OpenAI#
OpenAI offers a spectrum of models with different levels of power suitable for different tasks.
This example goes over how to use LangChain to interact with OpenAI models
# get a token: https://platform.openai.com/account/api-keys
from getpass import getpass
OPENAI_API_KEY = getpass()
······... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/openai.html |
4d269c395268-0 | .ipynb
.pdf
Cohere
Cohere#
Cohere is a Canadian startup that provides natural language processing models that help companies improve human-machine interactions.
This example goes over how to use LangChain to interact with Cohere models.
# Install the package
!pip install cohere
# get a new token: https://dashboard.cohe... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/cohere.html |
4d269c395268-1 | llm_chain.run(question)
" Let's start with the year that Justin Beiber was born. You know that he was born in 1994. We have to go back one year. 1993.\n\n1993 was the year that the Dallas Cowboys won the Super Bowl. They won over the Buffalo Bills in Super Bowl 26.\n\nNow, let's do it backwards. According to our inform... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/cohere.html |
24fffdad83b6-0 | .ipynb
.pdf
SageMaker Endpoint
Contents
Set up
Example
SageMaker Endpoint#
Amazon SageMaker is a system that can build, train, and deploy machine learning (ML) models for any use case with fully managed infrastructure, tools, and workflows.
This notebooks goes over how to use an LLM hosted on a SageMaker endpoint.
!p... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/sagemaker.html |
24fffdad83b6-1 | import json
query = """How long was Elizabeth hospitalized?
"""
prompt_template = """Use the following pieces of context to answer the question at the end.
{context}
Question: {question}
Answer:"""
PROMPT = PromptTemplate(
template=prompt_template, input_variables=["context", "question"]
)
class ContentHandler(LLMC... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/sagemaker.html |
875cd3dc88a4-0 | .ipynb
.pdf
OpenLM
Contents
Setup
Using LangChain with OpenLM
OpenLM#
OpenLM is a zero-dependency OpenAI-compatible LLM provider that can call different inference endpoints directly via HTTP.
It implements the OpenAI Completion class so that it can be used as a drop-in replacement for the OpenAI API. This changeset u... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/openlm.html |
875cd3dc88a4-1 | llm = OpenLM(model=model)
llm_chain = LLMChain(prompt=prompt, llm=llm)
result = llm_chain.run(question)
print("""Model: {}
Result: {}""".format(model, result))
Model: text-davinci-003
Result: France is a country in Europe. The capital of France is Paris.
Model: huggingface.co/gpt2
Result: Question: What is... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/openlm.html |
eaabc89ae1e8-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/bedrock.html |
001a13c3637c-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/promptlayer_openai.html |
001a13c3637c-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/promptlayer_openai.html |
6764d784fd76-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/deepinfra_example.html |
6764d784fd76-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.... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/deepinfra_example.html |
d14ecb3fd2ff-0 | .ipynb
.pdf
ForefrontAI
Contents
Imports
Set the Environment API Key
Create the ForefrontAI instance
Create a Prompt Template
Initiate the LLMChain
Run the LLMChain
ForefrontAI#
The Forefront platform gives you the ability to fine-tune and use open source large language models.
This notebook goes over how to use Lang... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/forefrontai_example.html |
d14ecb3fd2ff-1 | DeepInfra
next
Google Cloud Platform Vertex AI PaLM
Contents
Imports
Set the Environment API Key
Create the ForefrontAI instance
Create a Prompt Template
Initiate the LLMChain
Run the LLMChain
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/forefrontai_example.html |
62a3f5d78eda-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/llamacpp.html |
62a3f5d78eda-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 ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/llamacpp.html |
62a3f5d78eda-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/llamacpp.html |
62a3f5d78eda-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/llamacpp.html |
62a3f5d78eda-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 ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/llamacpp.html |
b6d573afaa2e-0 | .ipynb
.pdf
Modal
Modal#
The Modal Python Library provides convenient, on-demand access to serverless cloud compute from Python scripts on your local computer.
The Modal itself does not provide any LLMs but only the infrastructure.
This example goes over how to use LangChain to interact with Modal.
Here is another exam... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/modal.html |
b6d573afaa2e-1 | previous
Manifest
next
MosaicML
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/modal.html |
55db36188b59-0 | .ipynb
.pdf
Aviary
Aviary#
Aviary is an open source tooklit for evaluating and deploying production open source LLMs.
This example goes over how to use LangChain to interact with Aviary. You can try Aviary out https://aviary.anyscale.com.
You can find out more about Aviary at https://github.com/ray-project/aviary.
One ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/aviary.html |
025eeee2f6ee-0 | .ipynb
.pdf
Prediction Guard
Contents
Prediction Guard
Control the output structure/ type of LLMs
Chaining
Prediction Guard#
Prediction Guard gives a quick and easy access to state-of-the-art open and closed access LLMs, without needing to spend days and weeks figuring out all of the implementation details, managing... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/predictionguard.html |
025eeee2f6ee-1 | Result: """
prompt = PromptTemplate(template=template, input_variables=["query"])
# Without "guarding" or controlling the output of the LLM.
pgllm(prompt.format(query="What kind of post is this?"))
# With "guarding" or controlling the output of the LLM. See the
# Prediction Guard docs (https://docs.predictionguard.com... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/predictionguard.html |
025eeee2f6ee-2 | Prediction Guard
Control the output structure/ type of LLMs
Chaining
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/predictionguard.html |
5237824848ef-0 | .ipynb
.pdf
Jsonformer
Contents
HuggingFace Baseline
JSONFormer LLM Wrapper
Jsonformer#
Jsonformer is a library that wraps local HuggingFace pipeline models for structured decoding of a subset of the JSON Schema.
It works by filling in the structure tokens and then sampling the content tokens from the model.
Warning ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/jsonformer_experimental.html |
5237824848ef-1 | EXAMPLES
----
Human: "So what's all this about a GIL?"
AI Assistant:{{
"action": "ask_star_coder",
"action_input": {{"query": "What is a GIL?", "temperature": 0.0, "max_new_tokens": 100}}"
}}
Observation: "The GIL is python's Global Interpreter Lock"
Human: "Could you please write a calculator program in LISP?"
AI ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/jsonformer_experimental.html |
5237824848ef-2 | generated = original_model.predict(prompt, stop=["Observation:", "Human:"])
print(generated)
Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
'What's the difference between an iterator and an iterable?'
That’s not so impressive, is it? It didn’t follow the JSON format at all! Let’s try with the ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/jsonformer_experimental.html |
bb9d929ab653-0 | .ipynb
.pdf
NLP Cloud
NLP Cloud#
The NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, paraphrasing, grammar and spelling correction, keywords and keyphrases extraction, chatbot, product description and ad generation, intent classification, text g... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/nlpcloud.html |
681ff62469df-0 | .ipynb
.pdf
Anyscale
Anyscale#
Anyscale is a fully-managed Ray platform, on which you can build, deploy, and manage scalable AI and Python applications
This example goes over how to use LangChain to interact with Anyscale service
import os
os.environ["ANYSCALE_SERVICE_URL"] = ANYSCALE_SERVICE_URL
os.environ["ANYSCALE_S... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/anyscale.html |
681ff62469df-1 | resp = llm(prompt)
return resp
futures = [send_query.remote(llm, prompt) for prompt in prompt_list]
results = ray.get(futures)
previous
Aleph Alpha
next
Aviary
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/anyscale.html |
3d50628fb5b2-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
... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/gpt4all.html |
3d50628fb5b2-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/gpt4all.html |
c1cca2e59569-0 | .ipynb
.pdf
Azure OpenAI
Contents
API configuration
Deployments
Azure OpenAI#
This notebook goes over how to use Langchain with Azure OpenAI.
The Azure OpenAI API is compatible with OpenAI’s API. The openai Python package makes it easy to use both OpenAI and Azure OpenAI. You can call Azure OpenAI the same way you ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/azure_openai_example.html |
c1cca2e59569-1 | import openai
response = openai.Completion.create(
engine="text-davinci-002-prod",
prompt="This is a test",
max_tokens=5
)
!pip install openai
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_VERSION"] = "2023-03-15-preview"
os.environ["OPENAI_API_BASE"] = "..."
os.environ["OPENAI_AP... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/azure_openai_example.html |
407386520416-0 | .ipynb
.pdf
Banana
Banana#
Banana is focused on building the machine learning infrastructure.
This example goes over how to use LangChain to interact with Banana models
# Install the package https://docs.banana.dev/banana-docs/core-concepts/sdks/python
!pip install banana-dev
# get new tokens: https://app.banana.dev/
... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/banana.html |
c5f1a1358cb0-0 | .ipynb
.pdf
C Transformers
C Transformers#
The C Transformers library provides Python bindings for GGML models.
This example goes over how to use LangChain to interact with C Transformers models.
Install
%pip install ctransformers
Load Model
from langchain.llms import CTransformers
llm = CTransformers(model='marella/gp... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/ctransformers.html |
62d63ede4f85-0 | .ipynb
.pdf
AI21
AI21#
AI21 Studio provides API access to Jurassic-2 large language models.
This example goes over how to use LangChain to interact with AI21 models.
# install the package:
!pip install ai21
# get AI21_API_KEY. Use https://studio.ai21.com/account/account
from getpass import getpass
AI21_API_KEY = getpa... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/ai21.html |
cf538441e507-0 | .ipynb
.pdf
Hugging Face Pipeline
Contents
Load the model
Integrate the model in an LLMChain
Hugging Face Pipeline#
Hugging Face models can be run locally through the HuggingFacePipeline class.
The Hugging Face Model Hub hosts over 120k models, 20k datasets, and 50k demo apps (Spaces), all open source and publicly av... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/huggingface_pipelines.html |
cf538441e507-1 | question = "What is electroencephalography?"
print(llm_chain.run(question))
/Users/wfh/code/lc/lckg/.venv/lib/python3.11/site-packages/transformers/generation/utils.py:1288: UserWarning: Using `max_length`'s default (64) to control the generation length. This behaviour is deprecated and will be removed from the config ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/huggingface_pipelines.html |
4704e0083906-0 | .ipynb
.pdf
GooseAI
Contents
Install openai
Imports
Set the Environment API Key
Create the GooseAI instance
Create a Prompt Template
Initiate the LLMChain
Run the LLMChain
GooseAI#
GooseAI is a fully managed NLP-as-a-Service, delivered via API. GooseAI provides access to these models.
This notebook goes over how to u... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/gooseai_example.html |
4704e0083906-1 | Google Cloud Platform Vertex AI PaLM
next
GPT4All
Contents
Install openai
Imports
Set the Environment API Key
Create the GooseAI instance
Create a Prompt Template
Initiate the LLMChain
Run the LLMChain
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 16, 2023. | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/gooseai_example.html |
a4a5c3eeff49-0 | .ipynb
.pdf
Databricks
Contents
Wrapping a serving endpoint
Wrapping a cluster driver proxy app
Databricks#
The Databricks Lakehouse Platform unifies data, analytics, and AI on one platform.
This example notebook shows how to wrap Databricks endpoints as LLMs in LangChain.
It supports two endpoint types:
Serving endp... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/databricks.html |
a4a5c3eeff49-1 | # See https://docs.databricks.com/dev-tools/auth.html#databricks-personal-access-tokens
# We strongly recommend not exposing the API token explicitly inside a notebook.
# You can use Databricks secret manager to store your API token securely.
# See https://docs.databricks.com/dev-tools/databricks-utils.html#secrets-uti... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/databricks.html |
a4a5c3eeff49-2 | It uses a port number between [3000, 8000] and listens to the driver IP address or simply 0.0.0.0 instead of localhost only.
You have “Can Attach To” permission to the cluster.
The expected server schema (using JSON schema) is:
inputs:
{"type": "object",
"properties": {
"prompt": {"type": "string"},
"stop": {... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/databricks.html |
a4a5c3eeff49-3 | self.matched = self.stop[i]
return True
return False
def llm(prompt, stop=None, **kwargs):
check_stop = CheckStop(stop)
result = dolly(prompt, stopping_criteria=[check_stop], **kwargs)
return result[0]["generated_text"].rstrip(check_stop.matched)
app = Flask("dolly")
@app.route('/', method... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/databricks.html |
a4a5c3eeff49-4 | # Use `transform_input_fn` and `transform_output_fn` if the app
# expects a different input schema and does not return a JSON string,
# respectively, or you want to apply a prompt template on top.
def transform_input(**request):
full_prompt = f"""{request["prompt"]}
Be Concise.
"""
request["prompt"] = f... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/databricks.html |
e9ff4a92b969-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/aleph_alpha.html |
dc90c58a6ef3-0 | .ipynb
.pdf
CerebriumAI
Contents
Install cerebrium
Imports
Set the Environment API Key
Create the CerebriumAI instance
Create a Prompt Template
Initiate the LLMChain
Run the LLMChain
CerebriumAI#
Cerebrium is an AWS Sagemaker alternative. It also provides API access to several LLM models.
This notebook goes over how ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/cerebriumai_example.html |
dc90c58a6ef3-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
Bedrock
next
Cohere
Contents
Install cerebrium
Imports
Set the Environment API Key
Create the CerebriumAI instance
Create a Prompt Template
In... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/cerebriumai_example.html |
2079cc3443a8-0 | .ipynb
.pdf
Huggingface TextGen Inference
Huggingface TextGen Inference#
Text Generation Inference is a Rust, Python and gRPC server for text generation inference. Used in production at HuggingFace to power LLMs api-inference widgets.
This notebooks goes over how to use a self hosted LLM using Text Generation Inference... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/huggingface_textgen_inference.html |
0e540bb7c6a8-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 ... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/pipelineai_example.html |
0e540bb7c6a8-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... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/pipelineai_example.html |
67d5164aeffc-0 | .ipynb
.pdf
Petals
Contents
Install petals
Imports
Set the Environment API Key
Create the Petals instance
Create a Prompt Template
Initiate the LLMChain
Run the LLMChain
Petals#
Petals runs 100B+ language models at home, BitTorrent-style.
This notebook goes over how to use Langchain with Petals.
Install petals#
The p... | rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/petals_example.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.