跳到主要內容
Open In ColabOpen on GitHub

CerebriumAI

Cerebrium 是 AWS Sagemaker 的替代方案。它也提供 API 存取 多種 LLM 模型

本筆記本說明如何將 Langchain 與 CerebriumAI 搭配使用。

安裝 cerebrium

使用 CerebriumAI API 需要 cerebrium 套件。使用 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")

建立提示範本

我們將為問答建立提示範本。

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)

此頁面是否對您有幫助?