Skip to content

Conversation

Gmin2
Copy link
Contributor

@Gmin2 Gmin2 commented Aug 11, 2025

Details

Supported openapi tts model tracking

Issues

Resolves #2202

Testing

Screenshot from 2025-06-23 12-58-48

Followup of #2547

@Gmin2 Gmin2 requested a review from a team as a code owner August 11, 2025 09:16
@Gmin2
Copy link
Contributor Author

Gmin2 commented Aug 11, 2025

Hey @andrescrz i have followed up and open a pr in #2984

cc @vincentkoc

def test_openai_client_audio_speech_create__happyflow(
respx_mock, fake_backend, project_name, expected_project_name
):
respx_mock.post("https://api.aimlapi.com/v1/audio/speech").respond(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our library integration tests we're trying not to mock LLM providers to make sure we're processing them correctly. Let's replace it with a real request.

tags=["openai"],
metadata=ANY_DICT,
usage={
"total_tokens": len(INPUT_FOR_TESTS),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage expected here doesn't look like the usage openai declares they send (audio tokens are expected to be in input_tokens_details and output_tokens_details).

if current_span_data.input and current_span_data.input.get("input"):
opik_usage = llm_usage.try_build_opik_usage_or_log_error(
provider=LLMProvider.OPENAI,
usage={"total_tokens": len(current_span_data.input["input"])},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look correct (already mentioned in the tests comment).
We need to pass the real usage data from the response here.

error_message="Failed to log token usage from openai call",
)
result = arguments_helpers.EndSpanParameters(
output={},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be None, let's encode it with base64.

output={},
usage=opik_usage,
metadata={},
model=current_span_data.model,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should extract the exact model name from the provider response

import pydantic


class OpenAIAudioSpeechUsage(pydantic.BaseModel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this class, audio tokens are already part of the existing and known openai token usage dicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]: Support Openai TTS models tracking

3 participants