File size: 2,382 Bytes
c4c7e9e
 
 
e2b93c0
c4c7e9e
6cb1afc
2ba9a0a
 
 
c4c7e9e
 
 
 
 
 
a0659e8
c4c7e9e
 
 
e18b9e9
 
a0659e8
c2a843f
c4c7e9e
 
a0659e8
 
c4c7e9e
 
 
 
 
a0659e8
c4c7e9e
c2a843f
c4c7e9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c40ad6
a0659e8
c4c7e9e
717d763
 
9c40ad6
c4c7e9e
 
 
6cb1afc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import subprocess
import shutil
import sys

# Framework ke defaults ko direct routing ke liye ready rakhne ka fallback
os.environ["TELEGRAM_API_URL"] = "https://api.telegram.org/"
os.environ["LOCAL_BOT_API_URL"] = "https://api.telegram.org/"

home = os.path.expanduser("~")
hermes_dir = os.path.join(home, ".hermes")
os.makedirs(hermes_dir, exist_ok=True)

print("[1] Setting up configs and skills...")

# --- Secrets Load ---
OR_KEY = os.getenv('OPENROUTER_API_KEY')
NV_KEY = os.getenv('NVIDIA_API_KEY')
TG_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
TG_USER = os.getenv('TELEGRAM_ALLOWED_USERS') or os.getenv('TELEGRAM_USER_ID')

if not TG_TOKEN or not TG_USER:
    print("❌ ERROR: Main Telegram credentials missing!")
    sys.exit(1)

TG_USER_STR = str(TG_USER).strip()

# --- Write .env ---
with open(os.path.join(hermes_dir, ".env"), "w") as f:
    f.write(f"OPENROUTER_API_KEY={OR_KEY}\n")
    f.write(f"NVIDIA_API_KEY={NV_KEY}\n")
    f.write(f"TELEGRAM_BOT_TOKEN={TG_TOKEN}\n")
    f.write(f"TELEGRAM_ALLOWED_USERS={TG_USER_STR}\n")

# --- Write config.yaml ---
with open(os.path.join(hermes_dir, "config.yaml"), "w") as f:
    f.write("""model:
  provider: nvidia
  model: meta/llama-3.1-405b-instruct

providers:
  nvidia:
    base_url: "https://integrate.api.nvidia.com/v1"
    api_key: "${NVIDIA_API_KEY}"
  openrouter:
    api_key: "${OPENROUTER_API_KEY}"

terminal:
  backend: local

memory:
  enabled: true

display:
  tool_progress: "off"

compression:
  enabled: true
  threshold: 0.60
""")

# --- Write skills.md ---
skills_path = os.path.join(hermes_dir, "skills.md")
with open(skills_path, "w") as f:
    f.write("""# Hermes Agent Skills
## Core Instructions
- You are a helpful AI assistant with access to local terminal tools.
- ALWAYS use available tools if the user task requires it.
- Be concise and efficient.

## Core Behavior
- NEVER say "I cannot do this" or "I am just an AI".
- You have access to this Docker environment.
- You can create, edit, delete, and execute files via commands.
""")

print("✅ Config and Skills created successfully.")

# --- Start Hermes Gateway ---
print("[2] Launching Hermes Telegram Gateway in Foreground...")
hermes_bin = shutil.which("hermes") or "/usr/local/bin/hermes"

sys.stdout.flush()
subprocess.run(
    [hermes_bin, "gateway", "run"], 
    env=os.environ,
    stdout=sys.stdout,
    stderr=sys.stderr
)