Spaces:
Runtime error
Runtime error
Update server.py
Browse files
server.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import os, json, urllib.request, subprocess,
|
| 2 |
from http.server import BaseHTTPRequestHandler, HTTPServer
|
| 3 |
|
| 4 |
PORT = 7860
|
|
@@ -11,7 +11,6 @@ def log(msg):
|
|
| 11 |
sys.stdout.flush()
|
| 12 |
|
| 13 |
def send_tg(chat_id, text):
|
| 14 |
-
"""Отправка в Telegram через твой Cloudflare-мост"""
|
| 15 |
if not CF_URL or not TOKEN: return
|
| 16 |
url = f"{CF_URL}/bot{TOKEN}/sendMessage"
|
| 17 |
data = json.dumps({"chat_id": chat_id, "text": str(text)}).encode('utf-8')
|
|
@@ -36,40 +35,43 @@ class WebhookHandler(BaseHTTPRequestHandler):
|
|
| 36 |
send_tg(chat_id, "⛔ Доступ закрыт.")
|
| 37 |
return
|
| 38 |
|
| 39 |
-
|
| 40 |
-
send_tg(chat_id, "🚀 Запускаю DeepSeek-v4-Pro...")
|
| 41 |
|
| 42 |
try:
|
| 43 |
my_env = os.environ.copy()
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
|
|
|
|
| 47 |
|
|
|
|
| 48 |
if api_base:
|
| 49 |
if not api_base.endswith("/v1"):
|
| 50 |
api_base += "/v1"
|
| 51 |
my_env["OPENAI_API_BASE"] = api_base
|
| 52 |
my_env["OPENAI_BASE_URL"] = api_base
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
|
| 58 |
result = subprocess.run(cmd, capture_output=True, text=True, env=my_env)
|
| 59 |
|
| 60 |
reply = result.stdout.strip()
|
| 61 |
err_reply = result.stderr.strip()
|
| 62 |
|
| 63 |
-
if not reply:
|
| 64 |
-
reply = err_reply
|
| 65 |
-
|
| 66 |
if reply:
|
| 67 |
send_tg(chat_id, reply[-4000:])
|
|
|
|
|
|
|
|
|
|
| 68 |
else:
|
| 69 |
-
send_tg(chat_id, "✅
|
| 70 |
|
| 71 |
except Exception as e:
|
| 72 |
-
send_tg(chat_id, f"❌
|
| 73 |
|
| 74 |
def do_GET(self):
|
| 75 |
self.send_response(200)
|
|
@@ -77,6 +79,6 @@ class WebhookHandler(BaseHTTPRequestHandler):
|
|
| 77 |
self.wfile.write(b"Server Online")
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
| 80 |
-
log(f"🚀 Starting Hermes
|
| 81 |
HTTPServer(('0.0.0.0', PORT), WebhookHandler).serve_forever()
|
| 82 |
|
|
|
|
| 1 |
+
import os, json, urllib.request, subprocess, sys
|
| 2 |
from http.server import BaseHTTPRequestHandler, HTTPServer
|
| 3 |
|
| 4 |
PORT = 7860
|
|
|
|
| 11 |
sys.stdout.flush()
|
| 12 |
|
| 13 |
def send_tg(chat_id, text):
|
|
|
|
| 14 |
if not CF_URL or not TOKEN: return
|
| 15 |
url = f"{CF_URL}/bot{TOKEN}/sendMessage"
|
| 16 |
data = json.dumps({"chat_id": chat_id, "text": str(text)}).encode('utf-8')
|
|
|
|
| 35 |
send_tg(chat_id, "⛔ Доступ закрыт.")
|
| 36 |
return
|
| 37 |
|
| 38 |
+
send_tg(chat_id, "🎻 Дирижер Гермес выходит на сцену (Kimi-k2.6)...")
|
|
|
|
| 39 |
|
| 40 |
try:
|
| 41 |
my_env = os.environ.copy()
|
| 42 |
|
| 43 |
+
# 🔥 ЖЕСТКОЕ НАЗНАЧЕНИЕ КЛЮЧЕЙ ДЛЯ ГЕРМЕСА
|
| 44 |
+
api_key = my_env.get("OPENAI_API_KEY", my_env.get("NVIDIA_API_KEY", "")).strip()
|
| 45 |
+
my_env["OPENAI_API_KEY"] = api_key
|
| 46 |
|
| 47 |
+
api_base = my_env.get("OPENAI_API_BASE", my_env.get("NVIDIA_API_BASE", "")).strip().rstrip('/')
|
| 48 |
if api_base:
|
| 49 |
if not api_base.endswith("/v1"):
|
| 50 |
api_base += "/v1"
|
| 51 |
my_env["OPENAI_API_BASE"] = api_base
|
| 52 |
my_env["OPENAI_BASE_URL"] = api_base
|
| 53 |
|
| 54 |
+
# 🌟 ИСПОЛЬЗУЕМ KIMI ДЛЯ ИДЕАЛЬНОЙ РАБОТЫ С НАВЫКАМИ
|
| 55 |
+
model_name = "moonshotai/kimi-k2.6"
|
| 56 |
+
|
| 57 |
+
cmd = ["hermes", "-m", model_name, "-z", text, "chat", "--cli"]
|
| 58 |
+
log(f"⚙️ Выполняю: {' '.join(cmd)}")
|
| 59 |
|
| 60 |
result = subprocess.run(cmd, capture_output=True, text=True, env=my_env)
|
| 61 |
|
| 62 |
reply = result.stdout.strip()
|
| 63 |
err_reply = result.stderr.strip()
|
| 64 |
|
|
|
|
|
|
|
|
|
|
| 65 |
if reply:
|
| 66 |
send_tg(chat_id, reply[-4000:])
|
| 67 |
+
elif err_reply:
|
| 68 |
+
# Если есть ошибка, отправляем ее целиком, чтобы понять на чем споткнулся
|
| 69 |
+
send_tg(chat_id, f"⚠️ Ответ Гермеса:\n{err_reply[-4000:]}")
|
| 70 |
else:
|
| 71 |
+
send_tg(chat_id, "✅ Гермес отработал успешно, но ничего не вывел в консоль.")
|
| 72 |
|
| 73 |
except Exception as e:
|
| 74 |
+
send_tg(chat_id, f"❌ Ошибка моста: {e}")
|
| 75 |
|
| 76 |
def do_GET(self):
|
| 77 |
self.send_response(200)
|
|
|
|
| 79 |
self.wfile.write(b"Server Online")
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
+
log(f"🚀 Starting Hermes Orchestrator Bridge on port {PORT}")
|
| 83 |
HTTPServer(('0.0.0.0', PORT), WebhookHandler).serve_forever()
|
| 84 |
|