feat(gtm): add session history, database loading, and markdown file import
This commit is contained in:
@@ -131,6 +131,26 @@ def get_output_lang_instruction(lang):
|
||||
|
||||
# --- ORCHESTRATOR PHASES ---
|
||||
|
||||
def list_history(payload):
|
||||
projects = db_manager.get_all_projects()
|
||||
return {"projects": projects}
|
||||
|
||||
def load_history(payload):
|
||||
project_id = payload.get('projectId')
|
||||
if not project_id:
|
||||
raise ValueError("No projectId provided for loading history.")
|
||||
|
||||
data = db_manager.get_project_data(project_id)
|
||||
if not data:
|
||||
raise ValueError(f"Project {project_id} not found.")
|
||||
return data
|
||||
|
||||
def delete_session(payload):
|
||||
project_id = payload.get('projectId')
|
||||
if not project_id:
|
||||
raise ValueError("No projectId provided for deletion.")
|
||||
return db_manager.delete_project(project_id)
|
||||
|
||||
def phase1(payload):
|
||||
product_input = payload.get('productInput', '')
|
||||
lang = payload.get('lang', 'de')
|
||||
@@ -148,6 +168,20 @@ def phase1(payload):
|
||||
analysis_content = product_input
|
||||
logging.info("Input is raw text. Analyzing directly.")
|
||||
|
||||
# AUTOMATISCHE PROJEKTERSTELLUNG
|
||||
if not project_id:
|
||||
# Generiere Namen aus Input
|
||||
raw_name = product_input.strip()
|
||||
if raw_name.startswith('http'):
|
||||
name = f"Web Analysis: {raw_name[:30]}..."
|
||||
else:
|
||||
name = (raw_name[:30] + "...") if len(raw_name) > 30 else raw_name
|
||||
|
||||
logging.info(f"Creating new project: {name}")
|
||||
new_proj = db_manager.create_project(name)
|
||||
project_id = new_proj['id']
|
||||
logging.info(f"New Project ID: {project_id}")
|
||||
|
||||
sys_instr = get_system_instruction(lang)
|
||||
lang_instr = get_output_lang_instruction(lang)
|
||||
|
||||
@@ -170,12 +204,16 @@ def phase1(payload):
|
||||
try:
|
||||
data = json.loads(response)
|
||||
db_manager.save_gtm_result(project_id, 'phase1_result', json.dumps(data))
|
||||
|
||||
# WICHTIG: ID zurückgeben, damit Frontend sie speichert
|
||||
data['projectId'] = project_id
|
||||
return data
|
||||
except json.JSONDecodeError:
|
||||
logging.error(f"Failed to decode JSON from Gemini response in phase1: {response}")
|
||||
error_response = {
|
||||
"error": "Die Antwort des KI-Modells war kein gültiges JSON. Das passiert manchmal bei hoher Auslastung. Bitte versuchen Sie es in Kürze erneut.",
|
||||
"details": response
|
||||
"details": response,
|
||||
"projectId": project_id # Auch bei Fehler ID zurückgeben? Besser nicht, da noch nichts gespeichert.
|
||||
}
|
||||
return error_response
|
||||
|
||||
@@ -471,6 +509,9 @@ def main():
|
||||
"phase9": phase9,
|
||||
"translate": translate,
|
||||
"image": image,
|
||||
"list_history": list_history,
|
||||
"load_history": load_history,
|
||||
"delete_session": delete_session,
|
||||
}
|
||||
|
||||
mode_function = modes.get(args.mode)
|
||||
|
||||
Reference in New Issue
Block a user