LiteLLM

LiteLLM allows developers to call all LLM APIs using the openAI format. LiteLLM Proxy is a proxy server to call 100+ LLMs in OpenAI format. Both are supported by this auto-instrumentation.

Any calls made to the following functions will be automatically captured by this integration:

  • completion()

  • acompletion()

  • completion_with_retries()

  • embedding()

  • aembedding()

  • image_generation()

  • aimage_generation()

Launch Phoenix

Install packages:

pip install arize-phoenix

Launch Phoenix:

import phoenix as px
px.launch_app()

Connect your notebook to Phoenix:

from phoenix.otel import register

tracer_provider = register(
  project_name="my-llm-app", # Default is 'default'
)

By default, notebook instances do not have persistent storage, so your traces will disappear after the notebook is closed. See Persistence or use one of the other deployment options to retain traces.

Install

pip install openinference-instrumentation-litellm litellm

Setup

Initialize the InstructorInstrumentor before your application code.

from openinference.instrumentation.litellm import LiteLLMInstrumentor

LiteLLMInstrumentor().instrument(tracer_provider=tracer_provider)

Add any API keys needed by the models you are using with LiteLLM.

import os
os.environ["OPENAI_API_KEY"] = "PASTE_YOUR_API_KEY_HERE"

Run LiteLLM

You can now use LiteLLM as normal and calls will be traces in Phoenix.

import litellm
completion_response = litellm.completion(model="gpt-3.5-turbo", 
                   messages=[{"content": "What's the capital of China?", "role": "user"}])
print(completion_response)

Observe

Traces should now be visible in Phoenix!

Resources

Last updated