source/main.py aktualisiert
This commit is contained in:
@@ -9,6 +9,7 @@ import re
|
|||||||
import httpx
|
import httpx
|
||||||
import struct
|
import struct
|
||||||
import termios
|
import termios
|
||||||
|
from pathlib import Path
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
|
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
|
||||||
from telegram.error import InvalidToken
|
from telegram.error import InvalidToken
|
||||||
@@ -21,19 +22,40 @@ from fastapi.templating import Jinja2Templates
|
|||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from dotenv import load_dotenv, set_key
|
from dotenv import load_dotenv, set_key
|
||||||
|
|
||||||
# Lade Umgebungsvariablen
|
# Basis-Verzeichnis (source/)
|
||||||
load_dotenv()
|
BASE_DIR = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
# Pfade zu den neuen Ordnern (eins hoch, dann in den Zielordner)
|
||||||
|
ROOT_DIR = BASE_DIR.parent
|
||||||
|
CONFIG_DIR = ROOT_DIR / "config"
|
||||||
|
DATA_DIR = ROOT_DIR / "data"
|
||||||
|
WORKSPACE_DIR = ROOT_DIR / "workspace"
|
||||||
|
|
||||||
|
# Konfigurationsdateien
|
||||||
|
ENV_FILE = CONFIG_DIR / ".env"
|
||||||
|
load_dotenv(ENV_FILE)
|
||||||
|
DB_PATH = DATA_DIR / "cluster.db"
|
||||||
|
PROMPT_FILE = CONFIG_DIR / "system_prompt.txt"
|
||||||
|
|
||||||
|
# Workspace Dateien
|
||||||
|
NOTES_FILE = WORKSPACE_DIR / "NOTIZEN.md"
|
||||||
|
TODO_FILE = WORKSPACE_DIR / "TODO.md"
|
||||||
|
|
||||||
|
# Sicherstellen, dass die Workspace-Dateien existieren
|
||||||
|
WORKSPACE_DIR.mkdir(exist_ok=True)
|
||||||
|
for f in [NOTES_FILE, TODO_FILE]:
|
||||||
|
if not f.exists():
|
||||||
|
f.write_text(f"# {f.name}\nHier fängt dein Gedächtnis an, J.A.R.V.I.S.\n", encoding="utf-8")
|
||||||
|
|
||||||
|
# FastAPI Pfade (relativ zu main.py in source/)
|
||||||
|
templates = Jinja2Templates(directory=BASE_DIR / "templates")
|
||||||
|
app.mount("/static", StaticFiles(directory=BASE_DIR / "static"), name="static")
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
static_path = os.path.join(os.path.dirname(__file__), "static")
|
#static_path = os.path.join(os.path.dirname(__file__), "static")
|
||||||
app.mount("/static", StaticFiles(directory=static_path), name="static")
|
|
||||||
templates = Jinja2Templates(directory="templates")
|
|
||||||
|
|
||||||
SSH_KEY = os.path.expanduser("~/.ssh/id_rsa")
|
SSH_KEY = os.path.expanduser("~/.ssh/id_rsa")
|
||||||
DB_PATH = "cluster.db"
|
|
||||||
chat_history = []
|
chat_history = []
|
||||||
PROMPT_FILE = "system_prompt.txt"
|
|
||||||
ENV_FILE = os.path.join(os.path.dirname(__file__), ".env")
|
|
||||||
|
|
||||||
# KI KONFIGURATION
|
# KI KONFIGURATION
|
||||||
AI_PROVIDER = os.getenv("AI_PROVIDER", "google").lower()
|
AI_PROVIDER = os.getenv("AI_PROVIDER", "google").lower()
|
||||||
@@ -89,14 +111,25 @@ def get_system_prompt():
|
|||||||
docker_str = "Ja" if n['docker_installed'] else "Nein"
|
docker_str = "Ja" if n['docker_installed'] else "Nein"
|
||||||
node_info += f"- Name: {n['name']}, IP: {n['ip']}, User: {n['user']}, OS: {n['os']}, Arch: {n['arch']}, Docker: {docker_str}\n"
|
node_info += f"- Name: {n['name']}, IP: {n['ip']}, User: {n['user']}, OS: {n['os']}, Arch: {n['arch']}, Docker: {docker_str}\n"
|
||||||
|
|
||||||
if os.path.exists(PROMPT_FILE):
|
workspace_context = f"""
|
||||||
with open(PROMPT_FILE, "r", encoding="utf-8") as f:
|
### DEIN WORKSPACE (LOKALER SERVER)
|
||||||
template = f.read()
|
Du hast Zugriff auf ein eigenes Arbeitsverzeichnis für Notizen und Aufgaben:
|
||||||
else:
|
- Pfad: {WORKSPACE_DIR}
|
||||||
template = "Du bist ein Cluster-Orchestrator. Nodes:\n{node_info}\nBefehle via <EXECUTE target=\"IP\">cmd</EXECUTE>"
|
- Notizen: {NOTES_FILE}
|
||||||
print(f"⚠️ Warnung: {PROMPT_FILE} fehlt.")
|
- Aufgaben: {TODO_FILE}
|
||||||
|
|
||||||
return template.replace("{node_info}", node_info)
|
Du kannst diese Dateien jederzeit lesen oder beschreiben, um dir Dinge für Tony zu merken.
|
||||||
|
Nutze dazu: <EXECUTE target="localhost">Befehl</EXECUTE>
|
||||||
|
"""
|
||||||
|
# Hier liest du die system_prompt.txt aus config/
|
||||||
|
if PROMPT_FILE.exists():
|
||||||
|
template = PROMPT_FILE.read_text(encoding="utf-8")
|
||||||
|
else:
|
||||||
|
template = "Du bist J.A.R.V.I.S... {workspace_context}\nNodes: {node_info}"
|
||||||
|
|
||||||
|
prompt = template.replace("{node_info}", node_info)
|
||||||
|
prompt = prompt.replace("{workspace_context}", workspace_context)
|
||||||
|
return prompt
|
||||||
|
|
||||||
# --- KI FUNKTIONEN ---
|
# --- KI FUNKTIONEN ---
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user