Skip to content

Commit

Permalink
fix audio tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
vincelwt committed Dec 3, 2024
1 parent 441a0e6 commit dfc7651
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
20 changes: 20 additions & 0 deletions examples/openai/audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import lunary
from openai import OpenAI
import os

client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"),
)

lunary.set_config(app_id="f94d32eb-42e2-430a-b277-3511c170267f", verbose=True)

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": "Hello world"}],
)

print(completion.choices[0])
17 changes: 0 additions & 17 deletions lunary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,23 +707,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."""

Expand Down
9 changes: 7 additions & 2 deletions lunary/openai_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json, logging

logger = logging.getLogger(__name__)

MONITORED_KEYS = [
"frequency_penalty",
"functions",
Expand Down Expand Up @@ -28,7 +29,6 @@
"parallel_tool_calls"
]


class OpenAIUtils:
@staticmethod
def parse_role(role):
Expand All @@ -55,11 +55,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,
}
Expand All @@ -76,6 +80,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
Expand Down
17 changes: 13 additions & 4 deletions lunary/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,33 @@ def default_output_parser(output, *args, **kwargs):

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"
]
Expand Down

0 comments on commit dfc7651

Please sign in to comment.