跳到主要内容
Yuan2.0 是中科曙光(IEIT System)开发的新一代基础大语言模型。我们已经发布了三个模型:Yuan 2.0-102B、Yuan 2.0-51B 和 Yuan 2.0-2B。我们还为其他开发者提供了预训练、微调和推理服务的相关脚本。Yuan2.0 基于 Yuan1.0,利用更广泛的高质量预训练数据和指令微调数据集,增强了模型对语义、数学、推理、代码、知识等方面的理解。 本示例将介绍如何使用 LangChain 与 Yuan2.0 (2B/51B/102B) 推理服务进行交互以生成文本。 Yuan2.0 建立了推理服务,用户只需请求推理 API 即可获取结果,具体内容在 Yuan2.0 推理服务器 中有介绍。
from langchain.chains import LLMChain
from langchain_community.llms.yuan2 import Yuan2
# default infer_api for a local deployed Yuan2.0 inference server
infer_api = "http://127.0.0.1:8000/yuan"

# direct access endpoint in a proxied environment
# import os
# os.environ["no_proxy"]="localhost,127.0.0.1,::1"

yuan_llm = Yuan2(
    infer_api=infer_api,
    max_tokens=2048,
    temp=1.0,
    top_p=0.9,
    use_history=False,
)

# turn on use_history only when you want the Yuan2.0 to keep track of the conversation history
# and send the accumulated context to the backend model api, which make it stateful. By default it is stateless.
# llm.use_history = True
question = "请介绍一下中国。"
print(yuan_llm.invoke(question))

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.