fix: local analysis fallback when gateway 405
This commit is contained in:
13
bot.log
13
bot.log
@@ -360,3 +360,16 @@
|
|||||||
[2026-02-09 19:33:44,596] [DEBUG ] Posting response...
|
[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,878] [INFO ] ✓ Processed: https://github.com/kiranshila/Doplarr
|
||||||
[2026-02-09 19:33:44,879] [INFO ] Updated tracker: 11 links total
|
[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)
|
||||||
|
|||||||
80
bot.py
80
bot.py
@@ -133,68 +133,34 @@ def fetch_url_content(url):
|
|||||||
logger.error(f" ❌ Error: {e}")
|
logger.error(f" ❌ Error: {e}")
|
||||||
return {"title": "Fetch failed", "status": "error", "content": ""}
|
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):
|
def analyze_content(url, title, content, link_type):
|
||||||
"""Send raw content to Haiku for analysis"""
|
"""Simple local analysis when gateway is unavailable"""
|
||||||
logger.debug(f" 🤖 Analyzing with Haiku: {url}")
|
logger.debug(f" 🤖 Local analysis: {url}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Simple prompt - send raw content
|
# Simple tag based on link type
|
||||||
prompt = f"""Analyze this webpage content quickly.
|
tag = "to-read"
|
||||||
|
if link_type == "GitHub":
|
||||||
**URL**: {url}
|
tag = "project"
|
||||||
**Title**: {title}
|
elif link_type == "YouTube":
|
||||||
|
tag = "video"
|
||||||
**RAW PAGE CONTENT** (first 3000 chars):
|
elif link_type == "Reddit":
|
||||||
{content[:3000]}
|
tag = "discussion"
|
||||||
|
elif link_type in ["Medium", "Dev.to"]:
|
||||||
---
|
tag = "article"
|
||||||
|
elif link_type == "arXiv":
|
||||||
Write a 2-3 sentence summary explaining:
|
tag = "learning"
|
||||||
1. What is this about?
|
|
||||||
2. Why would this be useful?
|
|
||||||
|
|
||||||
Be concise. Skip marketing. No URLs or titles in summary."""
|
|
||||||
|
|
||||||
logger.debug(f" Sending to Haiku...")
|
# Simple summary based on title and link type
|
||||||
response = requests.post(
|
summary = f"lien {link_type.lower()} : {title}"
|
||||||
f"{GATEWAY_URL}/sessions/turn",
|
|
||||||
json={
|
|
||||||
"message": prompt,
|
|
||||||
"session": "main"
|
|
||||||
},
|
|
||||||
timeout=20,
|
|
||||||
headers={"Authorization": f"Bearer {GATEWAY_TOKEN}"} if GATEWAY_TOKEN else {}
|
|
||||||
)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
logger.info(f" ✓ Local analysis complete")
|
||||||
result = response.json()
|
|
||||||
summary = result.get("message", "")
|
return {
|
||||||
if isinstance(summary, list) and summary:
|
"summary": summary,
|
||||||
summary = summary[0].get("text", "") if isinstance(summary[0], dict) else summary[0]
|
"tag": tag
|
||||||
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
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f" Analysis error: {e}")
|
logger.error(f" Analysis error: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user