id stringlengths 14 16 | text stringlengths 36 2.73k | source stringlengths 49 117 |
|---|---|---|
754926b9735a-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 ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/cerebriumai_example.html |
754926b9735a-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/cerebriumai_example.html |
d22c580ae46e-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 ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/jsonformer_experimental.html |
d22c580ae46e-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 ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/jsonformer_experimental.html |
d22c580ae46e-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 ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/jsonformer_experimental.html |
6f7f8c33e56e-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/databricks.html |
6f7f8c33e56e-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/databricks.html |
6f7f8c33e56e-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": {... | https://python.langchain.com/en/latest/modules/models/llms/integrations/databricks.html |
6f7f8c33e56e-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/databricks.html |
6f7f8c33e56e-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/databricks.html |
30570833f7f7-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/cohere.html |
30570833f7f7-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/cohere.html |
9cf7a792092c-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/predictionguard.html |
9cf7a792092c-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/predictionguard.html |
9cf7a792092c-2 | Prediction Guard
Control the output structure/ type of LLMs
Chaining
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/integrations/predictionguard.html |
1a842b56f20e-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/replicate.html |
1a842b56f20e-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/replicate.html |
1a842b56f20e-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-... | https://python.langchain.com/en/latest/modules/models/llms/integrations/replicate.html |
1a842b56f20e-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/replicate.html |
43cd8a5523ab-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/huggingface_textgen_inference.html |
5b1124fbb88d-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/
... | https://python.langchain.com/en/latest/modules/models/llms/integrations/banana.html |
305082dfff31-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/runhouse.html |
305082dfff31-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 ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/runhouse.html |
305082dfff31-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/runhouse.html |
a841789a644b-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/sagemaker.html |
a841789a644b-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/sagemaker.html |
02d6218cb7ea-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,... | https://python.langchain.com/en/latest/modules/models/llms/integrations/baseten.html |
02d6218cb7ea-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/baseten.html |
c30c36598e45-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/ai21.html |
7f190c9a02b7-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/openlm.html |
7f190c9a02b7-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/openlm.html |
1059416199de-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/modal.html |
1059416199de-1 | previous
Manifest
next
MosaicML
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/integrations/modal.html |
e881f4680a6a-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/forefrontai_example.html |
e881f4680a6a-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 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/integrations/forefrontai_example.html |
26717f3b7be8-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/beam.html |
26717f3b7be8-1 | python_version="python3.8",
python_packages=[
"diffusers[torch]>=0.10",
"transformers",
"torch",
"pillow",
"accelerate",
"safetensors",
"xformers",],
max_length="50",
verbose=False)
... | https://python.langchain.com/en/latest/modules/models/llms/integrations/beam.html |
8a99d77190b8-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()
······... | https://python.langchain.com/en/latest/modules/models/llms/integrations/openai.html |
a7b2b1bc18b8-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/mosaicml.html |
42bd333433f9-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 ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/aviary.html |
09fa046c93e8-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/rellm_experimental.html |
09fa046c93e8-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/rellm_experimental.html |
a6b86ba3a5a1-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/petals_example.html |
a6b86ba3a5a1-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/petals_example.html |
45944ccb8fc7-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 ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/azure_openai_example.html |
45944ccb8fc7-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/azure_openai_example.html |
08055b49f7f5-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/huggingface_pipelines.html |
08055b49f7f5-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 ... | https://python.langchain.com/en/latest/modules/models/llms/integrations/huggingface_pipelines.html |
55eef615a5d5-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/anyscale.html |
55eef615a5d5-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 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/integrations/anyscale.html |
87cf25c1f990-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/nlpcloud.html |
7c763d98a236-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/gooseai_example.html |
7c763d98a236-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 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/integrations/gooseai_example.html |
545d278b0cbd-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/ctransformers.html |
89e087a55871-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/google_vertex_ai_palm.html |
89e087a55871-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... | https://python.langchain.com/en/latest/modules/models/llms/integrations/google_vertex_ai_palm.html |
31287a49da2f-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/human_input_llm.html |
31287a49da2f-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===... | https://python.langchain.com/en/latest/modules/models/llms/examples/human_input_llm.html |
31287a49da2f-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/human_input_llm.html |
31287a49da2f-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/human_input_llm.html |
31287a49da2f-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/human_input_llm.html |
31287a49da2f-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/human_input_llm.html |
31287a49da2f-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/human_input_llm.html |
eace95a95683-0 | .ipynb
.pdf
How to track token usage
How to track token usage#
This notebook goes over how to track your token usage for specific calls. It is currently only implemented for the OpenAI API.
Let’s first look at an extremely simple example of tracking token usage for a single LLM call.
from langchain.llms import OpenAI
f... | https://python.langchain.com/en/latest/modules/models/llms/examples/token_usage_tracking.html |
eace95a95683-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/token_usage_tracking.html |
7ffd8eda2add-0 | .ipynb
.pdf
How to serialize LLM classes
Contents
Loading
Saving
How to serialize LLM classes#
This notebook walks through how to write and read an LLM Configuration to and from disk. This is useful if you want to save the configuration for a given LLM (e.g., the provider, the temperature, etc).
from langchain.llms i... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_serialization.html |
7ffd8eda2add-1 | llm.save("llm.json")
llm.save("llm.yaml")
previous
How to cache LLM calls
next
How to stream LLM and Chat Model responses
Contents
Loading
Saving
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_serialization.html |
23c1e6412d64-0 | .ipynb
.pdf
How to write a custom LLM wrapper
How to write a custom LLM wrapper#
This notebook goes over how to create a custom LLM wrapper, in case you want to use your own LLM or a different wrapper than one that is supported in LangChain.
There is only one required thing that a custom LLM needs to implement:
A _call... | https://python.langchain.com/en/latest/modules/models/llms/examples/custom_llm.html |
23c1e6412d64-1 | 'This is a '
We can also print the LLM and see its custom print.
print(llm)
CustomLLM
Params: {'n': 10}
previous
How to use the async API for LLMs
next
How (and why) to use the fake LLM
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 11, 2023. | https://python.langchain.com/en/latest/modules/models/llms/examples/custom_llm.html |
776c52025374-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/async_llm.html |
776c52025374-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/async_llm.html |
81ebd155fa2b-0 | .ipynb
.pdf
How (and why) to use the fake LLM
How (and why) to use the fake LLM#
We expose a fake LLM class that can be used for testing. This allows you to mock out calls to the LLM and simulate what would happen if the LLM responded in a certain way.
In this notebook we go over how to use this.
We start this with usi... | https://python.langchain.com/en/latest/modules/models/llms/examples/fake_llm.html |
206042b7f347-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
206042b7f347-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 ... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
206042b7f347-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()
)
%... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
206042b7f347-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
206042b7f347-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
# ... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
206042b7f347-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
206042b7f347-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
206042b7f347-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
206042b7f347-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html |
667f23987975-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/streaming_llm.html |
667f23987975-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/streaming_llm.html |
667f23987975-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... | https://python.langchain.com/en/latest/modules/models/llms/examples/streaming_llm.html |
713d1d0e227e-0 | .rst
.pdf
How-To Guides
How-To Guides#
A chain is made up of links, which can be either primitives or other chains.
Primitives can be either prompts, models, arbitrary functions, or other chains.
The examples here are broken up into three sections:
Generic Functionality
Covers both generic chains (that are useful in a ... | https://python.langchain.com/en/latest/modules/chains/how_to_guides.html |
386337f453b6-0 | .ipynb
.pdf
Getting Started
Contents
Why do we need chains?
Quick start: Using LLMChain
Different ways of calling chains
Add memory to chains
Debug Chain
Combine chains with the SequentialChain
Create a custom chain with the Chain class
Getting Started#
In this tutorial, we will learn about creating simple chains in ... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
386337f453b6-1 | print(chain.run("colorful socks"))
Colorful Toes Co.
If there are multiple variables, you can input them all at once using a dictionary.
prompt = PromptTemplate(
input_variables=["company", "product"],
template="What is a good name for {company} that makes {product}?",
)
chain = LLMChain(llm=llm, prompt=prompt)... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
386337f453b6-2 | {'adjective': 'corny',
'text': 'Why did the tomato turn red? Because it saw the salad dressing!'}
By default, __call__ returns both the input and output key values. You can configure it to only return output key values by setting return_only_outputs to True.
llm_chain("corny", return_only_outputs=True)
{'text': 'Why d... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
386337f453b6-3 | llm=chat,
memory=ConversationBufferMemory()
)
conversation.run("Answer briefly. What are the first 3 colors of a rainbow?")
# -> The first three colors of a rainbow are red, orange, and yellow.
conversation.run("And the next 4?")
# -> The next four colors of a rainbow are green, blue, indigo, and violet.
'The next ... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
386337f453b6-4 | Human: What is ChatGPT?
AI:
> Finished chain.
'ChatGPT is an AI language model developed by OpenAI. It is based on the GPT-3 architecture and is capable of generating human-like responses to text prompts. ChatGPT has been trained on a massive amount of text data and can understand and respond to a wide range of topics.... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
386337f453b6-5 | catchphrase = overall_chain.run("colorful socks")
print(catchphrase)
> Entering new SimpleSequentialChain chain...
Rainbow Socks Co.
"Put a little rainbow in your step!"
> Finished chain.
"Put a little rainbow in your step!"
Create a custom chain with the Chain class#
LangChain provides many chains out of the box, but ... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
386337f453b6-6 | prompt_1 = PromptTemplate(
input_variables=["product"],
template="What is a good name for a company that makes {product}?",
)
chain_1 = LLMChain(llm=llm, prompt=prompt_1)
prompt_2 = PromptTemplate(
input_variables=["product"],
template="What is a good slogan for a company that makes {product}?",
)
chain... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
960b6aef14b2-0 | .ipynb
.pdf
Async API for Chain
Async API for Chain#
LangChain provides async support for Chains by leveraging the asyncio library.
Async methods are currently supported in LLMChain (through arun, apredict, acall) and LLMMathChain (through arun and acall), ChatVectorDBChain, and QA chains. Async support for other chain... | https://python.langchain.com/en/latest/modules/chains/generic/async_chain.html |
960b6aef14b2-1 | await generate_concurrently()
elapsed = time.perf_counter() - s
print('\033[1m' + f"Concurrent executed in {elapsed:0.2f} seconds." + '\033[0m')
s = time.perf_counter()
generate_serially()
elapsed = time.perf_counter() - s
print('\033[1m' + f"Serial executed in {elapsed:0.2f} seconds." + '\033[0m')
BrightSmile Toothpas... | https://python.langchain.com/en/latest/modules/chains/generic/async_chain.html |
d2486631d19e-0 | .ipynb
.pdf
Sequential Chains
Contents
SimpleSequentialChain
Sequential Chain
Memory in Sequential Chains
Sequential Chains#
The next step after calling a language model is make a series of calls to a language model. This is particularly useful when you want to take the output from one call and use it as the input to... | https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html |
d2486631d19e-1 | synopsis_chain = LLMChain(llm=llm, prompt=prompt_template)
# This is an LLMChain to write a review of a play given a synopsis.
llm = OpenAI(temperature=.7)
template = """You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.
Play Synopsis:
{synopsis}
R... | https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html |
d2486631d19e-2 | The play follows the couple as they struggle to stay together and battle the forces that threaten to tear them apart. Despite the tragedy that awaits them, they remain devoted to one another and fight to keep their love alive. In the end, the couple must decide whether to take a chance on their future together or succu... | https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html |
d2486631d19e-3 | The play's setting of the beach at sunset adds a touch of poignancy and romanticism to the story, while the mysterious figure serves to keep the audience enthralled. Overall, Tragedy at Sunset on the Beach is an engaging and thought-provoking play that is sure to leave audiences feeling inspired and hopeful.
Sequential... | https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html |
d2486631d19e-4 | Play Synopsis:
{synopsis}
Review from a New York Times play critic of the above play:"""
prompt_template = PromptTemplate(input_variables=["synopsis"], template=template)
review_chain = LLMChain(llm=llm, prompt=prompt_template, output_key="review")
# This is the overall chain where we run these two chains in sequence.
... | https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html |
d2486631d19e-5 | 'era': 'Victorian England',
'synopsis': "\n\nThe play follows the story of John, a young man from a wealthy Victorian family, who dreams of a better life for himself. He soon meets a beautiful young woman named Mary, who shares his dream. The two fall in love and decide to elope and start a new life together.\n\nOn th... | https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.