跳到主要内容
零一万物 (01.AI) 由李开复博士创立,是一家处于 AI 2.0 前沿的全球性公司。他们提供尖端的大型语言模型,包括参数范围从 6B 到数百亿的 Yi 系列。零一万物还提供多模态模型、开放 API 平台以及 Yi-34B/9B/6B 和 Yi-VL 等开源选项。
## Installing the langchain packages needed to use the integration
pip install -qU langchain-community

先决条件

访问 Yi LLM API 需要 API 密钥。请访问 www.lingyiwanwu.com/ 获取您的 API 密钥。申请 API 密钥时,您需要指明是用于国内(中国)还是国际使用。

使用 Yi LLM

import os

os.environ["YI_API_KEY"] = "YOUR_API_KEY"

from langchain_community.llms import YiLLM

# Load the model
llm = YiLLM(model="yi-large")

# You can specify the region if needed (default is "auto")
# llm = YiLLM(model="yi-large", region="domestic")  # or "international"

# Basic usage
res = llm.invoke("What's your name?")
print(res)
# Generate method
res = llm.generate(
    prompts=[
        "Explain the concept of large language models.",
        "What are the potential applications of AI in healthcare?",
    ]
)
print(res)
# Streaming
for chunk in llm.stream("Describe the key features of the Yi language model series."):
    print(chunk, end="", flush=True)
# Asynchronous streaming
import asyncio


async def run_aio_stream():
    async for chunk in llm.astream(
        "Write a brief on the future of AI according to Dr. Kai-Fu Lee's vision."
    ):
        print(chunk, end="", flush=True)


asyncio.run(run_aio_stream())
# Adjusting parameters
llm_with_params = YiLLM(
    model="yi-large",
    temperature=0.7,
    top_p=0.9,
)

res = llm_with_params(
    "Propose an innovative AI application that could benefit society."
)
print(res)

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