Yi
01.AI,由李开复博士创立,是一家处于AI 2.0前沿的全球公司。他们提供先进的大型语言模型,包括Yi系列,参数范围从6B到数千亿。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 Reference: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)
相关
- LLM 概念指南
- LLM how-to guides