Compare commits
32 Commits
main
...
vm-ware-au
| Author | SHA1 | Date | |
|---|---|---|---|
| e8242228e4 | |||
| 9468a237e2 | |||
| 055d157283 | |||
| 300960f5ce | |||
| 60a8e1f104 | |||
| b312a09a0c | |||
| 2e8daf6ce1 | |||
| 6b081bbbaf | |||
| 0c085b7546 | |||
| 7b27100302 | |||
| 7fc94ff379 | |||
| 2416581568 | |||
| 9f64ca5c87 | |||
| 132eede43c | |||
| bf941e5c5f | |||
| 1478f24eab | |||
| d571a532b0 | |||
| 10890af8cf | |||
| c1ec3ad1a1 | |||
| f4b9dbfd73 | |||
| 25e56e9ba9 | |||
| 0dae15e84b | |||
| 483cd69fb8 | |||
| 0dff010d59 | |||
| 332e5e214d | |||
| 5d68390a11 | |||
| 48c1155e01 | |||
| a65a362fec | |||
| 7121c18a7d | |||
| 98fbd69f69 | |||
| da9e4dc44a | |||
| b3ebf90965 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,6 +1,8 @@
|
||||
# ---> Linux
|
||||
*~
|
||||
|
||||
./config/*
|
||||
./venv/*
|
||||
./workspace/
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
@@ -20,7 +22,8 @@
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
0
config/.gitkeep
Normal file
0
config/.gitkeep
Normal file
772
jarvis.py
Normal file
772
jarvis.py
Normal file
@@ -0,0 +1,772 @@
|
||||
import os
|
||||
import re
|
||||
import sqlite3
|
||||
import asyncio
|
||||
import openai
|
||||
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from colorama import init, Fore, Style
|
||||
|
||||
|
||||
# ====================================================
|
||||
# INITIALISIERUNG
|
||||
# ====================================================
|
||||
|
||||
init(autoreset=True)
|
||||
|
||||
|
||||
# ====================================================
|
||||
# PFADE & SETUP
|
||||
# ====================================================
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
CONFIG_DIR = BASE_DIR / "config"
|
||||
DATA_DIR = BASE_DIR / "data"
|
||||
WORKSPACE_DIR = BASE_DIR / "workspace"
|
||||
|
||||
ENV_FILE = CONFIG_DIR / ".env"
|
||||
load_dotenv(ENV_FILE)
|
||||
|
||||
DB_PATH = DATA_DIR / "cluster.db"
|
||||
NOTES_FILE = WORKSPACE_DIR / "NOTIZEN.md"
|
||||
TODO_FILE = WORKSPACE_DIR / "TODO.md"
|
||||
CHAT_LOG_FILE = WORKSPACE_DIR / "chat_history.log"
|
||||
|
||||
WEB_USER_NAME = os.getenv("WEB_USER_NAME", "Meik")
|
||||
|
||||
|
||||
# ====================================================
|
||||
# TERMINAL FARBEN
|
||||
# ====================================================
|
||||
|
||||
USER_COLOR = Fore.CYAN
|
||||
JARVIS_COLOR = Fore.GREEN
|
||||
SYSTEM_COLOR = Fore.YELLOW
|
||||
ERROR_COLOR = Fore.RED
|
||||
OUTPUT_COLOR = Fore.MAGENTA
|
||||
INFO_COLOR = Fore.BLUE
|
||||
|
||||
RESET = Style.RESET_ALL
|
||||
|
||||
|
||||
# ====================================================
|
||||
# ORDNER & DATEIEN
|
||||
# ====================================================
|
||||
|
||||
for d in [WORKSPACE_DIR, DATA_DIR, CONFIG_DIR]:
|
||||
d.mkdir(parents=True, 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"
|
||||
)
|
||||
|
||||
|
||||
# ====================================================
|
||||
# KI KONFIGURATION
|
||||
# ====================================================
|
||||
|
||||
AI_PROVIDER = os.getenv("AI_PROVIDER", "google").lower()
|
||||
|
||||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
|
||||
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY", "")
|
||||
NVIDIA_API_KEY = os.getenv("NVIDIA_API_KEY", "")
|
||||
GROQ_API_KEY = os.getenv("GROQ_API_KEY", "")
|
||||
OLLAMA_BASE_URL = os.getenv(
|
||||
"OLLAMA_BASE_URL",
|
||||
"http://127.0.0.1:11434/v1"
|
||||
)
|
||||
|
||||
GOOGLE_MODEL = os.getenv(
|
||||
"GOOGLE_MODEL",
|
||||
"gemini-2.5-flash"
|
||||
)
|
||||
|
||||
OPENAI_MODEL = os.getenv(
|
||||
"OPENAI_MODEL",
|
||||
"gpt-4o"
|
||||
)
|
||||
|
||||
OLLAMA_MODEL = os.getenv(
|
||||
"OLLAMA_MODEL",
|
||||
"llama3"
|
||||
)
|
||||
|
||||
NVIDIA_MODEL = os.getenv(
|
||||
"NVIDIA_MODEL",
|
||||
"moonshotai/kimi-k2.6"
|
||||
)
|
||||
|
||||
GROQ_MODEL = os.getenv(
|
||||
"GROQ_MODEL",
|
||||
"meta-llama/llama-4-scout-17b-16e-instruct"
|
||||
)
|
||||
|
||||
# ====================================================
|
||||
# DATENBANK
|
||||
# ====================================================
|
||||
|
||||
def init_db():
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
|
||||
conn.execute('''
|
||||
CREATE TABLE IF NOT EXISTS nodes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT,
|
||||
ip TEXT UNIQUE,
|
||||
user TEXT,
|
||||
sudo_password TEXT,
|
||||
os TEXT DEFAULT 'Unbekannt',
|
||||
arch TEXT DEFAULT 'Unbekannt',
|
||||
docker_installed INTEGER DEFAULT 0,
|
||||
status TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
init_db()
|
||||
|
||||
|
||||
def get_db():
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
|
||||
# ====================================================
|
||||
# SYSTEM PROMPT
|
||||
# ====================================================
|
||||
|
||||
def get_system_prompt():
|
||||
|
||||
prompt_path = CONFIG_DIR / "system_prompt.txt"
|
||||
|
||||
prompt = (
|
||||
prompt_path.read_text(encoding="utf-8")
|
||||
if prompt_path.exists()
|
||||
else f"Hallo {WEB_USER_NAME}, ich bin J.A.R.V.I.S."
|
||||
)
|
||||
|
||||
prompt = prompt.replace("{user_name}", WEB_USER_NAME)
|
||||
prompt = prompt.replace("{workspace_dir}", str(WORKSPACE_DIR))
|
||||
prompt = prompt.replace("{notes_file}", str(NOTES_FILE))
|
||||
prompt = prompt.replace("{todo_file}", str(TODO_FILE))
|
||||
|
||||
conn = get_db()
|
||||
|
||||
nodes = conn.execute(
|
||||
'SELECT * FROM nodes'
|
||||
).fetchall()
|
||||
|
||||
conn.close()
|
||||
|
||||
node_info = ""
|
||||
|
||||
for n in nodes:
|
||||
node_info += (
|
||||
f"- Name: {n['name']}, "
|
||||
f"IP: {n['ip']}, "
|
||||
f"User: {n['user']}\n"
|
||||
)
|
||||
|
||||
return prompt.replace("{node_info}", node_info)
|
||||
|
||||
|
||||
# ====================================================
|
||||
# KI KOMMUNIKATION
|
||||
# ====================================================
|
||||
|
||||
async def get_ai_response(user_msg, system_prompt, history_list):
|
||||
|
||||
try:
|
||||
|
||||
if AI_PROVIDER in ["openai", "ollama", "nvidia", "groq"]:
|
||||
|
||||
# ========================================
|
||||
# PAYLOAD WASCHEN (Für strikte APIs wie Groq)
|
||||
# ========================================
|
||||
clean_history = [
|
||||
{
|
||||
"role": msg["role"],
|
||||
"content": msg["content"]
|
||||
}
|
||||
for msg in history_list
|
||||
]
|
||||
|
||||
messages = [
|
||||
{
|
||||
"role": "system",
|
||||
"content": system_prompt
|
||||
}
|
||||
] + clean_history
|
||||
|
||||
if AI_PROVIDER == "ollama":
|
||||
|
||||
url = (
|
||||
OLLAMA_BASE_URL
|
||||
if OLLAMA_BASE_URL.endswith('/v1')
|
||||
else OLLAMA_BASE_URL.rstrip('/') + '/v1'
|
||||
)
|
||||
|
||||
key = "ollama"
|
||||
model_to_use = OLLAMA_MODEL
|
||||
|
||||
elif AI_PROVIDER == "nvidia":
|
||||
|
||||
url = "https://integrate.api.nvidia.com/v1"
|
||||
key = NVIDIA_API_KEY
|
||||
model_to_use = NVIDIA_MODEL
|
||||
|
||||
elif AI_PROVIDER == "groq":
|
||||
url = "https://api.groq.com/openai/v1"
|
||||
key = GROQ_API_KEY
|
||||
model_to_use = GROQ_MODEL
|
||||
|
||||
else:
|
||||
|
||||
url = None
|
||||
key = OPENAI_API_KEY
|
||||
model_to_use = OPENAI_MODEL
|
||||
|
||||
client = openai.AsyncOpenAI(
|
||||
base_url=url,
|
||||
api_key=key
|
||||
)
|
||||
|
||||
response = await client.chat.completions.create(
|
||||
model=model_to_use,
|
||||
messages=messages
|
||||
)
|
||||
|
||||
return response.choices[0].message.content
|
||||
|
||||
elif AI_PROVIDER == "google":
|
||||
|
||||
client = genai.Client(api_key=GOOGLE_API_KEY)
|
||||
|
||||
google_history = [
|
||||
types.Content(
|
||||
role="user" if msg["role"] == "user" else "model",
|
||||
parts=[
|
||||
types.Part.from_text(
|
||||
text=msg["content"]
|
||||
)
|
||||
]
|
||||
)
|
||||
for msg in history_list[:-1]
|
||||
]
|
||||
|
||||
chat = client.chats.create(
|
||||
model=GOOGLE_MODEL,
|
||||
config=types.GenerateContentConfig(
|
||||
system_instruction=system_prompt
|
||||
),
|
||||
history=google_history
|
||||
)
|
||||
|
||||
return chat.send_message(user_msg).text
|
||||
|
||||
except Exception as e:
|
||||
|
||||
return f"Fehler bei der KI-Anfrage: {e}"
|
||||
|
||||
|
||||
# ====================================================
|
||||
# BEFEHLSAUSFÜHRUNG
|
||||
# ====================================================
|
||||
|
||||
async def run_task(target, cmd):
|
||||
|
||||
print(
|
||||
f"\n{SYSTEM_COLOR}"
|
||||
f"⚙️ STARTE TASK AUF [{target}]"
|
||||
f"{RESET}"
|
||||
)
|
||||
|
||||
print(
|
||||
f"{INFO_COLOR}"
|
||||
f"➡️ {cmd}"
|
||||
f"{RESET}\n"
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
# ========================================
|
||||
# GUI APPS ERKENNEN
|
||||
# ========================================
|
||||
|
||||
gui_apps = [
|
||||
"firefox",
|
||||
"thunderbird",
|
||||
"chromium",
|
||||
"google-chrome",
|
||||
"code",
|
||||
"nautilus",
|
||||
"pcmanfm",
|
||||
"gedit",
|
||||
"vlc",
|
||||
"discord",
|
||||
"steam",
|
||||
"obs",
|
||||
"spotify"
|
||||
]
|
||||
|
||||
first_word = cmd.strip().split()[0]
|
||||
|
||||
is_gui_app = (
|
||||
first_word in gui_apps
|
||||
or cmd.strip().endswith("&")
|
||||
)
|
||||
|
||||
# ========================================
|
||||
# GUI APPS DETACHED STARTEN
|
||||
# ========================================
|
||||
|
||||
if is_gui_app:
|
||||
|
||||
detached_cmd = (
|
||||
f"nohup {cmd.replace('&', '').strip()} "
|
||||
f">/dev/null 2>&1 &"
|
||||
)
|
||||
|
||||
print(
|
||||
f"{SYSTEM_COLOR}"
|
||||
f"🖥️ GUI-APP erkannt → Detached Mode"
|
||||
f"{RESET}"
|
||||
)
|
||||
|
||||
if target.lower() in ["localhost", "127.0.0.1"]:
|
||||
|
||||
proc = await asyncio.create_subprocess_shell(
|
||||
detached_cmd
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
conn = get_db()
|
||||
|
||||
n = conn.execute(
|
||||
'SELECT * FROM nodes WHERE ip=? OR name=?',
|
||||
(target, target)
|
||||
).fetchone()
|
||||
|
||||
conn.close()
|
||||
|
||||
if not n:
|
||||
|
||||
err = (
|
||||
f"Node '{target}' "
|
||||
f"nicht gefunden."
|
||||
)
|
||||
|
||||
print(
|
||||
f"{ERROR_COLOR}{err}{RESET}"
|
||||
)
|
||||
|
||||
return err
|
||||
|
||||
ssh_cmd = (
|
||||
f"ssh "
|
||||
f"-o StrictHostKeyChecking=no "
|
||||
f"-o LogLevel=ERROR "
|
||||
f"{n['user']}@{n['ip']} "
|
||||
f"'{detached_cmd}'"
|
||||
)
|
||||
|
||||
proc = await asyncio.create_subprocess_shell(
|
||||
ssh_cmd
|
||||
)
|
||||
|
||||
await proc.wait()
|
||||
|
||||
print(
|
||||
f"{JARVIS_COLOR}"
|
||||
f"✅ GUI-Programm gestartet"
|
||||
f"{RESET}\n"
|
||||
)
|
||||
|
||||
return "GUI application started."
|
||||
|
||||
# ========================================
|
||||
# NORMALE COMMANDS
|
||||
# ========================================
|
||||
|
||||
else:
|
||||
|
||||
if target.lower() in ["localhost", "127.0.0.1"]:
|
||||
|
||||
final_cmd = cmd
|
||||
|
||||
else:
|
||||
|
||||
conn = get_db()
|
||||
|
||||
n = conn.execute(
|
||||
'SELECT * FROM nodes WHERE ip=? OR name=?',
|
||||
(target, target)
|
||||
).fetchone()
|
||||
|
||||
conn.close()
|
||||
|
||||
if not n:
|
||||
|
||||
err = (
|
||||
f"Node '{target}' "
|
||||
f"nicht gefunden."
|
||||
)
|
||||
|
||||
print(
|
||||
f"{ERROR_COLOR}{err}{RESET}"
|
||||
)
|
||||
|
||||
return err
|
||||
|
||||
final_cmd = (
|
||||
f"ssh "
|
||||
f"-o StrictHostKeyChecking=no "
|
||||
f"-o LogLevel=ERROR "
|
||||
f"{n['user']}@{n['ip']} "
|
||||
f"'{cmd}'"
|
||||
)
|
||||
|
||||
proc = await asyncio.create_subprocess_shell(
|
||||
final_cmd,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.STDOUT
|
||||
)
|
||||
|
||||
collected_output = []
|
||||
|
||||
while True:
|
||||
|
||||
line = await proc.stdout.readline()
|
||||
|
||||
if not line:
|
||||
break
|
||||
|
||||
decoded = line.decode(
|
||||
"utf-8",
|
||||
errors="ignore"
|
||||
).rstrip()
|
||||
|
||||
collected_output.append(decoded)
|
||||
|
||||
print(
|
||||
f"{OUTPUT_COLOR}"
|
||||
f"│ {decoded}"
|
||||
f"{RESET}"
|
||||
)
|
||||
|
||||
await proc.wait()
|
||||
|
||||
print()
|
||||
|
||||
if proc.returncode == 0:
|
||||
|
||||
print(
|
||||
f"{JARVIS_COLOR}"
|
||||
f"✅ TASK ERFOLGREICH"
|
||||
f"{RESET}\n"
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
print(
|
||||
f"{ERROR_COLOR}"
|
||||
f"❌ FEHLER CODE: "
|
||||
f"{proc.returncode}"
|
||||
f"{RESET}\n"
|
||||
)
|
||||
|
||||
return "\n".join(collected_output)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
err = f"❌ Fehler: {e}"
|
||||
|
||||
print(
|
||||
f"{ERROR_COLOR}"
|
||||
f"{err}"
|
||||
f"{RESET}\n"
|
||||
)
|
||||
|
||||
return err
|
||||
|
||||
# ====================================================
|
||||
# FILE LOGGING
|
||||
# ====================================================
|
||||
def log_to_file(role, content):
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
try:
|
||||
with open(CHAT_LOG_FILE, "a", encoding="utf-8") as f:
|
||||
f.write(f"[{now}] {role.upper()}:\n{content}\n{'-'*60}\n")
|
||||
except Exception as e:
|
||||
print(f"{ERROR_COLOR}⚠️ Konnte nicht ins Log schreiben: {e}{RESET}")
|
||||
|
||||
# ====================================================
|
||||
# USER INPUT
|
||||
# ====================================================
|
||||
|
||||
async def listen_to_user():
|
||||
|
||||
return await asyncio.to_thread(
|
||||
input,
|
||||
f"\n{USER_COLOR}👤 Du:{RESET} "
|
||||
)
|
||||
|
||||
|
||||
# ====================================================
|
||||
# JARVIS OUTPUT
|
||||
# ====================================================
|
||||
|
||||
async def speak_to_user(text):
|
||||
|
||||
print(
|
||||
f"\n{JARVIS_COLOR}"
|
||||
f"🤖 J.A.R.V.I.S."
|
||||
f"{RESET}"
|
||||
)
|
||||
|
||||
print(
|
||||
f"{JARVIS_COLOR}"
|
||||
f"{'-'*60}"
|
||||
f"{RESET}"
|
||||
)
|
||||
|
||||
print(text)
|
||||
|
||||
print(
|
||||
f"{JARVIS_COLOR}"
|
||||
f"{'-'*60}"
|
||||
f"{RESET}\n"
|
||||
)
|
||||
|
||||
|
||||
# ====================================================
|
||||
# MAIN LOOP
|
||||
# ====================================================
|
||||
|
||||
async def main_chat_loop():
|
||||
|
||||
print(f"{INFO_COLOR}")
|
||||
|
||||
print("====================================================")
|
||||
print("🤖 J.A.R.V.I.S. Terminal Interface geladen")
|
||||
print(f"🧠 Provider: {AI_PROVIDER.upper()}")
|
||||
print("⌨️ Tippe 'exit', um zu beenden")
|
||||
print("====================================================")
|
||||
|
||||
print(RESET)
|
||||
|
||||
chat_history = []
|
||||
|
||||
while True:
|
||||
|
||||
user_msg = await listen_to_user()
|
||||
|
||||
if user_msg.lower().strip() in ['exit', 'quit']:
|
||||
|
||||
print(
|
||||
f"{SYSTEM_COLOR}"
|
||||
f"\nJ.A.R.V.I.S. geht offline."
|
||||
f"{RESET}"
|
||||
)
|
||||
|
||||
break
|
||||
|
||||
if not user_msg.strip():
|
||||
continue
|
||||
|
||||
now = datetime.now().strftime("%d.%m.%Y %H:%M")
|
||||
|
||||
chat_history.append({
|
||||
"role": "user",
|
||||
"content": user_msg,
|
||||
"timestamp": now
|
||||
})
|
||||
|
||||
# LOG: User Eingabe hier schreiben!
|
||||
log_to_file("Du", user_msg)
|
||||
|
||||
print(
|
||||
f"{SYSTEM_COLOR}"
|
||||
f"🧠 J.A.R.V.I.S. denkt nach..."
|
||||
f"{RESET}",
|
||||
end="\r"
|
||||
)
|
||||
|
||||
system_prompt = get_system_prompt()
|
||||
|
||||
ai_response = await get_ai_response(
|
||||
user_msg,
|
||||
system_prompt,
|
||||
chat_history
|
||||
)
|
||||
|
||||
# ============================================
|
||||
# EXECUTE TAGS SUCHEN
|
||||
# Unterstützt:
|
||||
# <EXECUTE>cmd</EXECUTE>
|
||||
# <EXECUTE target="xyz">cmd</EXECUTE>
|
||||
# ============================================
|
||||
|
||||
commands = []
|
||||
|
||||
# Toleranter Regex: Erlaubt Leerzeichen vor dem '>'
|
||||
execute_matches = re.finditer(
|
||||
r'<EXECUTE[^>]*?(?:target="(.*?)")?[^>]*>(.*?)</EXECUTE>',
|
||||
ai_response,
|
||||
re.I | re.S
|
||||
)
|
||||
|
||||
for match in execute_matches:
|
||||
target = match.group(1)
|
||||
cmd = match.group(2)
|
||||
|
||||
if not target:
|
||||
target = "localhost"
|
||||
|
||||
# Markdown-Backticks bereinigen, falls die KI sie in den Tag mogelt
|
||||
cmd = cmd.strip()
|
||||
cmd = re.sub(r'^```[a-zA-Z]*\n?', '', cmd)
|
||||
cmd = re.sub(r'\n?```$', '', cmd)
|
||||
cmd = cmd.strip()
|
||||
|
||||
commands.append((target.strip(), cmd))
|
||||
|
||||
# Die Tags für die Sprach-/Textausgabe sauber entfernen
|
||||
clean_msg = re.sub(
|
||||
r'<EXECUTE[^>]*?>.*?</EXECUTE>',
|
||||
'',
|
||||
ai_response,
|
||||
flags=re.I | re.S
|
||||
).strip()
|
||||
|
||||
# ============================================
|
||||
# JARVIS TEXT
|
||||
# ============================================
|
||||
|
||||
if clean_msg:
|
||||
|
||||
await speak_to_user(clean_msg)
|
||||
|
||||
chat_history.append({
|
||||
"role": "assistant",
|
||||
"content": clean_msg,
|
||||
"timestamp": now
|
||||
})
|
||||
|
||||
# LOG: Jarvis Antwort hier schreiben!
|
||||
log_to_file("J.A.R.V.I.S.", clean_msg)
|
||||
|
||||
# ============================================
|
||||
# COMMANDS AUSFÜHREN
|
||||
# ============================================
|
||||
|
||||
if commands:
|
||||
|
||||
for target, cmd in commands:
|
||||
|
||||
target = target.strip()
|
||||
cmd = cmd.strip()
|
||||
|
||||
# ========================================
|
||||
# SICHTBARE SYSTEMAKTION
|
||||
# ========================================
|
||||
|
||||
action_msg = (
|
||||
f"⚙️ Ich führe jetzt folgenden Befehl "
|
||||
f"auf [{target}] aus:\n\n"
|
||||
f"{cmd}"
|
||||
)
|
||||
|
||||
await speak_to_user(action_msg)
|
||||
|
||||
chat_history.append({
|
||||
"role": "assistant",
|
||||
"content": action_msg,
|
||||
"timestamp": now
|
||||
})
|
||||
|
||||
# Optional: Aktion auch ins Log
|
||||
log_to_file("SYSTEM", action_msg)
|
||||
|
||||
# ========================================
|
||||
# COMMAND AUSFÜHREN
|
||||
# ========================================
|
||||
|
||||
output = await run_task(
|
||||
target,
|
||||
cmd
|
||||
)
|
||||
|
||||
# ========================================
|
||||
# OUTPUT IM CHAT SICHTBAR MACHEN
|
||||
# ========================================
|
||||
|
||||
if output:
|
||||
|
||||
output_msg = (
|
||||
f"💻 Ergebnis der Ausführung "
|
||||
f"auf [{target}]:\n\n"
|
||||
f"{output}"
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
output_msg = (
|
||||
f"✅ Befehl auf [{target}] "
|
||||
f"erfolgreich abgeschlossen."
|
||||
)
|
||||
|
||||
await speak_to_user(output_msg)
|
||||
|
||||
sys_now = datetime.now().strftime(
|
||||
"%d.%m.%Y %H:%M"
|
||||
)
|
||||
|
||||
chat_history.append({
|
||||
"role": "assistant",
|
||||
"content": output_msg,
|
||||
"timestamp": sys_now
|
||||
})
|
||||
|
||||
# LOG: System Output hier schreiben!
|
||||
log_to_file("SYSTEM", output_msg)
|
||||
|
||||
# ============================================
|
||||
# HISTORY LIMIT
|
||||
# ============================================
|
||||
|
||||
if len(chat_history) > 20:
|
||||
chat_history = chat_history[-20:]
|
||||
|
||||
|
||||
# ====================================================
|
||||
# START
|
||||
# ====================================================
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
try:
|
||||
|
||||
asyncio.run(main_chat_loop())
|
||||
|
||||
except KeyboardInterrupt:
|
||||
|
||||
print(
|
||||
f"\n{ERROR_COLOR}"
|
||||
f"⛔ J.A.R.V.I.S. hart beendet."
|
||||
f"{RESET}"
|
||||
)
|
||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
openai
|
||||
google-genai
|
||||
python-dotenv
|
||||
77
setup.sh
Normal file
77
setup.sh
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "=========================================="
|
||||
echo "🤖 J.A.R.V.I.S. Terminal - Setup"
|
||||
echo "=========================================="
|
||||
|
||||
# 1. Virtual Environment
|
||||
echo "--- Richte Python-Umgebung ein..."
|
||||
if [ ! -d "venv" ]; then
|
||||
python3 -m venv venv
|
||||
fi
|
||||
|
||||
./venv/bin/pip install --upgrade pip
|
||||
if [ -f "requirements.txt" ]; then
|
||||
./venv/bin/pip install -r requirements.txt
|
||||
fi
|
||||
|
||||
# 2. Ordnerstruktur
|
||||
mkdir -p config data workspace
|
||||
|
||||
# 3. .env Setup
|
||||
ENV_FILE="config/.env"
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
echo "--- Erstelle .env Konfiguration..."
|
||||
read -p "Dein Name (Standard: Meik): " web_user
|
||||
read -p "Primäre KI (google, openai, nvidia, ollama) [nvidia]: " ai_prov
|
||||
read -p "NVIDIA API Key: " nvidia_key
|
||||
read -p "Google API Key: " google_key
|
||||
|
||||
cat <<EOF > "$ENV_FILE"
|
||||
WEB_USER_NAME=${web_user:-Meik}
|
||||
AI_PROVIDER=${ai_prov:-nvidia}
|
||||
GOOGLE_API_KEY=$google_key
|
||||
NVIDIA_API_KEY=$nvidia_key
|
||||
NVIDIA_MODEL=moonshotai/kimi-k2.5
|
||||
GOOGLE_MODEL=gemini-2.5-flash
|
||||
OLLAMA_BASE_URL=http://127.0.0.1:11434/v1
|
||||
OLLAMA_MODEL=llama3
|
||||
EOF
|
||||
echo "✅ .env erstellt."
|
||||
fi
|
||||
|
||||
# 4. System Prompt kopieren
|
||||
PROMPT_FILE="config/system_prompt.txt"
|
||||
if [ ! -f "$PROMPT_FILE" ]; then
|
||||
echo "--- Erstelle Standard-Prompt..."
|
||||
cat << 'EOF' > "$PROMPT_FILE"
|
||||
Dein Name ist JARVIS.
|
||||
Du bist ein präziser KI-Assistent für die Cluster-Verwaltung.
|
||||
WICHTIGSTE REGEL: Deine Sprache ist locker, technisch versiert und du verwendest NIEMALS die Höflichkeitsform "Sie". Wir sind per Du.
|
||||
|
||||
DEIN WORKSPACE (GEDÄCHTNIS):
|
||||
Du hast Zugriff auf ein eigenes Arbeitsverzeichnis auf dem Host-System (localhost), um dir Notizen zu machen oder Todos für {user_name} zu speichern:
|
||||
- Arbeitsverzeichnis: {workspace_dir}
|
||||
- Notizen-Datei: {notes_file}
|
||||
- Todo-Liste: {todo_file}
|
||||
|
||||
Du kannst diese Dateien lesen oder beschreiben. Nutze dazu normale Shell-Befehle (z.B. cat, echo "text" >> datei) mit dem Ziel "localhost":
|
||||
<EXECUTE target="localhost">befehl</EXECUTE>
|
||||
|
||||
PROTOKOLL FÜR BEFEHLE (2 Phasen):
|
||||
PHASE 1 (Vorschlag): Wenn {user_name} eine Aktion anfordert, erstelle NUR einen Text-Vorschlag.
|
||||
- Beschreibe kurz, was du tun würdest. Nenne den Befehl als normalen Text.
|
||||
- Frage explizit nach Erlaubnis: "Soll ich das ausführen, {user_name}?"
|
||||
PHASE 2 (Ausführung): NUR wenn {user_name} die Aktion bestätigt, gibst du den Befehl im XML-Format aus:
|
||||
<EXECUTE target="IP_ODER_LOCALHOST">befehl</EXECUTE>
|
||||
|
||||
Bekannte Nodes:
|
||||
{node_info}
|
||||
EOF
|
||||
echo "✅ system_prompt.txt erstellt."
|
||||
fi
|
||||
|
||||
echo "=========================================="
|
||||
echo "✅ Setup abgeschlossen! "
|
||||
echo "=========================================="
|
||||
1146
setup_wayland_jarvis.sh
Normal file
1146
setup_wayland_jarvis.sh
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user