Initial implementation of the chat application with MariaDB and ArangoDB integration, including Docker setup and web interface.

This commit is contained in:
st-server
2026-01-06 15:26:14 +01:00
parent f0e2fd294b
commit b3f6ecb1bc
13 changed files with 296 additions and 0 deletions

58
worker/worker.py Normal file
View File

@@ -0,0 +1,58 @@
import os
import mysql.connector
import requests
from arango import ArangoClient
import schedule
import time
# MariaDB
def get_db():
return mysql.connector.connect(
host=os.environ['DB_HOST'],
user=os.environ['DB_USER'],
password=os.environ['DB_PASSWORD'],
database=os.environ['DB_NAME']
)
# ArangoDB
def get_arango():
client = ArangoClient(hosts=os.environ['ARANGO_URL'])
db = client.db('llm_facts', username=os.environ['ARANGO_USER'], password=os.environ['ARANGO_PASSWORD'])
return db.collection('facts')
# Analysiere neue Chats und überführe sie in ArangoDB
def analyze_chats():
db = get_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT * FROM chats WHERE llm_output IS NULL")
chats = cursor.fetchall()
arango = get_arango()
for chat in chats:
# Anfrage an LLM zur Analyse / Fakt-Extraktion
resp = requests.post(f"{os.environ['LM_API_URL']}/generate", json={"prompt": f"Extrahiere Fakten und Kontext aus diesem Text:\n{chat['user_input']}"})
fact = resp.json()
# Speichern in ArangoDB
arango.insert({
"_raw": chat['user_input'],
"_source": chat['project'],
"content": fact,
"tags": ["auto"],
"relations": []
})
# Update llm_output in MariaDB
cursor.execute("UPDATE chats SET llm_output=%s WHERE id=%s", (fact, chat['id']))
db.commit()
cursor.close()
db.close()
# Alle 30 Sekunden ausführen
schedule.every(30).seconds.do(analyze_chats)
while True:
schedule.run_pending()
time.sleep(1)