前沿人工智能
The Forefront 平台为您提供微调和使用开源大语言模型的能力。
本笔记本介绍了如何将Langchain与ForefrontAI一起使用。
Imports
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)