01.AI, founded by Dr. Kai-Fu Lee, is a global company at the forefront of AI 2.0. They offer cutting-edge large language models, including the Yi series, which range from 6B to hundreds of billions of parameters. 01.AI also provides multimodal models, an open API platform, and open-source options like Yi-34B/9B/6B and Yi-VL.
Copy
Ask AI
## Installing the langchain packages needed to use the integration%pip install -qU langchain-community
An API key is required to access Yi LLM API. Visit www.lingyiwanwu.com/ to get your API key. When applying for the API key, you need to specify whether it’s for domestic (China) or international use.
import osos.environ["YI_API_KEY"] = "YOUR_API_KEY"from langchain_community.llms import YiLLM# Load the modelllm = YiLLM(model="yi-large")# You can specify the region if needed (default is "auto")# llm = YiLLM(model="yi-large", region="domestic") # or "international"# Basic usageres = llm.invoke("What's your name?")print(res)
Copy
Ask AI
# Generate methodres = llm.generate( prompts=[ "Explain the concept of large language models.", "What are the potential applications of AI in healthcare?", ])print(res)
Copy
Ask AI
# Streamingfor chunk in llm.stream("Describe the key features of the Yi language model series."): print(chunk, end="", flush=True)
Copy
Ask AI
# Asynchronous streamingimport asyncioasync 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())
Copy
Ask AI
# Adjusting parametersllm_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)
Was this page helpful?
Assistant
Responses are generated using AI and may contain mistakes.