fix: extract content from ASR JSON before sending to Antaf

ASR wraps user speech as JSON {"content":"...", "language":"zh", "emotion":"..."},
extract only the content field instead of sending raw JSON to Antaf bridge.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hailin 2026-04-05 20:32:45 -07:00
parent cb9d430cfc
commit 12b4994ac0
1 changed files with 10 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import json
import requests
from config.logger import setup_logging
from core.providers.llm.base import LLMProviderBase
@ -61,6 +62,14 @@ class LLMProvider(LLMProviderBase):
if msg.get("role") == "user":
content = msg.get("content", "")
if not self._is_system_injected(content):
# ASR 结果可能是 JSON: {"content":"...", "language":"zh", "emotion":"..."}
try:
parsed = json.loads(content)
if isinstance(parsed, dict) and "content" in parsed:
query = parsed["content"]
else:
query = content
except (json.JSONDecodeError, TypeError):
query = content
break