Skip to main content
GooseAI 是一个完全托管的 NLP 即服务平台,通过 API 提供服务。GooseAI 提供对这些模型的访问。 本 notebook 介绍如何将 LangChain 与 GooseAI 配合使用。

安装 openai

使用 GooseAI API 需要 openai 包。请使用 pip install openai 安装 openai
pip install -qU  langchain-openai

导入

import os

from langchain_classic.chains import LLMChain
from langchain_community.llms import GooseAI
from langchain_core.prompts import PromptTemplate

设置环境 API 密钥

确保从 GooseAI 获取您的 API 密钥。您将获得 $10 的免费额度用于测试不同模型。
from getpass import getpass

GOOSEAI_API_KEY = getpass()
os.environ["GOOSEAI_API_KEY"] = GOOSEAI_API_KEY

创建 GooseAI 实例

您可以指定不同的参数,如模型名称、最大生成 token 数、温度等。
llm = GooseAI()

创建 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)