Skip to main content
Open In ColabOpen on GitHub

通义千问

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

设置

This guide will walk you

# 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 Reference: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 Reference: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.'