From aa04276c9adcac2ecb7bf666ab2d48a0008d4f01 Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Thu, 14 May 2026 10:11:13 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Auto-deploy:=20BotVPS=20atualiza?= =?UTF-8?q?do=20em=2014/05/2026=2010:11:13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai_agent.py | 14 +++++++++----- hermes_wrapper.py | 6 ++++++ llm_providers.py | 25 ++++++++++++++++++++----- scratch/test_key.py | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 hermes_wrapper.py create mode 100644 scratch/test_key.py diff --git a/ai_agent.py b/ai_agent.py index 5b73347..d022c59 100644 --- a/ai_agent.py +++ b/ai_agent.py @@ -31,7 +31,7 @@ async def query_agent_async(prompt: str, override_provider=None, chat_history=No # Identifica o modelo padrão baseado no provedor if provider == "minimax": - current_model = cfg.get("minimax_model") or "abab7-preview" + current_model = cfg.get("minimax_model") or "minimax-2.7" model_desc = f"**{current_model}** via Hermes (MiniMax API)" elif provider == "openrouter": current_model = cfg.get("openrouter_model") or "qwen/qwen-2.5-72b-instruct" @@ -150,12 +150,16 @@ DIRETRIZES: if t_name in all_tools: tool_info = all_tools[t_name] func = tool_info["func"] - print(f"[AGENT] Executando {t_name} com argumento: {arg[:50]}...") - + import inspect + sig = inspect.signature(func) + has_params = len(sig.parameters) > 0 + + print(f"[AGENT] Executando {t_name}{f' com argumento: {arg[:50]}' if arg and has_params else ''}...") + if asyncio.iscoroutinefunction(func): - obs = await func(arg) if arg else await func() + obs = await func(arg) if (arg and has_params) else await func() else: - obs = func(arg) if arg else func() + obs = func(arg) if (arg and has_params) else func() if isinstance(obs, dict): obs = obs.get("output") or obs.get("message") or str(obs) diff --git a/hermes_wrapper.py b/hermes_wrapper.py new file mode 100644 index 0000000..b6f8175 --- /dev/null +++ b/hermes_wrapper.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +import sys +sys.path.insert(0, "/host_root/usr/local/lib/hermes-agent") +sys.argv = ["/usr/local/bin/hermes", "-z"] + sys.argv[1:] +from hermes_cli.main import main +main() diff --git a/llm_providers.py b/llm_providers.py index 12ac8fd..7c3a83d 100644 --- a/llm_providers.py +++ b/llm_providers.py @@ -5,8 +5,12 @@ import asyncio import time from typing import Optional, Dict, List from collections import deque +from dotenv import load_dotenv from config import get_config, save_config +# Carrega variáveis do .env caso não tenham sido carregadas +load_dotenv() + # Monitor de requisições (Rate Limiting Monitoring) REQUEST_HISTORY = deque() ALERT_THRESHOLD = 20 @@ -91,8 +95,8 @@ LLM_PROVIDERS = { "minimax": { "name": "MiniMax (Hermes)", "type": "api", - "models": ["abab7-preview", "abab6.5s-chat", "minimax-text-01"], - "default": "abab7-preview", + "models": ["minimax-2.7", "abab6.5s-chat", "minimax-text-01"], + "default": "minimax-2.7", "endpoint": "https://api.minimax.io/v1/text/chatcompletion_v2" }, "ollama": { @@ -293,7 +297,7 @@ async def _call_openrouter_async(model: str, prompt: str, system_prompt: str = N res = await client.post(url, json=payload, headers=headers, timeout=120) if res.status_code == 200: data = res.json() - if "choices" in data and len(data["choices"]) > 0: + if data.get("choices") and len(data["choices"]) > 0: return { "content": data["choices"][0]["message"]["content"], "usage": data.get("usage", {}), @@ -352,6 +356,12 @@ async def _call_gemini_async(model: str, prompt: str, system_prompt: str = None) async def _call_minimax_async(model: str, prompt: str, system_prompt: str = None) -> dict: """Chama API do MiniMax (V2) via httpx (async).""" api_key = get_api_key("minimax") + if api_key: + api_key = api_key.strip() + + if not api_key: + return {"content": "Erro: API Key do MiniMax não encontrada ou vazia no .env.", "usage": {}} + url = "https://api.minimax.io/v1/text/chatcompletion_v2" messages = [] @@ -377,13 +387,18 @@ async def _call_minimax_async(model: str, prompt: str, system_prompt: str = None if res.status_code == 200: data = res.json() # MiniMax V2 structure - if "choices" in data and len(data["choices"]) > 0: + if data.get("choices") and len(data["choices"]) > 0: return { "content": data["choices"][0]["message"]["content"], "usage": data.get("usage", {}), "model": data.get("base_resp", {}).get("model") or model } - return {"content": f"Erro MiniMax (Resposta inesperada): {json.dumps(data)}", "usage": {}} + base_resp = data.get("base_resp", {}) + status_code = base_resp.get("status_code") + status_msg = base_resp.get("status_msg", "Unknown") + if status_code == 2013: + return {"content": f"Modelo indefinido/no MiniMax: {model}. API disse: {status_msg}", "usage": {}} + return {"content": f"Erro MiniMax: [{status_code}] {status_msg} | Raw: {json.dumps(data)}", "usage": {}} return {"content": f"Erro MiniMax {res.status_code}: {res.text}", "usage": {}} except Exception as e: return {"content": f"Erro MiniMax: {str(e)}", "usage": {}} diff --git a/scratch/test_key.py b/scratch/test_key.py new file mode 100644 index 0000000..bd56cea --- /dev/null +++ b/scratch/test_key.py @@ -0,0 +1,18 @@ +import os +from dotenv import load_dotenv +import sys + +# Add current dir to path to import local modules +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from llm_providers import get_api_key + +load_dotenv() +key = get_api_key("minimax") +print(f"MINIMAX_API_KEY found: {bool(key)}") +if key: + print(f"Key starts with: {key[:4]}...") +else: + print("Key is empty!") + +print(f"Direct os.getenv('MINIMAX_API_KEY'): {bool(os.getenv('MINIMAX_API_KEY'))}")