Skip to main content

CerebriumAI

Cerebrium 是 AWS Sagemaker 的替代品。它还提供对 多个大型语言模型 的 API 访问。

本笔记本介绍了如何将 LangChain 与 CerebriumAI 一起使用。

安装 cerebrium

cerebrium 包是使用 CerebriumAI API 所必需的。使用 pip3 install cerebrium 安装 cerebrium

# Install the package
!pip3 install cerebrium

导入

<!--IMPORTS:[{"imported": "LLMChain", "source": "langchain.chains", "docs": "https://python.langchain.com/api_reference/langchain/chains/langchain.chains.llm.LLMChain.html", "title": "CerebriumAI"}, {"imported": "CerebriumAI", "source": "langchain_community.llms", "docs": "https://python.langchain.com/api_reference/community/llms/langchain_community.llms.cerebriumai.CerebriumAI.html", "title": "CerebriumAI"}, {"imported": "PromptTemplate", "source": "langchain_core.prompts", "docs": "https://python.langchain.com/api_reference/core/prompts/langchain_core.prompts.prompt.PromptTemplate.html", "title": "CerebriumAI"}]-->
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)

相关


Was this page helpful?


You can also leave detailed feedback on GitHub.

扫我,入群扫我,找书