Skip to content
LlamaIndex 文档版本 跟随上游 源快照 8ba33944 更新于 2026-10-18

本 notebook 演示如何将 Nebius AI Studio 的 LLM 与 LlamaIndex 一起使用。Nebius AI Studio 实现了所有可用于商业用途的最先进 LLM。

首先,让我们安装 LlamaIndex 和 Nebius AI Studio 的依赖。

%pip install llama-index-llms-nebius llama-index

从下面的系统变量中上传你的 Nebius AI Studio 密钥,或直接插入。你可以通过在 Nebius AI Studio 免费注册并在 API Keys 部分签发密钥来获取。”

import os

NEBIUS_API_KEY = os.getenv("NEBIUS_API_KEY")  # NEBIUS_API_KEY = ""
from llama_index.llms.nebius import NebiusLLM

llm = NebiusLLM(
    api_key=NEBIUS_API_KEY, model="meta-llama/Llama-3.3-70B-Instruct-fast"
)
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.

使用提示词调用 complete

response = llm.complete("Amsterdam is the capital of ")
print(response)
The Netherlands! Amsterdam is indeed the capital and largest city of the Netherlands.

使用消息列表调用 chat

from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(role="system", content="You are a helpful AI assistant."),
    ChatMessage(
        role="user",
        content="Answer briefly: who is Wall-e?",
    ),
]
response = llm.chat(messages)
print(response)
assistant: WALL-E is a small waste-collecting robot and the main character in the 2008 Pixar animated film of the same name.

流式

使用 stream_complete 端点

response = llm.stream_complete("Amsterdam is the capital of ")
for r in response:
    print(r.delta, end="")
The Netherlands! Amsterdam is indeed the capital and largest city of the Netherlands.

使用 stream_chat 和消息列表

from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(role="system", content="You are a helpful AI assistant."),
    ChatMessage(
        role="user",
        content="Answer briefly: who is Wall-e?",
    ),
]
response = llm.stream_chat(messages)
for r in response:
    print(r.delta, end="")
WALL-E is a small waste-collecting robot and the main character in the 2008 Pixar animated film of the same name.

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。