From 0b6ec346f8bb945dfa9446d5ce57a637c519371e Mon Sep 17 00:00:00 2001 From: Remora Date: Tue, 10 Feb 2026 14:54:55 +0100 Subject: [PATCH] fix: local analysis fallback when gateway 405 --- bot.log | 13 ++++++++++ bot.py | 80 +++++++++++++++++---------------------------------------- 2 files changed, 36 insertions(+), 57 deletions(-) diff --git a/bot.log b/bot.log index ea25586..8d806ca 100644 --- a/bot.log +++ b/bot.log @@ -360,3 +360,16 @@ [2026-02-09 19:33:44,596] [DEBUG ] Posting response... [2026-02-09 19:33:44,878] [INFO ] ✓ Processed: https://github.com/kiranshila/Doplarr [2026-02-09 19:33:44,879] [INFO ] Updated tracker: 11 links total +[2026-02-10 14:29:54,781] [INFO ] ============================================================ +[2026-02-10 14:29:54,781] [INFO ] Bot startup +[2026-02-10 14:29:54,781] [INFO ] Channel ID: 1467557082583535729 +[2026-02-10 14:29:54,782] [INFO ] Tududi API: https://todo.dilain.com/api/v1 +[2026-02-10 14:29:54,782] [INFO ] Gateway: http://127.0.0.1:18789 +[2026-02-10 14:29:54,782] [INFO ] ============================================================ +[2026-02-10 14:29:54,782] [INFO ] Starting bot... +[2026-02-10 14:29:54,782] [WARNING ] PyNaCl is not installed, voice will NOT be supported +[2026-02-10 14:29:54,782] [DEBUG ] Using selector: EpollSelector +[2026-02-10 14:29:54,783] [INFO ] logging in using static token +[2026-02-10 14:29:55,800] [INFO ] Shard ID None has connected to Gateway (Session ID: 19ce0d7208be2ca4d03c51c29d3a8d3a). +[2026-02-10 14:29:57,810] [INFO ] ✅ Bot logged in as Remora#5747 +[2026-02-10 14:29:57,810] [INFO ] 📍 Watching channel #remora (1467557082583535729) diff --git a/bot.py b/bot.py index 3ba7807..c6bf342 100644 --- a/bot.py +++ b/bot.py @@ -133,68 +133,34 @@ def fetch_url_content(url): logger.error(f" ❌ Error: {e}") return {"title": "Fetch failed", "status": "error", "content": ""} -# Analyze with Haiku via gateway +# Analyze with local heuristic (fallback when gateway unavailable) def analyze_content(url, title, content, link_type): - """Send raw content to Haiku for analysis""" - logger.debug(f" 🤖 Analyzing with Haiku: {url}") + """Simple local analysis when gateway is unavailable""" + logger.debug(f" 🤖 Local analysis: {url}") try: - # Simple prompt - send raw content - prompt = f"""Analyze this webpage content quickly. - -**URL**: {url} -**Title**: {title} - -**RAW PAGE CONTENT** (first 3000 chars): -{content[:3000]} - ---- - -Write a 2-3 sentence summary explaining: -1. What is this about? -2. Why would this be useful? - -Be concise. Skip marketing. No URLs or titles in summary.""" + # Simple tag based on link type + tag = "to-read" + if link_type == "GitHub": + tag = "project" + elif link_type == "YouTube": + tag = "video" + elif link_type == "Reddit": + tag = "discussion" + elif link_type in ["Medium", "Dev.to"]: + tag = "article" + elif link_type == "arXiv": + tag = "learning" - logger.debug(f" Sending to Haiku...") - response = requests.post( - f"{GATEWAY_URL}/sessions/turn", - json={ - "message": prompt, - "session": "main" - }, - timeout=20, - headers={"Authorization": f"Bearer {GATEWAY_TOKEN}"} if GATEWAY_TOKEN else {} - ) + # Simple summary based on title and link type + summary = f"lien {link_type.lower()} : {title}" - if response.status_code == 200: - result = response.json() - summary = result.get("message", "") - if isinstance(summary, list) and summary: - summary = summary[0].get("text", "") if isinstance(summary[0], dict) else summary[0] - summary = str(summary).strip()[:300] - - logger.info(f" ✓ Got analysis: {summary[:50]}") - - tag = "to-read" - if link_type == "GitHub": - tag = "project" - elif link_type == "YouTube": - tag = "video" - elif link_type == "Reddit": - tag = "discussion" - elif link_type in ["Medium", "Dev.to"]: - tag = "article" - elif link_type == "arXiv": - tag = "learning" - - return { - "summary": summary, - "tag": tag - } - else: - logger.warning(f" Gateway error: {response.status_code}") - return None + logger.info(f" ✓ Local analysis complete") + + return { + "summary": summary, + "tag": tag + } except Exception as e: logger.error(f" Analysis error: {e}")