docs/examples/llm/yi.ipynb
<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/llm/yi.ipynb" target="_parent"></a>
This notebook shows how to use Yi series LLMs.
If you're opening this Notebook on colab, you will need to install LlamaIndex 🦙 and the Yi Python SDK.
%pip install llama-index-llms-yi
!pip install llama-index
You will need to get an API key from platform.01.ai. Once you have one, you can either pass it explicity to the model, or use the YI_API_KEY environment variable.
The details are as follows
import os
os.environ["YI_API_KEY"] = "your api key"
complete with a promptfrom llama_index.llms.yi import Yi
llm = Yi(model="yi-large")
response = llm.complete("What is the capital of France?")
print(response)
chat with a list of messagesfrom llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.chat(messages)
print(resp)
Using stream_complete endpoint
from llama_index.llms.yi import Yi
llm = Yi(model="yi-large")
response = llm.stream_complete("Who is Paul Graham?")
for r in response:
print(r.delta, end="")
Using stream_chat endpoint
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.stream_chat(messages)
for r in resp:
print(r.delta, end="")