跳至主要内容

通义千问

通义千问是阿里巴巴达摩院研发的超大规模语言模型。它能够基于用户以自然语言输入的意图,通过自然语言理解和语义分析理解用户意图,并为用户在不同领域和任务中提供服务和帮助。通过提供清晰、详细的指令,可以获得更符合预期的结果。

设置

# 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().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.'

此页面是否有帮助?


您也可以在 GitHub 上留下详细的反馈 on GitHub.