ilang-ai commited on
Commit ·
488fe74
1
Parent(s): 39fe1a0
fix: pin google-generativeai==0.8.4 + startup AI test
Browse filesLatest version is deprecated/broken, causing empty responses.
Pin to known working version. Add startup test to verify
Gemini API connection on boot.
- bot.py +18 -0
- requirements.txt +1 -1
bot.py
CHANGED
|
@@ -461,6 +461,24 @@ def main():
|
|
| 461 |
asyncio.set_event_loop(loop)
|
| 462 |
loop.run_until_complete(init_db())
|
| 463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
logger.info("I-Lang Guard starting...")
|
| 465 |
app.run_polling(
|
| 466 |
drop_pending_updates=True,
|
|
|
|
| 461 |
asyncio.set_event_loop(loop)
|
| 462 |
loop.run_until_complete(init_db())
|
| 463 |
|
| 464 |
+
# Startup test: verify Gemini API works
|
| 465 |
+
async def _test_ai():
|
| 466 |
+
try:
|
| 467 |
+
from modules.chat import model, _safe_text
|
| 468 |
+
r = await model.generate_content_async("Say hello in one word. JSON: {\"intent\":\"chat\",\"reply\":\"your word\"}")
|
| 469 |
+
text = _safe_text(r)
|
| 470 |
+
if text:
|
| 471 |
+
logger.info("AI startup test OK: " + text[:100])
|
| 472 |
+
else:
|
| 473 |
+
logger.error("AI startup test FAILED: empty response")
|
| 474 |
+
if hasattr(r, 'prompt_feedback'):
|
| 475 |
+
logger.error("Feedback: " + str(r.prompt_feedback))
|
| 476 |
+
if hasattr(r, 'candidates') and r.candidates:
|
| 477 |
+
logger.error("Candidates: " + str(r.candidates))
|
| 478 |
+
except Exception as e:
|
| 479 |
+
logger.error("AI startup test EXCEPTION: " + str(e))
|
| 480 |
+
loop.run_until_complete(_test_ai())
|
| 481 |
+
|
| 482 |
logger.info("I-Lang Guard starting...")
|
| 483 |
app.run_polling(
|
| 484 |
drop_pending_updates=True,
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
python-telegram-bot[job-queue]>=21.0
|
| 2 |
-
google-generativeai
|
| 3 |
aiosqlite>=0.20.0
|
|
|
|
| 1 |
python-telegram-bot[job-queue]>=21.0
|
| 2 |
+
google-generativeai==0.8.4
|
| 3 |
aiosqlite>=0.20.0
|