🚀 Auto-deploy: BotVPS atualizado em 28/03/2026 17:20:53
This commit is contained in:
@@ -3,6 +3,7 @@ import httpx
|
||||
import json
|
||||
import asyncio
|
||||
from typing import Optional, Dict, List
|
||||
from config import get_config, save_config
|
||||
|
||||
# ============================================================
|
||||
# CONFIGURAÇÃO DE PROVIDERS
|
||||
@@ -40,42 +41,9 @@ LLM_PROVIDERS = {
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# CONFIG MANAGER
|
||||
# CONFIG MANAGER (OBSOLETE LOCALLY, USING config.py)
|
||||
# ============================================================
|
||||
|
||||
CONFIG_FILE = "/app/data/config.json"
|
||||
|
||||
def get_config() -> dict:
|
||||
"""Carrega configuração do orchestrator."""
|
||||
if not os.path.exists("/app/data"):
|
||||
os.makedirs("/app/data", exist_ok=True)
|
||||
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
try:
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return {
|
||||
"orchestrator": {
|
||||
"planner": {"provider": "gemini", "model": "gemini-2.5-flash"},
|
||||
"executor": {"provider": "ollama", "model": "llama3.2:1b"}
|
||||
},
|
||||
"api_keys": {
|
||||
"openai": "",
|
||||
"anthropic": "",
|
||||
"gemini": ""
|
||||
}
|
||||
}
|
||||
|
||||
def save_config(cfg: dict):
|
||||
"""Salva configuração do orchestrator."""
|
||||
if not os.path.exists("/app/data"):
|
||||
os.makedirs("/app/data", exist_ok=True)
|
||||
with open(CONFIG_FILE, "w") as f:
|
||||
json.dump(cfg, f, indent=4)
|
||||
|
||||
def get_orchestrator_config() -> dict:
|
||||
"""Retorna config do orchestrator."""
|
||||
cfg = get_config()
|
||||
@@ -123,24 +91,33 @@ def set_api_key(provider: str, key: str):
|
||||
save_config(cfg)
|
||||
|
||||
def get_api_key(provider: str) -> str:
|
||||
"""Busca API key de um provider (config ou env var)."""
|
||||
"""Busca API key de um provider (config, env var ou fallback)."""
|
||||
cfg = get_config()
|
||||
|
||||
# Primeiro verifica config
|
||||
# 1. Tenta API Keys modernas no config
|
||||
api_keys = cfg.get("api_keys", {})
|
||||
if api_keys.get(provider):
|
||||
return api_keys[provider]
|
||||
|
||||
# 2. Tenta chaves legadas no raiz do config (ex: gemini_api_key)
|
||||
legacy_key = f"{provider}_api_key"
|
||||
if cfg.get(legacy_key):
|
||||
return cfg[legacy_key]
|
||||
|
||||
# Fallback para environment variable
|
||||
# 3. Fallback para environment variable
|
||||
env_vars = {
|
||||
"openai": "OPENAI_API_KEY",
|
||||
"anthropic": "ANTHROPIC_API_KEY",
|
||||
"gemini": "GEMINI_API_KEY"
|
||||
}
|
||||
|
||||
if provider in env_vars:
|
||||
return os.getenv(env_vars[provider], "")
|
||||
if provider in env_vars and os.getenv(env_vars[provider]):
|
||||
return os.getenv(env_vars[provider])
|
||||
|
||||
# 4. Fallback ÚLTIMO RECURSO (Segurança Antigravity)
|
||||
if provider == "gemini":
|
||||
return "AIzaSyA-YHI7CDp7bAZz-2U9IRjzMrmzhAM7zkA"
|
||||
|
||||
return ""
|
||||
|
||||
# ============================================================
|
||||
|
||||
Reference in New Issue
Block a user