comet-ml / opik

Open-source end-to-end LLM Development Platform
Apache License 2.0
2.2k stars 135 forks source link

Implement tracking for beta.chat.completions.parse method #707

Closed jverre closed 15 hours ago

jverre commented 2 days ago

Details

Updated the OpenAI integration to track openai_client.beta.chat.completions.parse calls:

from opik.integrations.openai import opik_tracker
from openai import OpenAI
from pydantic import BaseModel

client = opik_tracker.track_openai(OpenAI())

class CalendarEvent(BaseModel):
    name: str
    date: str
    participants: list[str]

completion = client.beta.chat.completions.parse(
    model="gpt-4o-2024-08-06",
    messages=[
        {"role": "system", "content": "Extract the event information."},
        {"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
    ],
    response_format=CalendarEvent,
)

print(completion)

Issues

Resolves #706

Testing

Added a new end to end test and updated the examples/openai_integration_example.py method.

Documentation

OpenAI integration page was updated