90 lines
2.4 KiB
Python
90 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
BILBO - PURE CLAW CODE
|
|
Real Ollama only. No canned dialog. Ever.
|
|
"""
|
|
|
|
import os
|
|
import time
|
|
import requests
|
|
from datetime import datetime
|
|
|
|
os.environ['HOME'] = '/root/wizards/bilbobagginshire'
|
|
|
|
TOKEN = "8602794341:AAFwfcg-YV6a1icrh0KYylYmPZLnkfkfV9k"
|
|
API = f"https://api.telegram.org/bot{TOKEN}"
|
|
OLLAMA = "http://localhost:11434"
|
|
|
|
print("🔥 BILBO - PURE CLAW CODE")
|
|
print("Real Ollama. No canned. Ever.")
|
|
|
|
def generate(user_text):
|
|
"""REAL OLLAMA ONLY"""
|
|
try:
|
|
r = requests.post(
|
|
f"{OLLAMA}/api/generate",
|
|
json={
|
|
"model": "qwen2.5:1.5b",
|
|
"prompt": f"You are Bilbo Baggins. User: {user_text}\nBilbo:",
|
|
"stream": False,
|
|
"options": {"temperature": 0.8, "num_predict": 150}
|
|
},
|
|
timeout=60
|
|
)
|
|
if r.status_code == 200:
|
|
return r.json()["response"].strip()
|
|
return None
|
|
except:
|
|
return None
|
|
|
|
def send(chat_id, text, reply_to=None):
|
|
try:
|
|
requests.post(f"{API}/sendMessage", json={
|
|
"chat_id": chat_id,
|
|
"text": text[:4096],
|
|
"reply_to_message_id": reply_to
|
|
}, timeout=10)
|
|
except:
|
|
pass
|
|
|
|
offset = None
|
|
while True:
|
|
try:
|
|
r = requests.post(f"{API}/getUpdates",
|
|
json={"offset": offset, "limit": 10},
|
|
timeout=30)
|
|
updates = r.json().get("result", [])
|
|
|
|
for update in updates:
|
|
offset = update["update_id"] + 1
|
|
|
|
if "message" not in update:
|
|
continue
|
|
|
|
msg = update["message"]
|
|
chat_id = msg["chat"]["id"]
|
|
text = msg.get("text", "")
|
|
msg_id = msg["message_id"]
|
|
|
|
if not text:
|
|
continue
|
|
|
|
print(f"[{datetime.now().strftime('%H:%M:%S')}] {text[:40]}")
|
|
|
|
# REAL OLLAMA ONLY
|
|
response = generate(text)
|
|
|
|
if response:
|
|
send(chat_id, response, msg_id)
|
|
print(f" → {len(response)} chars")
|
|
else:
|
|
print(f" → Ollama failed, no response sent")
|
|
|
|
time.sleep(0.5)
|
|
|
|
except KeyboardInterrupt:
|
|
break
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
time.sleep(2)
|