Add russian translate
This commit is contained in:
@@ -27,11 +27,11 @@ def is_reset_command(text: str) -> bool:
|
||||
|
||||
|
||||
def ask_agent_stream(text: str, conv=None, agent_id: str = "cosmo") -> str:
|
||||
"""
|
||||
Отправляет запрос к OpenClaw gateway как полноценный агент.
|
||||
История хранится на стороне gateway (session_key).
|
||||
conv параметр сохранён для обратной совместимости, не используется.
|
||||
"""
|
||||
"""Отправляет запрос к OpenClaw gateway и озвучивает ответ."""
|
||||
def _maybe_speak(t: str):
|
||||
if t.strip():
|
||||
speak(t, agent_id)
|
||||
|
||||
cfg = AGENTS.get(agent_id, AGENTS["cosmo"])
|
||||
gateway_url = cfg["gateway_url"]
|
||||
session = cfg["session"]
|
||||
@@ -61,21 +61,21 @@ def ask_agent_stream(text: str, conv=None, agent_id: str = "cosmo") -> str:
|
||||
msg = "Не могу связаться с сервером, попробуй ещё раз."
|
||||
print(f"⚠️ {msg}")
|
||||
play_error_sound()
|
||||
speak(msg, agent_id)
|
||||
_maybe_speak(msg)
|
||||
return msg
|
||||
except requests.Timeout:
|
||||
log.exception("Gateway таймаут")
|
||||
msg = "Сервер не ответил вовремя, попробуй ещё раз."
|
||||
print(f"⚠️ {msg}")
|
||||
play_error_sound()
|
||||
speak(msg, agent_id)
|
||||
_maybe_speak(msg)
|
||||
return msg
|
||||
except requests.HTTPError:
|
||||
log.exception(f"Gateway HTTP ошибка {resp.status_code}")
|
||||
msg = "Ошибка сервера, попробуй ещё раз."
|
||||
print(f"⚠️ Gateway {resp.status_code}: {resp.text}")
|
||||
play_error_sound()
|
||||
speak(msg, agent_id)
|
||||
_maybe_speak(msg)
|
||||
return msg
|
||||
|
||||
full_text = ""
|
||||
@@ -99,8 +99,7 @@ def ask_agent_stream(text: str, conv=None, agent_id: str = "cosmo") -> str:
|
||||
last_punct = find_sentence_end(buffer, min_len=120)
|
||||
if last_punct > -1:
|
||||
sentence = clean_for_speech(buffer[:last_punct + 1])
|
||||
if sentence.strip():
|
||||
speak(sentence, agent_id)
|
||||
_maybe_speak(sentence)
|
||||
buffer = buffer[last_punct + 1:].lstrip()
|
||||
|
||||
except (json.JSONDecodeError, KeyError, IndexError):
|
||||
@@ -111,18 +110,15 @@ def ask_agent_stream(text: str, conv=None, agent_id: str = "cosmo") -> str:
|
||||
|
||||
if not full_text:
|
||||
msg = "Не получил ответ, попробуй ещё раз."
|
||||
speak(msg, agent_id)
|
||||
_maybe_speak(msg)
|
||||
return msg
|
||||
|
||||
result = clean_for_speech(full_text)
|
||||
|
||||
if TTS_MODE == "full":
|
||||
if result.strip():
|
||||
speak(result, agent_id)
|
||||
_maybe_speak(result)
|
||||
else:
|
||||
if buffer.strip():
|
||||
tail = clean_for_speech(buffer)
|
||||
if tail:
|
||||
speak(tail, agent_id)
|
||||
_maybe_speak(clean_for_speech(buffer))
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user