通義千問 (Tongyi Qwen)
通義千問是阿里巴巴達摩院開發的大規模語言模型。它能夠通過自然語言理解和語義分析來理解用戶意圖,基於自然語言的用戶輸入。它在不同領域和任務中為用戶提供服務和幫助。通過提供清晰和詳細的說明,您可以獲得更符合您期望的結果。
設定
# Install the package
%pip install --upgrade --quiet langchain-community dashscope
# Get a new token: https://help.aliyun.com/document_detail/611472.html?spm=a2c4g.2399481.0.0
from getpass import getpass
DASHSCOPE_API_KEY = getpass()
········
import os
os.environ["DASHSCOPE_API_KEY"] = DASHSCOPE_API_KEY
from langchain_community.llms import Tongyi
API 參考:Tongyi
Tongyi().invoke("What NFL team won the Super Bowl in the year Justin Bieber was born?")
'Justin Bieber was born on March 1, 1994. The Super Bowl that took place in the same year was Super Bowl XXVIII, which was played on January 30, 1994. The winner of that Super Bowl was the Dallas Cowboys, who defeated the Buffalo Bills with a score of 30-13.'
在鏈中使用
from langchain_core.prompts import PromptTemplate
API 參考:PromptTemplate
llm = Tongyi()
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate.from_template(template)
chain = prompt | llm
question = "What NFL team won the Super Bowl in the year Justin Bieber was born?"
chain.invoke({"question": question})
'Justin Bieber was born on March 1, 1994. The Super Bowl that took place in the same calendar year was Super Bowl XXVIII, which was played on January 30, 1994. The winner of Super Bowl XXVIII was the Dallas Cowboys, who defeated the Buffalo Bills with a score of 30-13.'