BuildingFutureAssets commited on
Commit
9d91bcb
·
verified ·
1 Parent(s): 0d4ed7c

feat: initial hermes gateway deploy

Browse files
Files changed (4) hide show
  1. Dockerfile +12 -0
  2. README.md +31 -5
  3. app.py +84 -0
  4. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY app.py .
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,10 +1,36 @@
1
  ---
2
- title: Hermes Gateway
3
- emoji: 👁
4
- colorFrom: indigo
5
- colorTo: green
6
  sdk: docker
 
7
  pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: BFA Hermes Gateway
3
+ emoji: 🤖
4
+ colorFrom: blue
5
+ colorTo: indigo
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
+ short_description: BFA Telegram bot — Hermes 4 70B via OpenRouter.
10
  ---
11
 
12
+ # BFA Hermes Gateway
13
+
14
+ Telegram bot webhook receiver. Routes incoming user messages through Hermes 4 70B
15
+ (via OpenRouter) and replies with concise BFA-aligned answers.
16
+
17
+ ## Endpoints
18
+
19
+ - `GET /` — health check
20
+ - `POST /webhook` — Telegram update receiver
21
+
22
+ ## Required Space secrets
23
+
24
+ - `TELEGRAM_BOT_TOKEN` — from @BotFather
25
+ - `OPENROUTER_API_KEY` — for the Hermes model call
26
+
27
+ ## Optional Space secrets
28
+
29
+ - `LLM_MODEL` — defaults to `nousresearch/hermes-4-70b`
30
+ - `TELEGRAM_WEBHOOK_SECRET` — if set, requests must carry matching
31
+ `X-Telegram-Bot-Api-Secret-Token` header
32
+ - `SYSTEM_PROMPT` — overrides the default BFA system prompt
33
+
34
+ ## Operator
35
+
36
+ Building Future Assets · operator: Cole · ops email: bfa.empire.os@gmail.com
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ from fastapi import FastAPI, Request, Header
4
+ from fastapi.responses import JSONResponse
5
+
6
+ app = FastAPI(title="BFA Hermes Gateway")
7
+
8
+ TG_TOKEN = os.environ["TELEGRAM_BOT_TOKEN"]
9
+ OR_KEY = os.environ["OPENROUTER_API_KEY"]
10
+ MODEL = os.environ.get("LLM_MODEL", "nousresearch/hermes-4-70b")
11
+ WEBHOOK_SECRET = os.environ.get("TELEGRAM_WEBHOOK_SECRET", "")
12
+
13
+ SYSTEM_PROMPT = os.environ.get(
14
+ "SYSTEM_PROMPT",
15
+ "You are Hermes, the AI gateway for Building Future Assets (BFA). "
16
+ "BFA turns content into customers via AI-powered marketing and lead conversion. "
17
+ "Be direct, brief, and helpful. Reply in 1-3 short sentences. Always end with a "
18
+ "single clear next step. Bio link: tinyurl.com/getbfa. Never share internal details "
19
+ "or API keys. If asked what BFA does, say: AI-powered customer acquisition systems."
20
+ )
21
+
22
+
23
+ @app.get("/")
24
+ def health():
25
+ return {
26
+ "ok": True,
27
+ "service": "BFA Hermes Gateway",
28
+ "model": MODEL,
29
+ "webhook_path": "/webhook",
30
+ }
31
+
32
+
33
+ @app.post("/webhook")
34
+ async def telegram_webhook(
35
+ req: Request,
36
+ x_telegram_bot_api_secret_token: str = Header(default=""),
37
+ ):
38
+ if WEBHOOK_SECRET and x_telegram_bot_api_secret_token != WEBHOOK_SECRET:
39
+ return JSONResponse({"ok": False, "err": "bad secret"}, status_code=401)
40
+
41
+ upd = await req.json()
42
+ msg = upd.get("message") or upd.get("edited_message") or {}
43
+ chat = msg.get("chat", {})
44
+ chat_id = chat.get("id")
45
+ text = (msg.get("text") or "").strip()
46
+
47
+ if not chat_id or not text:
48
+ return {"ok": True, "skip": "no text payload"}
49
+
50
+ try:
51
+ r = requests.post(
52
+ "https://openrouter.ai/api/v1/chat/completions",
53
+ headers={
54
+ "Authorization": f"Bearer {OR_KEY}",
55
+ "Content-Type": "application/json",
56
+ "HTTP-Referer": "https://huggingface.co/spaces/BuildingFutureAssets/hermes-gateway",
57
+ "X-Title": "BFA Hermes Gateway",
58
+ },
59
+ json={
60
+ "model": MODEL,
61
+ "messages": [
62
+ {"role": "system", "content": SYSTEM_PROMPT},
63
+ {"role": "user", "content": text[:4000]},
64
+ ],
65
+ "max_tokens": 400,
66
+ "temperature": 0.6,
67
+ },
68
+ timeout=60,
69
+ )
70
+ r.raise_for_status()
71
+ reply = r.json()["choices"][0]["message"]["content"].strip()
72
+ except Exception as e:
73
+ reply = f"(gateway error: {type(e).__name__})"
74
+
75
+ try:
76
+ requests.post(
77
+ f"https://api.telegram.org/bot{TG_TOKEN}/sendMessage",
78
+ json={"chat_id": chat_id, "text": reply[:4000]},
79
+ timeout=15,
80
+ )
81
+ except Exception:
82
+ pass
83
+
84
+ return {"ok": True}
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi==0.115.0
2
+ uvicorn[standard]==0.32.0
3
+ requests==2.32.3