The Nebuly SDK enables you to monitor all the requests made to:

All of them are supported also when using stream or async mode.

The process is straightforward, you just need to:

  • import the LlamaIndexTrackingHandler from the Nebuly SDK
  • setup the LlamaIndexTrackingHandler as global llama_index handler

You can then use the platform to analyze the results and get insights about your LLM users.

LLMs

  • Python

from nebuly.providers.llama_index import LlamaIndexTrackingHandler

handler = LlamaIndexTrackingHandler(
    api_key="<YOUR_NEBULY_API_KEY>",
    user_id="<USER_ID>",
    # Nebuly additional kwargs...
)

import llama_index
from llama_index.core.base.llms.types import ChatMessage, MessageRole
from llama_index.llms.openai import OpenAI

# Setup the global handler to track llms calls
llama_index.core.global_handler = handler

response = OpenAI(api_key="YOUR_OPENAI_API_KEY").chat(
    messages=[
        ChatMessage(
            role=MessageRole.USER, content="Who is Paul Graham?"
        )
    ]
)

You can find a detailed explanation of the allowed nebuly additional keyword arguments below:

user_id
string
required

An id or username uniquely identifying the end-user. We recommend hashing their username or email address, in order to avoid sending us any identifying information.

nebuly_tags
dict

Tag user interactions by adding key-value pairs using this parameter. Each key represents the tag name, and the corresponding value is the tag value.

For example, if you want to tag an interaction with the model version used to reply to user input, provide it as an argument for nebuly_tags, e.g. {"version": "v1.0.0"}. You have the flexibility to define custom tags, making them available as potential filters on the Nebuly platform.

Query Engine

You can download the file used in this example here: paul_graham_essay.txt

  • Python

from nebuly.providers.llama_index import LlamaIndexTrackingHandler

handler = LlamaIndexTrackingHandler(
    api_key="<YOUR_NEBULY_API_KEY>", 
    user_id="<USER_ID>"
    # Nebuly additional kwargs...
)

import os
import urllib.request

import llama_index
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

# Setup the global handler to track llms calls
llama_index.core.global_handler = handler
os.environ["OPENAI_API_KEY"] = "<YOUR_OPENAI_API_KEY>"

# Define the directory and file paths - NEEDED FOR THIS EXAMPLE
url = "https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt"
dir_path = "data"
file_path = os.path.join(dir_path, "paul_graham_essay.txt")
os.makedirs(dir_path, exist_ok=True)
urllib.request.urlretrieve(url, file_path)
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")

You can find a detailed explanation of the allowed nebuly additional keyword arguments below:

user_id
string
required

An id or username uniquely identifying the end-user. We recommend hashing their username or email address, in order to avoid sending us any identifying information.

nebuly_tags
dict

Tag user interactions by adding key-value pairs using this parameter. Each key represents the tag name, and the corresponding value is the tag value.

For example, if you want to tag an interaction with the model version used to reply to user input, provide it as an argument for nebuly_tags, e.g. {"version": "v1.0.0"}. You have the flexibility to define custom tags, making them available as potential filters on the Nebuly platform.

Chat Engine

You can download the file used in this example here: paul_graham_essay.txt

  • Python

from nebuly.providers.llama_index import LlamaIndexTrackingHandler

handler = LlamaIndexTrackingHandler(
    api_key="<YOUR_NEBULY_API_KEY>",
    user_id="<USER_ID>",
    # Additional nebuly kwargs...
)

import os
import urllib.request

import llama_index
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.base.llms.types import ChatMessage, MessageRole
from llama_index.core.memory import ChatMemoryBuffer

# Setup the global handler to track llms calls
llama_index.core.global_handler = handler
os.environ["OPENAI_API_KEY"] = "<YOUR_OPENAI_API_KEY>"

# Define the directory and file paths - NEEDED FOR THIS EXAMPLE
url = "https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt"
dir_path = "data"
file_path = os.path.join(dir_path, "paul_graham_essay.txt")
os.makedirs(dir_path, exist_ok=True)
urllib.request.urlretrieve(url, file_path)

documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)
memory = ChatMemoryBuffer.from_defaults()
chat_engine = index.as_chat_engine(
    chat_mode="context",
    memory=memory,
    system_prompt=(
        "You are a chatbot, able to have normal interactions, as well as talk"
        " about an essay discussing Paul Graham's life."
    ),
)
response = chat_engine.chat(
    "What did Paul Graham do growing up?",
    chat_history=[
        ChatMessage(role=MessageRole.USER, content="Hello"),
        ChatMessage(role=MessageRole.ASSISTANT, content="Hello, how can I help you?"),
    ],
)

You can find a detailed explanation of the allowed nebuly additional keyword arguments below:

user_id
string
required

An id or username uniquely identifying the end-user. We recommend hashing their username or email address, in order to avoid sending us any identifying information.

nebuly_tags
dict

Tag user interactions by adding key-value pairs using this parameter. Each key represents the tag name, and the corresponding value is the tag value.

For example, if you want to tag an interaction with the model version used to reply to user input, provide it as an argument for nebuly_tags, e.g. {"version": "v1.0.0"}. You have the flexibility to define custom tags, making them available as potential filters on the Nebuly platform.