百川 LLM
百川智能(https://www.baichuan-ai.com/)是一家中國人工通用智慧時代的創業公司,致力於滿足人類的基本需求:效率、健康和快樂。
##Installing the langchain packages needed to use the integration
%pip install -qU langchain-community
先決條件
需要 API 金鑰才能存取百川 LLM API。請訪問 https://platform.baichuan-ai.com/ 以取得您的 API 金鑰。
使用百川 LLM
import os
os.environ["BAICHUAN_API_KEY"] = "YOUR_API_KEY"
from langchain_community.llms import BaichuanLLM
# Load the model
llm = BaichuanLLM()
res = llm.invoke("What's your name?")
print(res)
API 參考:BaichuanLLM
res = llm.generate(prompts=["你好!"])
res
for res in llm.stream("Who won the second world war?"):
print(res)
import asyncio
async def run_aio_stream():
async for res in llm.astream("Write a poem about the sun."):
print(res)
asyncio.run(run_aio_stream())