跳到主要内容
百川智能 (www.baichuan-ai.com/) 是一家通用人工智能时代的中国初创公司,致力于解决人类基本需求:效率、健康和幸福。
##Installing the langchain packages needed to use the integration
pip install -qU langchain-community

先决条件

访问百川大模型 API 需要 API 密钥。请访问 platform.baichuan-ai.com/ 获取您的 API 密钥。

使用百川大模型

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

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