跳到主要內容
Open In ColabOpen on GitHub

Yuan2.0

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
API 參考文件:LLMChain | 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))

此頁面是否對您有幫助?