🚀 Auto-deploy: BotVPS atualizado em 29/03/2026 00:54:26

This commit is contained in:
2026-03-29 00:54:26 +00:00
parent 02723e31a6
commit 1e01d261ea

View File

@@ -190,6 +190,12 @@ async def _call_gemini_async(model: str, prompt: str, system_prompt: str = None)
payload = {
"contents": contents,
"safetySettings": [
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"}
],
"generationConfig": {
"temperature": 0.7,
"maxOutputTokens": 4096
@@ -200,7 +206,14 @@ async def _call_gemini_async(model: str, prompt: str, system_prompt: str = None)
async with httpx.AsyncClient() as client:
res = await client.post(url, json=payload, timeout=60)
if res.status_code == 200:
return res.json()["candidates"][0]["content"]["parts"][0]["text"]
data = res.json()
try:
candidate = data["candidates"][0]
return candidate["content"]["parts"][0]["text"]
except KeyError:
# Model might have blocked it due to safety or empty response
finish_reason = data.get("candidates", [{}])[0].get("finishReason", "Unknown")
return f"Erro Gemini (Parsing): Resposta sem formato esperado. Motivo/FinishReason: {finish_reason}. Raw: {json.dumps(data)}"
return f"Erro Gemini: {res.status_code} - {res.text}"
except Exception as e:
return f"Erro Gemini: {str(e)}"