作为独立模块使用LLM#
您可以单独使用我们的LLM模块。
文本补全示例#
from llama_index.llms.openai import OpenAI
# 非流式
resp = OpenAI().complete("Paul Graham is ")
print(resp)
# 使用流式端点
from llama_index.llms.openai import OpenAI
llm = OpenAI()
resp = llm.stream_complete("Paul Graham is ")
for delta in resp:
print(delta, end="")
聊天示例#
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai import OpenAI
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = OpenAI().chat(messages)
print(resp)
查看我们的模块部分以获取每个LLM的使用指南。