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
# 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))