## Predibase

[Predibase](https://predibase.com/) allows you to train, fine-tune, and deploy any ML model—from linear regression to large language model.

This example demonstrates using Langchain with models deployed on Predibase

## Setup

To run this notebook, you’ll need a [Predibase account](https://predibase.com/free-trial/?utm_source=langchain) and an [API key](https://docs.predibase.com/sdk-guide/intro).

You’ll also need to install the Predibase Python package:

```
%pip install --upgrade --quiet  predibaseimport osos.environ["PREDIBASE_API_TOKEN"] = "{PREDIBASE_API_TOKEN}"
```

## Initial Call[​](#initial-call "Direct link to Initial Call")

```
from langchain_community.llms import Predibasemodel = Predibase(    model="mistral-7b",    predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN"),)
```

```
from langchain_community.llms import Predibase# With a fine-tuned adapter hosted at Predibase (adapter_version can be specified; omitting it is equivalent to the most recent version).model = Predibase(    model="mistral-7b",    adapter_id="e2e_nlg",    adapter_version=1,    predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN"),)
```

```
from langchain_community.llms import Predibase# With a fine-tuned adapter hosted at HuggingFace (adapter_version does not apply and will be ignored).model = Predibase(    model="mistral-7b",    adapter_id="predibase/e2e_nlg",    predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN"),)
```

```
response = model("Can you recommend me a nice dry wine?")print(response)
```

## Chain Call Setup[​](#chain-call-setup "Direct link to Chain Call Setup")

```
from langchain_community.llms import Predibasemodel = Predibase(    model="mistral-7b", predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN"))
```

```
# With a fine-tuned adapter hosted at Predibase (adapter_version can be specified; omitting it is equivalent to the most recent version).model = Predibase(    model="mistral-7b",    adapter_id="e2e_nlg",    adapter_version=1,    predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN"),)
```

```
# With a fine-tuned adapter hosted at HuggingFace (adapter_version does not apply and will be ignored).llm = Predibase(    model="mistral-7b",    adapter_id="predibase/e2e_nlg",    predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN"),)
```

## SequentialChain[​](#sequentialchain "Direct link to SequentialChain")

```
from langchain.chains import LLMChainfrom langchain_core.prompts import PromptTemplate
```

```
# This is an LLMChain to write a synopsis given a title of a play.template = """You are a playwright. Given the title of play, it is your job to write a synopsis for that title.Title: {title}Playwright: This is a synopsis for the above play:"""prompt_template = PromptTemplate(input_variables=["title"], template=template)synopsis_chain = LLMChain(llm=llm, prompt=prompt_template)
```

```
# This is an LLMChain to write a review of a play given a synopsis.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}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)
```

```
# This is the overall chain where we run these two chains in sequence.from langchain.chains import SimpleSequentialChainoverall_chain = SimpleSequentialChain(    chains=[synopsis_chain, review_chain], verbose=True)
```

```
review = overall_chain.run("Tragedy at sunset on the beach")
```

## Fine-tuned LLM (Use your own fine-tuned LLM from Predibase)[​](#fine-tuned-llm-use-your-own-fine-tuned-llm-from-predibase "Direct link to Fine-tuned LLM (Use your own fine-tuned LLM from Predibase)")

```
from langchain_community.llms import Predibasemodel = Predibase(    model="my-base-LLM",    adapter_id="my-finetuned-adapter-id",  # Supports both, Predibase-hosted and HuggingFace-hosted model repositories.    # adapter_version=1,  # optional (returns the latest, if omitted)    predibase_api_key=os.environ.get(        "PREDIBASE_API_TOKEN"    ),  # Adapter argument is optional.)# replace my-finetuned-LLM with the name of your model in Predibase
```

```
# response = model("Can you help categorize the following emails into positive, negative, and neutral?")
```