id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
49
117
f642fd45317b-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
f642fd45317b-1
previous How to use few shot examples next Integrations By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 25, 2023.
https://python.langchain.com/en/latest/modules/models/chat/examples/streaming.html
a1b10be25b18-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
a1b10be25b18-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
be5552b2d358-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
1ccc378e5f3a-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
1ccc378e5f3a-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
1ccc378e5f3a-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/getting_started.html
91d21b434d54-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 Azure OpenAI Banana Beam integration for langchain CerebriumAI Cohere DeepInfra ForefrontAI Google Cloud Platform Vertex AI PaLM GooseAI GPT4All Hugging Face Hub Hugg...
https://python.langchain.com/en/latest/modules/models/llms/integrations.html
c266079a89ea-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
874390d90dba-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
874390d90dba-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
874390d90dba-2
Hugging Face Local Pipelines Contents Examples StableLM, by Stability AI Dolly, by DataBricks Camel, by Writer By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/integrations/huggingface_hub.html
84914865a3f6-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
698e1535f04d-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
a3d4d6106ccc-0
.ipynb .pdf Beam integration for langchain Beam integration for langchain# Calls the Beam API wrapper to deploy and make subsequent calls to an instance of the gpt2 LLM in a cloud deployment. Requires installation of the Beam library and registration of Beam Client ID and Client Secret. By calling the wrapper an instan...
https://python.langchain.com/en/latest/modules/models/llms/integrations/beam.html
a3d4d6106ccc-1
"torch", "pillow", "accelerate", "safetensors", "xformers",], max_length="50", verbose=False) llm._deploy() response = llm._call("Running machine learning on a remote GPU") print(response) previous Banana next CerebriumAI By Harrison Chas...
https://python.langchain.com/en/latest/modules/models/llms/integrations/beam.html
1e553890569d-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
1e553890569d-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
1e553890569d-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
76c7c350f8cf-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
76c7c350f8cf-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 May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/integrations/forefrontai_example.html
6442c1c996ca-0
.ipynb .pdf Hugging Face Local Pipelines Contents Load the model Integrate the model in an LLMChain Hugging Face Local Pipelines# 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 a...
https://python.langchain.com/en/latest/modules/models/llms/integrations/huggingface_pipelines.html
6442c1c996ca-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
c36540793725-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
c36540793725-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
ba56e1e37813-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
ba56e1e37813-1
previous 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 May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/integrations/gooseai_example.html
eb1db6001fb4-0
.ipynb .pdf Structured Decoding with JSONFormer Contents HuggingFace Baseline JSONFormer LLM Wrapper Structured Decoding with 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 sa...
https://python.langchain.com/en/latest/modules/models/llms/integrations/jsonformer_experimental.html
eb1db6001fb4-1
{arg_schema} 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 ...
https://python.langchain.com/en/latest/modules/models/llms/integrations/jsonformer_experimental.html
eb1db6001fb4-2
original_model = HuggingFacePipeline(pipeline=hf_model) 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 d...
https://python.langchain.com/en/latest/modules/models/llms/integrations/jsonformer_experimental.html
f66d41535b38-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
f66d41535b38-1
def send_query(llm, prompt): resp = llm(prompt) return resp futures = [send_query.remote(llm, prompt) for prompt in prompt_list] results = ray.get(futures) previous Aleph Alpha next Azure OpenAI By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/integrations/anyscale.html
002abdc21232-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
f5f796e14dbb-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
f5f796e14dbb-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
04e3286ebe56-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
0d8faf45fa22-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
6ca722052658-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
a3d5fdf3449e-0
.ipynb .pdf SageMakerEndpoint Contents Set up Example SageMakerEndpoint# 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. !pip...
https://python.langchain.com/en/latest/modules/models/llms/integrations/sagemaker.html
a3d5fdf3449e-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
c2a21ee7e89f-0
.ipynb .pdf Llama-cpp 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. !pip install llama-cpp-python Make sure you are following all instructions to install all necessary model files. You don’t need an API_TOKEN! from langch...
https://python.langchain.com/en/latest/modules/models/llms/integrations/llamacpp.html
c2a21ee7e89f-1
' First we need to identify what year Justin Beiber was born in. A quick google search reveals that he was born on March 1st, 1994. Now we know when the Super Bowl was played in, so we can look up which NFL team won it. The NFL Superbowl of the year 1994 was won by the San Francisco 49ers against the San Diego Chargers...
https://python.langchain.com/en/latest/modules/models/llms/integrations/llamacpp.html
a0a5b0693dcb-0
.ipynb .pdf Structured Decoding with RELLM Contents Hugging Face Baseline RELLM LLM Wrapper Structured Decoding with 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 pro...
https://python.langchain.com/en/latest/modules/models/llms/integrations/rellm_experimental.html
a0a5b0693dcb-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
97420c3a1afe-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
97420c3a1afe-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
97420c3a1afe-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
b3137ef14314-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
b3137ef14314-1
llm_chain.run(question) previous Manifest next MosaicML By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/integrations/modal.html
4bfbc64bc4e2-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
4bfbc64bc4e2-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
75248574fdf4-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
75248574fdf4-1
llm_chain.run(question) previous Cohere next ForefrontAI Contents Imports Set the Environment API Key Create the DeepInfra instance Create a Prompt Template Initiate the LLMChain Run the LLMChain By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/integrations/deepinfra_example.html
d1c4c2c3c099-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
d88126b6333e-0
.ipynb .pdf PredictionGuard Contents Basic LLM usage Chaining PredictionGuard# How to use PredictionGuard wrapper ! pip install predictionguard langchain import predictionguard as pg from langchain.llms import PredictionGuard Basic LLM usage# pgllm = PredictionGuard(name="default-text-gen", token="<your access token>...
https://python.langchain.com/en/latest/modules/models/llms/integrations/predictionguard.html
5b9bffddb2c1-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
5b9bffddb2c1-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 PredictionGuard Contents Install pipeline-ai Imports Set the Environment API Key Create the PipelineAI instance Create a Prompt Te...
https://python.langchain.com/en/latest/modules/models/llms/integrations/pipelineai_example.html
4d322cf61b2c-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() import ...
https://python.langchain.com/en/latest/modules/models/llms/integrations/openai.html
3dd609c06312-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
3dd609c06312-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 Beam integration for langchain next Cohere Contents Install cerebrium Imports Set the Environment API Key Create the CerebriumAI instance Crea...
https://python.langchain.com/en/latest/modules/models/llms/integrations/cerebriumai_example.html
ce6c5ff4a6ff-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
ce6c5ff4a6ff-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
f0f0e2471318-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
f0f0e2471318-1
for model in ["text-davinci-003", "huggingface.co/gpt2"]: 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 ...
https://python.langchain.com/en/latest/modules/models/llms/integrations/openlm.html
a04ccb186f72-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
a04ccb186f72-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"] = "2022-12-01" os.environ["OPENAI_API_BASE"] = "..." os.environ["OPENAI_API_KEY"] ...
https://python.langchain.com/en/latest/modules/models/llms/integrations/azure_openai_example.html
52f228df3c1f-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
52f228df3c1f-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
52f228df3c1f-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
52f228df3c1f-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
8ecfc074f7de-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
8ecfc074f7de-1
prompt = PromptTemplate(template=template, input_variables=["question"]) 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...
https://python.langchain.com/en/latest/modules/models/llms/integrations/google_vertex_ai_palm.html
db8c4fcbcefd-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
db8c4fcbcefd-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
d8d7ff748b2a-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
d8d7ff748b2a-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
d8d7ff748b2a-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
d8d7ff748b2a-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
d8d7ff748b2a-4
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
d8d7ff748b2a-5
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
d8d7ff748b2a-6
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
7fde38e306f6-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
7fde38e306f6-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 May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/examples/custom_llm.html
15bfd67cf820-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
15bfd67cf820-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
15bfd67cf820-2
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 You quench my thirst, you make me feel alive S...
https://python.langchain.com/en/latest/modules/models/llms/examples/streaming_llm.html
4ef367a25851-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
4ef367a25851-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 May 25, 2023.
https://python.langchain.com/en/latest/modules/models/llms/examples/llm_serialization.html
108e1bae2738-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
3ac4b934a09b-0
.ipynb .pdf How to cache LLM calls Contents In Memory Cache SQLite Cache Redis Cache Standard Cache Semantic Cache GPTCache 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. from langchain.l...
https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html
3ac4b934a09b-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
3ac4b934a09b-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
3ac4b934a09b-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
3ac4b934a09b-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
3ac4b934a09b-5
__tablename__ = "llm_cache_fulltext" id = Column(Integer, Sequence('cache_id'), primary_key=True) prompt = Column(String, nullable=False) llm = Column(String, nullable=False) idx = Column(Integer) response = Column(String) prompt_tsv = Column(TSVectorType(), Computed("to_tsvector('english', llm ...
https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html
3ac4b934a09b-6
Optional Caching in Chains# You can also turn off caching for particular nodes in chains. Note that because of certain interfaces, its often easier to construct the chain first, and then edit the LLM afterwards. As an example, we will load a summarizer map-reduce chain. We will cache results for the map-step, but then ...
https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html
3ac4b934a09b-7
Wall time: 5.09 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 and infrastructure. In response to Russian aggression in Ukraine, the United S...
https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html
c475a2c8c7d3-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
c475a2c8c7d3-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