Yi
01.AI,由李开复博士创立,是一家处于 AI 2.0 前沿的全球公司。他们提供尖端的大型语言模型,包括 Yi 系列,参数范围从 60 亿到数百亿。01.AI 还提供多模态模型,开放 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 密钥。访问 https://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)
API 参考:YiLLM
# 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)