ForefrontAI
Forefront
平台讓您能夠微調和使用開放原始碼大型語言模型。
本筆記本說明如何將 Langchain 與ForefrontAI 一起使用。
匯入
import os
from langchain.chains import LLMChain
from langchain_community.llms import ForefrontAI
from langchain_core.prompts import PromptTemplate
設定環境 API 金鑰
請務必從 ForefrontAI 取得您的 API 金鑰。您將獲得 5 天的免費試用期來測試不同的模型。
# get a new token: https://docs.forefront.ai/forefront/api-reference/authentication
from getpass import getpass
FOREFRONTAI_API_KEY = getpass()
os.environ["FOREFRONTAI_API_KEY"] = FOREFRONTAI_API_KEY
建立 ForefrontAI 實例
您可以指定不同的參數,例如模型端點 URL、長度、溫度等。您必須提供端點 URL。
llm = ForefrontAI(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)