.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, you’ll need a Baseten account and an API key.
You’ll also need to install the Baseten Python package:
!pip install baseten
import baseten
baseten.login("YOUR_API_KEY")
Single model call#
First, you’ll need to deploy a model to Baseten.
You can deploy foundation models like WizardLM and Alpaca with one click from the Baseten model library or if you have your own model, deploy it with this tutorial.
In this example, we’ll work with WizardLM. Deploy WizardLM here and follow along with the deployed model’s version ID.
from langchain.llms import Baseten
# Load the model
wizardlm = Baseten(model="MODEL_VERSION_ID", verbose=True)
# Prompt the model
wizardlm("What is the difference between a Wizard and a Sorcerer?")
Chained model calls#
We can chain together multiple calls to one or multiple models, which is the whole point of Langchain!
This example uses WizardLM to plan a meal with an entree, three sides, and an alcoholic and non-alcoholic beverage pairing.
from langchain.chains import SimpleSequentialChain
from langchain import PromptTemplate, LLMChain
# Build the first link in the chain
prompt = PromptTemplate(
    input_variables=["cuisine"],
    template="Name a complex entree for a {cuisine} dinner. Respond with just the name of a single dish.",
)
rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/baseten.html