CerebriumAI
Cerebrium
是 AWS Sagemaker 的替代方案。 它還提供對 多個 LLM 模型 的 API 訪問權限。
本筆記本介紹了如何將 Langchain 與 CerebriumAI 一起使用。
安裝 cerebrium
需要 cerebrium
套件才能使用 CerebriumAI
API。 使用 pip3 install cerebrium
安裝 cerebrium
。
# Install the package
!pip3 install cerebrium
匯入
import os
from langchain.chains import LLMChain
from langchain_community.llms import CerebriumAI
from langchain_core.prompts import PromptTemplate
設定環境 API 金鑰
請務必從 CerebriumAI 取得您的 API 金鑰。 請參閱 此處。 您可以獲得 1 小時的免費無伺服器 GPU 計算來測試不同的模型。
os.environ["CEREBRIUMAI_API_KEY"] = "YOUR_KEY_HERE"
建立 CerebriumAI 實例
您可以指定不同的參數,例如模型端點 URL、最大長度、溫度等。您必須提供端點 URL。
llm = CerebriumAI(endpoint_url="YOUR ENDPOINT URL HERE")
建立 Prompt 範本
我們將建立一個用於問答的 Prompt 範本。
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate.from_template(template)
初始化 LLMChain
llm_chain = LLMChain(prompt=prompt, llm=llm)
執行 LLMChain
提供一個問題並執行 LLMChain。
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.run(question)