Hemis / main.py
THED2's picture
Update main.py
6cb1afc verified
Raw
History Blame Contribute Delete
2.38 kB
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
)