Skip to main content
Open In ColabOpen on GitHub

GooseAI

GooseAI 是一项通过 API 提供的完全托管的“自然语言处理即服务”。GooseAI 提供对 这些模型 的访问。

本笔记本介绍了如何将Langchain与GooseAI一起使用。

安装 openai

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

%pip install --upgrade --quiet  langchain-openai

Imports

import os

from langchain.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实例

您可以指定不同的参数,如模型名称、生成的最大tokens数量、温度等。

llm = GooseAI()

创建一个提示模板

我们将为问答创建一个提示模板。

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)