diff --git a/examples/openai/audio.py b/examples/openai/audio.py new file mode 100644 index 0000000..2130514 --- /dev/null +++ b/examples/openai/audio.py @@ -0,0 +1,18 @@ +import lunary +from openai import OpenAI +import os + +client = OpenAI( + api_key=os.environ.get("OPENAI_API_KEY"), +) + +lunary.monitor(client) + +completion = client.chat.completions.create( + model="gpt-4o-audio-preview", + modalities=["audio", "text"], + audio={"voice": "alloy", "format": "wav"}, + messages=[{"role": "user", "content": "Tell me a short story"}], +) + +print(completion.choices[0]) diff --git a/lunary/__init__.py b/lunary/__init__.py index 6c3f816..8379f45 100644 --- a/lunary/__init__.py +++ b/lunary/__init__.py @@ -773,23 +773,6 @@ def decorator(fn): spans: Dict[str, Any] = {} - PARAMS_TO_CAPTURE = [ - "temperature", - "top_p", - "top_k", - "stop", - "presence_penalty", - "frequency_penalty", - "seed", - "function_call", - "functions", - "tools", - "tool_choice", - "response_format", - "max_tokens", - "logit_bias", - ] - class UserContextManager: """Context manager for Lunary user context.""" diff --git a/lunary/openai_utils.py b/lunary/openai_utils.py index c35d34d..b5c261e 100644 --- a/lunary/openai_utils.py +++ b/lunary/openai_utils.py @@ -28,7 +28,6 @@ "parallel_tool_calls" ] - class OpenAIUtils: @staticmethod def parse_role(role): @@ -55,11 +54,15 @@ def parse_message(message): ] tool_calls = tool_calls_serialized + audio = OpenAIUtils.get_property(message, "audio") + if audio is not None: + audio = json.loads(audio.model_dump_json(indent=2, exclude_unset=True)) + parsed_message = { "role": OpenAIUtils.get_property(message, "role"), "content": OpenAIUtils.get_property(message, "content"), "refusal": OpenAIUtils.get_property(message, "refusal"), - "audio": OpenAIUtils.get_property(message, "audio"), + "audio": audio, "function_call": OpenAIUtils.get_property(message, "function_call"), "tool_calls": tool_calls, } @@ -76,6 +79,7 @@ def parse_input(*args, **kwargs): or kwargs.get("deployment_id", None) ) extra = {key: kwargs[key] for key in MONITORED_KEYS if key in kwargs} + return {"name": name, "input": messages, "extra": extra} @staticmethod diff --git a/lunary/parsers.py b/lunary/parsers.py index bcb6672..289cdac 100644 --- a/lunary/parsers.py +++ b/lunary/parsers.py @@ -49,24 +49,33 @@ def flatten(self, obj, data): PARAMS_TO_CAPTURE = [ "frequency_penalty", - "function_call", + "function_call", "functions", "logit_bias", "logprobs", "max_tokens", + "max_completion_tokens", "n", - "presence_penalty", + "presence_penalty", "response_format", "seed", "stop", + "stream", + "audio", + "modalities", "temperature", "tool_choice", "tools", + "tool_calls", + "top_p", + "top_k", "top_logprobs", - "top_p", + "prediction", + "service_tier", + "parallel_tool_calls", # Additional params "extra_headers", - "extra_query", + "extra_query", "extra_body", "timeout" ]