Skip to main content

Predibase

Predibase允许您训练、微调和部署任何机器学习模型,从线性回归到大型语言模型。

此示例演示了在Predibase上部署模型时使用Langchain。

设置

要运行此笔记本,您需要一个Predibase账户和一个API密钥

您还需要安装Predibase Python包:

pip install predibase
import os

os.environ["PREDIBASE_API_TOKEN"] = "{PREDIBASE_API_TOKEN}"

初始调用

from langchain.llms import Predibase

model = Predibase(
model="vicuna-13b", predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN")
)
response = model("Can you recommend me a nice dry wine?")
print(response)

链式调用设置

llm = Predibase(
model="vicuna-13b", predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN")
)

顺序链

from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
# 这是一个LLMChain,用于根据剧本的标题编写简介。
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)
# 这是一个LLMChain,用于根据剧本的简介编写评论。
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)
# 这是整体链,我们按顺序运行这两个链。
from langchain.chains import SimpleSequentialChain

overall_chain = SimpleSequentialChain(
chains=[synopsis_chain, review_chain], verbose=True
)
review = overall_chain.run("Tragedy at sunset on the beach")

微调的LLM(使用您自己在Predibase上微调的LLM)

from langchain.llms import Predibase

model = Predibase(
model="my-finetuned-LLM", predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN")
)
# 将my-finetuned-LLM替换为您在Predibase上的模型名称
# response = model("Can you help categorize the following emails into positive, negative, and neutral?")