feat: add AI_VOICE_AI_TIMEOUT_SECONDS for configurable voice timeout
deploy / deploy (push) Successful in 30s

This commit is contained in:
2026-08-29 00:50:08 +05:00
parent b8c922c9cf
commit 09bcf7457c
5 changed files with 74 additions and 11 deletions
+16 -2
View File
@@ -1475,6 +1475,14 @@ def _ai_timeout_seconds() -> float:
return max(3.0, _float_env("AI_TIMEOUT_SECONDS", 20.0))
def _ai_voice_timeout_seconds() -> float:
return max(3.0, _float_env("AI_VOICE_AI_TIMEOUT_SECONDS", _ai_timeout_seconds()))
def _ai_decision_max_tokens() -> int:
return max(64, int(_float_env("AI_DECISION_MAX_TOKENS", 500)))
def _ai_telegram_enabled() -> bool:
return _bool_env("AI_TELEGRAM_ENABLED", False)
@@ -2339,17 +2347,23 @@ def _openai_prompt(
]
def _request_structured_model_decision(messages: list[dict[str, str]]) -> dict[str, Any]:
def _request_structured_model_decision(
messages: list[dict[str, str]],
*,
timeout_seconds: float | None = None,
) -> dict[str, Any]:
if not _ai_api_base() or not _ai_api_key():
raise RuntimeError("AI_API_BASE / AI_API_KEY are required for openai_compatible provider")
started = time.perf_counter()
payload = {
"model": _ai_model(),
"temperature": 0.2,
"max_tokens": _ai_decision_max_tokens(),
"response_format": {"type": "json_object"},
"messages": messages,
}
with httpx.Client(timeout=_ai_timeout_seconds()) as client:
effective_timeout = timeout_seconds if timeout_seconds is not None else _ai_timeout_seconds()
with httpx.Client(timeout=effective_timeout) as client:
response = client.post(
f"{_ai_api_base()}/chat/completions",
json=payload,
+2 -1
View File
@@ -1664,7 +1664,8 @@ def _voice_llm_decision(
name_value=name_value,
name_status=name_status,
operator_config=operator_config,
)
),
timeout_seconds=app._ai_voice_timeout_seconds(),
)
except Exception:
return None