Skip to content

Commit c9be67a

Browse files
committed
chore: fix test cases
1 parent 379a132 commit c9be67a

File tree

3 files changed

+446
-30
lines changed

3 files changed

+446
-30
lines changed

backend/app/crud/llm.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from uuid import UUID
1414
from sqlmodel import Session, select
1515
from app.core.util import now
16+
import base64
1617
import json
1718
from app.models.llm import LlmCall, LLMCallRequest, ConfigBlob
1819
from app.models.llm.request import (
@@ -176,35 +177,18 @@ def update_llm_call_response(
176177
db_llm_call.provider_response_id = provider_response_id
177178

178179
if content is not None:
179-
# For TTS responses: transform audio_bytes to metadata only
180-
# (audio_bytes should already be converted to audio_base64 by LLMOutput validator,
181-
# but handle it defensively in case it wasn't)
182-
if "audio_bytes" in content:
183-
import base64
184-
185-
audio_bytes = content.pop("audio_bytes")
186-
if audio_bytes:
187-
content["audio_size_bytes"] = len(audio_bytes)
188-
# Convert to base64 for storage if not already done
189-
if "audio_base64" not in content:
190-
content["audio_base64"] = base64.b64encode(audio_bytes).decode(
191-
"utf-8"
180+
# For audio outputs (AudioOutput model): calculate size metadata from base64 content
181+
# AudioOutput serializes as: {"type": "audio", "content": {"format": "base64", "value": "...", "mime_type": "..."}}
182+
if content.get("type") == "audio":
183+
audio_value = content.get("content", {}).get("value")
184+
if audio_value:
185+
try:
186+
audio_data = base64.b64decode(audio_value)
187+
content["audio_size_bytes"] = len(audio_data)
188+
except Exception as e:
189+
logger.warning(
190+
f"[update_llm_call_response] Failed to calculate audio size: {e}"
192191
)
193-
logger.info(
194-
f"[update_llm_call_response] Converted audio_bytes to audio_base64 for storage"
195-
)
196-
197-
# Calculate audio size from base64 if present and audio_size_bytes not set
198-
if "audio_base64" in content and "audio_size_bytes" not in content:
199-
import base64
200-
201-
try:
202-
audio_data = base64.b64decode(content["audio_base64"])
203-
content["audio_size_bytes"] = len(audio_data)
204-
except Exception as e:
205-
logger.warning(
206-
f"[update_llm_call_response] Failed to calculate audio size: {e}"
207-
)
208192

209193
db_llm_call.content = content
210194

backend/app/services/llm/jobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def execute_job(
371371
)
372372

373373
else:
374-
response.response.output.text = safe_output["error"]
374+
response.response.output.content.value = safe_output["error"]
375375

376376
callback_response = APIResponse.failure_response(
377377
error=safe_output["error"],

0 commit comments

Comments
 (0)