Inverting model hierarchy: Ling primary, Qwen fallback and fixing VPSFileCleaner UI
This commit is contained in:
26
ai_agent.py
26
ai_agent.py
@@ -87,20 +87,32 @@ DIRETRIZES:
|
||||
try:
|
||||
res_dict = await call_llm(provider, current_model, system_prompt + current_history)
|
||||
|
||||
# Lógica de FALLBACK: Se o Ling falhar (especialmente por ser free/busy), tenta o Qwen 2.5-72B
|
||||
# Lógica de FALLBACK: Se o Ling falhar, tenta o Qwen
|
||||
if (res_dict.get("content", "").startswith("Erro OpenRouter") or "error" in res_dict.get("content", "").lower()) and provider == "openrouter":
|
||||
backup_model = "qwen/qwen-2.5-72b-instruct"
|
||||
print(f"⚠️ [FALLBACK CHAT] Falha no Ling. Tentando {backup_model}...")
|
||||
print(f"⚠️ [FALLBACK] Falha no Ling. Tentando {backup_model}...")
|
||||
res_dict = await call_llm("openrouter", backup_model, system_prompt + current_history)
|
||||
|
||||
except Exception as e:
|
||||
if provider == "openrouter":
|
||||
# Lógica de EMERGÊNCIA: Se houver exceção no Ling, tenta o Qwen
|
||||
print(f"⚠️ [EMERGENCY FALLBACK] Exceção no Ling ({str(e)}). Tentando {backup_model}...")
|
||||
try:
|
||||
backup_model = "qwen/qwen-2.5-72b-instruct"
|
||||
print(f"⚠️ [FALLBACK CHAT] Exceção no Ling ({str(e)}). Tentando {backup_model}...")
|
||||
res_dict = await call_llm("openrouter", backup_model, system_prompt + current_history)
|
||||
else:
|
||||
return f"Erro Crítico no Agente: {str(e)}"
|
||||
except:
|
||||
return f"RESUMO: ❌ Desculpe, os modelos Ling e Qwen estão instáveis no OpenRouter no momento. Por favor, tente novamente em instantes."
|
||||
|
||||
response = res_dict["content"]
|
||||
response = res_dict.get("content", "Erro: Resposta vazia.")
|
||||
|
||||
# Limpeza de segurança: Se a resposta for um erro técnico persistente
|
||||
if response.startswith("Erro OpenRouter"):
|
||||
return f"RESUMO: ⚠️ Instabilidade no OpenRouter (Ling/Qwen):\n`{response[:200]}...`\n\nPor favor, tente reenviar sua mensagem."
|
||||
|
||||
# Limpeza de segurança: Se a resposta for um erro técnico persistente
|
||||
if response.startswith("Erro OpenRouter"):
|
||||
return f"RESUMO: ⚠️ Instabilidade no OpenRouter (Ling/Qwen):\n`{response[:200]}...`\n\nPor favor, tente reenviar sua mensagem."
|
||||
|
||||
usage = res_dict.get("usage", {})
|
||||
usage = res_dict.get("usage", {})
|
||||
total_in += usage.get("prompt_tokens", 0)
|
||||
total_out += usage.get("completion_tokens", 0)
|
||||
|
||||
@@ -157,9 +157,13 @@ async def handle_voice(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if audio_url:
|
||||
filename = audio_url.split("/")[-1]
|
||||
audio_path = os.path.join("/tmp", filename)
|
||||
logger.info(f"Tentando enviar voz: {audio_path}")
|
||||
if os.path.exists(audio_path):
|
||||
with open(audio_path, "rb") as audio_file:
|
||||
await context.bot.send_voice(chat_id=chat_id, voice=audio_file)
|
||||
logger.info(f"Voz enviada com sucesso: {audio_path}")
|
||||
else:
|
||||
logger.error(f"Arquivo de áudio não encontrado: {audio_path}")
|
||||
|
||||
if chat_id not in chat_histories: chat_histories[chat_id] = []
|
||||
chat_histories[chat_id].append({"user": user_text, "bot": bot_reply})
|
||||
|
||||
Reference in New Issue
Block a user