GooseAI#

GooseAI是一个完全托管的NLP-as-a-Service,通过API提供。GooseAI提供访问这些模型 (opens in a new tab)

本笔记本介绍了如何使用GooseAI (opens in a new tab)与Langchain。

安装openai#

使用GooseAI API需要安装openai软件包。使用pip3 install openai进行安装。

$ pip3 install openai

导入#

import os
from langchain.llms import GooseAI
from langchain import PromptTemplate, LLMChain

设置环境API密钥#

确保从GooseAI获取您的API密钥。您将获得10美元的免费信用以测试不同的模型。

from getpass import getpass

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

创建GooseAI实例#

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

llm = GooseAI()

创建提示模板#

我们将为问题和答案创建提示模板。

template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

启动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)