Comet Opik

Comet Opik

Opik은 개발 중과 운영 환경에서 LLM 프롬프트와 응답을 추적할 수 있게 도와주는 오픈소스 엔드투엔드 LLM 평가 플랫폼이에요. 개발자는 배포 전에 LLM 앱을 테스트하기 위해 평가를 정의하고 실행하여 환각(hallucination), 정확성, 컨텍스트 검색 등을 확인할 수 있어요!

출처: 문서

본문

사전 준비 (Pre-Requisites)

Opik 설정에 대해 더 알아보려면 Opik quickstart 가이드를 참고하세요. Opik 셀프 호스팅에 대해 더 알아보려면 셀프 호스팅 가이드를 참고할 수도 있어요.

빠른 시작 (Quick Start)

단 4줄의 코드로 모든 프로바이더의 응답을 Opik으로 즉시 기록할 수 있어요.

Opik API 키는 여기에서 가입해서 받을 수 있어요!

import litellm
litellm.callbacks = ["opik"]

전체 예시:

SDK

import litellm
import os

# Configure the Opik API key or call opik.configure()
os.environ["OPIK_API_KEY"] = ""
os.environ["OPIK_WORKSPACE"] = ""

# LLM provider API Keys:
os.environ["OPENAI_API_KEY"] = ""

# set "opik" as a callback, litellm will send the data to an Opik server (such as comet.com)
litellm.callbacks = ["opik"]

# openai call
response = litellm.completion(
    model="gpt-5.6-luna",
    messages=[
        {"role": "user", "content": "Why is tracking and evaluation of LLMs important?"}
    ])

Opik의 @track 데코레이터로 추적되는 함수 안에서 liteLLM을 사용한다면, LLM 호출이 올바른 트레이스에 할당되도록 metadata 속성에 current_span_data 필드를 제공해야 해요:

from opik import track
from opik.opik_context import get_current_span_data
import litellm

litellm.callbacks = ["opik"]

@track()
def streaming_function(input):
    messages = [{"role": "user", "content": input}]
    response = litellm.completion(
        model="gpt-5.6-luna",
        messages=messages,
        metadata = {
            "opik": {
                "current_span_data": get_current_span_data(),
                "tags": ["streaming-test"],
            },
        }
    )
    return response

response = streaming_function("Why is tracking and evaluation of LLMs important?")
chunks = list(response)

Proxy

config.yaml 설정:

model_list:
  - model_name: gpt-3.5-turbo-testing
    litellm_params:
      model: gpt-5.6-luna
      api_key: os.environ/OPENAI_API_KEY

litellm_settings:
  callbacks: ["opik"]

environment_variables:
  OPIK_API_KEY: ""
  OPIK_WORKSPACE: ""

프록시 실행:

litellm --config config.yaml

테스트:

curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer ***" \
  -d '{
  "model": "gpt-3.5-turbo-testing",
  "messages": [
    {
      "role": "user",
      "content": "What's the weather like in Boston today?"
    }
  ]
}'

Opik 특정 파라미터 (Opik-Specific Parameters)

이들은 metadata 안에서 opik 키로 전달할 수 있어요.

필드 (Fields)

  • project_name - 데이터를 보낼 Opik 프로젝트 이름
  • current_span_data - 추적에 사용할 현재 span 데이터
  • tags - 추적에 사용할 태그
  • thread_id - 여러 관련 트레이스를 하나로 묶는 스레드 ID

사용법 (Usage)

SDK

from opik import track
from opik.opik_context import get_current_span_data
import litellm

litellm.callbacks = ["opik"]
messages = [{"role": "user", "content": input}]
response = litellm.completion(
    model="gpt-5.6-luna",
    messages=messages,
    metadata = {
        "opik": {
            "project_name": "your-opik-project-name",
            "current_span_data": get_current_span_data(),
            "tags": ["streaming-test"],
            "thread_id": "your-thread-id"
        },
    })
return response

Proxy

curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer ***" \
  -d '{
  "model": "gpt-5.6-luna",
  "messages": [
    {
      "role": "user",
      "content": "What's the weather like in Boston today?"
    }
  ],
  "metadata": {
    "opik": {
      "project_name": "your-opik-project-name",
      "current_span_data": "...",
      "tags": ["streaming-test"],
      "thread_id": "your-thread-id"
    },
  }
}'

요청 헤더에 opik_* 접두사를 붙여 필드를 전달할 수도 있어요:

curl --location --request POST 'http://0.0.0.0:4000/chat/completions' \
    --header 'Content-Type: application/json' \
    --header "Authorization: Bearer ***" \
    --header 'opik_project_name: your-opik-project-name' \
    --header 'opik_thread_id: your-thread-id' \
    --header 'opik_tags: ["streaming-test"]' \
    --data '{
    "model": "gpt-5.6-luna",
    "messages": [
        {
        "role": "user",
        "content": "What's the weather like in Boston today?"
        }
    ]
}'

API 키에서 자동 메타데이터 (Automatic Metadata from API Keys)

경우에 따라 요청자가 요청에 Opik 메타데이터를 추가하지 못하거나 방법을 모를 수 있어요. 모든 Opik 관련 작업이 제대로 추적되도록, LiteLLM Proxy는 요청에 제공된 메타데이터가 없을 때 사용자별 API 키에서 메타데이터를 자동으로 연결할 수 있어요.

동작 방식 (How It Works)

LiteLLM Proxy에서 API 키를 만들 때 Opik 특정 메타데이터를 키 자체에 첨부할 수 있어요. 이 메타데이터는 요청이 자체 Opik 메타데이터를 명시적으로 제공하지 않는 한(제공하면 우선), 해당 키로 이루어지는 모든 요청에 자동으로 적용돼요.

사용법 (Usage)

Step 1: 해당 API 키에 Opik 메타데이터 저장

'Virtual Keys'로 이동해 선택한 API 키를 클릭하고 'Settings'를 편집하세요. 이제 opik 메타데이터를 사용자 API 키 메타데이터로 저장하세요.

Step 2: 키 사용 - Opik 메타데이터가 자동으로 적용됨

curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ***' \
  -d '{
  "model": "gpt-5.6-luna",
  "messages": [
    {
      "role": "user",
      "content": "What's the weather like in Boston today?"
    }
  ]
}'

이 키로 이루어지는 모든 요청은 사용자가 각 요청에 메타데이터를 전달하지 않아도 지정된 태그와 함께 "TestProject" Opik 프로젝트에서 자동으로 추적돼요.

더 알아보기 (Learn more)