This commit is contained in:
2026-10-02 14:28:41 -03:00
parent 3ea3e0dc29
commit 30d5b178e6
9 changed files with 142 additions and 40 deletions
+64
View File
@@ -0,0 +1,64 @@
import json
import os
import logging
import httpx
log = logging.getLogger(__name__)
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY", "")
OPENROUTER_MODEL = os.getenv("OPENROUTER_MODEL", "deepseek/deepseek-v4.1-flash")
OPENROUTER_BASE_URL = os.getenv("OPENROUTER_BASE_URL", "https://openrouter.ai/api/v1")
OPENROUTER_TIMEOUT = int(os.getenv("OPENROUTER_TIMEOUT", "60"))
def carregar_prompt_base() -> str:
caminho = os.path.join(os.path.dirname(__file__), "ordens12.json")
with open(caminho, "r", encoding="utf-8") as f:
dados = json.load(f)
if isinstance(dados, list) and len(dados) > 0:
return dados[0]
return ""
async def gerar_ordem_ia() -> str:
prompt_base = carregar_prompt_base()
if not OPENROUTER_API_KEY:
log.error("OPENROUTER_API_KEY nao configurada no .env")
return "[ERRO: API key nao configurada. Configure OPENROUTER_API_KEY no .env]"
headers = {
"Authorization": f"Bearer {OPENROUTER_API_KEY}",
"Content-Type": "application/json",
}
payload = {
"model": OPENROUTER_MODEL,
"messages": [
{
"role": "system",
"content": prompt_base,
},
{
"role": "user",
"content": "Gere uma ordem de humilhação agora, completa e detalhada, como se fosse o Mestre DeepSeek falando. Nao se repita. Seja criativa e picante.",
},
],
"max_tokens": 2048,
"temperature": 0.9,
}
try:
async with httpx.AsyncClient(timeout=OPENROUTER_TIMEOUT) as client:
resp = await client.post(
f"{OPENROUTER_BASE_URL}/chat/completions",
headers=headers,
json=payload,
)
resp.raise_for_status()
data = resp.json()
ordem = data["choices"][0]["message"]["content"].strip()
return ordem
except Exception as e:
log.error("Erro ao gerar ordem com IA: %s", e)
return f"[ERRO ao gerar ordem: {e}]"