跳至主要內容

GooseAI

GooseAI 是一個完全託管的 NLP 即服務,透過 API 提供。 GooseAI 提供對這些模型的存取權。

本筆記本介紹如何將 Langchain 與GooseAI 一起使用。

安裝 openai

需要 openai 套件才能使用 GooseAI API。使用 pip install openai 安裝 openai

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

匯入

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 實例

您可以指定不同的參數,例如模型名稱、產生的最大 token 數、溫度等。

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)

此頁面是否有幫助?