Protokoll #12447

ID12447
Zeitstempel2025-12-24 01:28:19.911624
Clientroot
IP
Warning: Undefined array key "request_ip" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 13

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 13
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens4,835 (Input: 0, Output: 0)
Dauer91 ms
Request-Zeit
Warning: Undefined array key "request_timestamp" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 18
Response-Zeit-

Warning: Undefined array key "error_message" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 22

Request

{
    "event": "PreToolUse",
    "tool_name": "Edit",
    "tool_input": {
        "file_path": "\/var\/www\/scripts\/pipeline\/web_generate.py",
        "old_string": "def update_generation_status(order_id: int, status: str, error: str | None = None) -> None:\n    \"\"\"Update generation_status in content_orders table.\"\"\"\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        if status == \"generating\":\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_started_at = NOW(), generation_log = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        elif error:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = %s, updated_at = NOW() WHERE id = %s\",\n                (status, error, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"DB update failed: {e}\", file=sys.stderr)",
        "new_string": "def update_generation_status(order_id: int, status: str, error: str | None = None) -> None:\n    \"\"\"Update generation_status in content_orders table.\"\"\"\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        if status == \"generating\":\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_started_at = NOW(), generation_log = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        elif error:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = %s, updated_at = NOW() WHERE id = %s\",\n                (status, error, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"DB update failed: {e}\", file=sys.stderr)\n\n\ndef log_critique_step(order_id: int, message: str, step: str | None = None) -> None:\n    \"\"\"Append a log line for critique and optionally update current step.\"\"\"\n    timestamp = datetime.now().strftime(\"%H:%M:%S\")\n    log_line = f\"[{timestamp}] {message}\"\n\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        cursor.execute(\"SELECT critique_log FROM content_orders WHERE id = %s\", (order_id,))\n        row = cursor.fetchone()\n        current_log = row[0] if row and row[0] else \"\"\n\n        lines = current_log.split(\"\\n\") if current_log else []\n        lines.append(log_line)\n        if len(lines) > MAX_LOG_LINES:\n            lines = lines[-MAX_LOG_LINES:]\n        new_log = \"\\n\".join(lines)\n\n        if step:\n            cursor.execute(\n                \"UPDATE content_orders SET critique_log = %s, critique_step = %s, updated_at = NOW() WHERE id = %s\",\n                (new_log, step, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET critique_log = %s, updated_at = NOW() WHERE id = %s\",\n                (new_log, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"Critique log update failed: {e}\", file=sys.stderr)\n\n\ndef update_critique_status(order_id: int, status: str, error: str | None = None) -> None:\n    \"\"\"Update critique_status in content_orders table.\"\"\"\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        if status == \"critiquing\":\n            cursor.execute(\n                \"UPDATE content_orders SET critique_status = %s, critique_started_at = NOW(), critique_log = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        elif error:\n            cursor.execute(\n                \"UPDATE content_orders SET critique_status = %s, critique_error = %s, updated_at = NOW() WHERE id = %s\",\n                (status, error, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET critique_status = %s, critique_error = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"Critique DB update failed: {e}\", file=sys.stderr)"
    }
}

Response

{
    "tool_response": {
        "filePath": "\/var\/www\/scripts\/pipeline\/web_generate.py",
        "oldString": "def update_generation_status(order_id: int, status: str, error: str | None = None) -> None:\n    \"\"\"Update generation_status in content_orders table.\"\"\"\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        if status == \"generating\":\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_started_at = NOW(), generation_log = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        elif error:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = %s, updated_at = NOW() WHERE id = %s\",\n                (status, error, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"DB update failed: {e}\", file=sys.stderr)",
        "newString": "def update_generation_status(order_id: int, status: str, error: str | None = None) -> None:\n    \"\"\"Update generation_status in content_orders table.\"\"\"\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        if status == \"generating\":\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_started_at = NOW(), generation_log = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        elif error:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = %s, updated_at = NOW() WHERE id = %s\",\n                (status, error, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"DB update failed: {e}\", file=sys.stderr)\n\n\ndef log_critique_step(order_id: int, message: str, step: str | None = None) -> None:\n    \"\"\"Append a log line for critique and optionally update current step.\"\"\"\n    timestamp = datetime.now().strftime(\"%H:%M:%S\")\n    log_line = f\"[{timestamp}] {message}\"\n\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        cursor.execute(\"SELECT critique_log FROM content_orders WHERE id = %s\", (order_id,))\n        row = cursor.fetchone()\n        current_log = row[0] if row and row[0] else \"\"\n\n        lines = current_log.split(\"\\n\") if current_log else []\n        lines.append(log_line)\n        if len(lines) > MAX_LOG_LINES:\n            lines = lines[-MAX_LOG_LINES:]\n        new_log = \"\\n\".join(lines)\n\n        if step:\n            cursor.execute(\n                \"UPDATE content_orders SET critique_log = %s, critique_step = %s, updated_at = NOW() WHERE id = %s\",\n                (new_log, step, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET critique_log = %s, updated_at = NOW() WHERE id = %s\",\n                (new_log, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"Critique log update failed: {e}\", file=sys.stderr)\n\n\ndef update_critique_status(order_id: int, status: str, error: str | None = None) -> None:\n    \"\"\"Update critique_status in content_orders table.\"\"\"\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        if status == \"critiquing\":\n            cursor.execute(\n                \"UPDATE content_orders SET critique_status = %s, critique_started_at = NOW(), critique_log = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        elif error:\n            cursor.execute(\n                \"UPDATE content_orders SET critique_status = %s, critique_error = %s, updated_at = NOW() WHERE id = %s\",\n                (status, error, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET critique_status = %s, critique_error = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"Critique DB update failed: {e}\", file=sys.stderr)",
        "originalFile": "#!\/usr\/bin\/env python3\n\"\"\"\nWeb Content Generation Interface for KI-System\nCalled from PHP with command and parameters.\n\nUsage:\n    python web_generate.py generate <order_id> [model] [collection] [limit]\n    python web_generate.py critique <version_id> [model]\n    python web_generate.py revise <version_id> [model]\n\"\"\"\n\nimport json\nimport sys\nfrom datetime import datetime\n\nimport mysql.connector\n\n# Change to pipeline directory and add to path\nPIPELINE_PATH = \"\/var\/www\/scripts\/pipeline\"\nsys.path.insert(0, PIPELINE_PATH)\n\nfrom config import DB_CONFIG\nfrom generate import generate_content, revise_content, run_critique_round\n\n# Max log lines to keep\nMAX_LOG_LINES = 50\n\n\ndef log_step(order_id: int, message: str, step: str | None = None) -> None:\n    \"\"\"Append a log line and optionally update current step.\"\"\"\n    timestamp = datetime.now().strftime(\"%H:%M:%S\")\n    log_line = f\"[{timestamp}] {message}\"\n\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        # Get current log\n        cursor.execute(\"SELECT generation_log FROM content_orders WHERE id = %s\", (order_id,))\n        row = cursor.fetchone()\n        current_log = row[0] if row and row[0] else \"\"\n\n        # Append new line, keep last N lines\n        lines = current_log.split(\"\\n\") if current_log else []\n        lines.append(log_line)\n        if len(lines) > MAX_LOG_LINES:\n            lines = lines[-MAX_LOG_LINES:]\n        new_log = \"\\n\".join(lines)\n\n        # Update DB\n        if step:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_log = %s, generation_step = %s, updated_at = NOW() WHERE id = %s\",\n                (new_log, step, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_log = %s, updated_at = NOW() WHERE id = %s\",\n                (new_log, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"Log update failed: {e}\", file=sys.stderr)\n\n\ndef update_generation_status(order_id: int, status: str, error: str | None = None) -> None:\n    \"\"\"Update generation_status in content_orders table.\"\"\"\n    try:\n        conn = mysql.connector.connect(**DB_CONFIG)\n        cursor = conn.cursor()\n        if status == \"generating\":\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_started_at = NOW(), generation_log = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        elif error:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = %s, updated_at = NOW() WHERE id = %s\",\n                (status, error, order_id),\n            )\n        else:\n            cursor.execute(\n                \"UPDATE content_orders SET generation_status = %s, generation_error = NULL, updated_at = NOW() WHERE id = %s\",\n                (status, order_id),\n            )\n        conn.commit()\n        cursor.close()\n        conn.close()\n    except Exception as e:\n        print(f\"DB update failed: {e}\", file=sys.stderr)\n\n\ndef main():\n    \"\"\"Route CLI commands to content generation functions.\"\"\"\n    if len(sys.argv) < 3:\n        print(json.dumps({\"error\": \"Usage: web_generate.py <command> <id> [options]\"}))\n        return\n\n    command = sys.argv[1]\n    entity_id = int(sys.argv[2])\n\n    try:\n        if command == \"generate\":\n            model = sys.argv[3] if len(sys.argv) > 3 else \"anthropic\"\n            collection = sys.argv[4] if len(sys.argv) > 4 else \"documents\"\n            limit = int(sys.argv[5]) if len(sys.argv) > 5 else 5\n\n            # Update status to generating\n            update_generation_status(entity_id, \"generating\")\n\n            # Log start\n            model_display = model.replace(\"ollama:\", \"Ollama: \") if model.startswith(\"ollama:\") else f\"Claude ({model})\"\n            log_step(entity_id, f\"Starte Content-Generierung...\", \"init\")\n            log_step(entity_id, f\"Modell: {model_display}\")\n            log_step(entity_id, f\"Collection: {collection}, Kontext-Limit: {limit}\")\n\n            # Log RAG search\n            log_step(entity_id, \"Suche relevante Dokumente (RAG)...\", \"rag\")\n\n            # Run generation with intermediate logging\n            result = generate_content(order_id=entity_id, model=model, collection=collection, context_limit=limit)\n\n            # Log result\n            if result.get(\"error\"):\n                log_step(entity_id, f\"Fehler: {result['error']}\", \"error\")\n                update_generation_status(entity_id, \"failed\", result[\"error\"])\n            else:\n                sources = result.get(\"sources\", [])\n                log_step(entity_id, f\"{len(sources)} Quellen gefunden\", \"sources\")\n                for src in sources[:3]:\n                    log_step(entity_id, f\"  - {src.get('source', 'Unbekannt')} ({int(src.get('score', 0) * 100)}%)\")\n\n                log_step(entity_id, \"Generiere Content mit KI...\", \"llm\")\n                log_step(entity_id, \"Content erfolgreich generiert!\", \"done\")\n                log_step(entity_id, f\"Version {result.get('version_number', '?')} erstellt\")\n                update_generation_status(entity_id, \"completed\")\n\n        elif command == \"critique\":\n            model = sys.argv[3] if len(sys.argv) > 3 else \"anthropic\"\n            result = run_critique_round(version_id=entity_id, model=model)\n\n        elif command == \"revise\":\n            model = sys.argv[3] if len(sys.argv) > 3 else \"anthropic\"\n            result = revise_content(version_id=entity_id, model=model)\n\n        else:\n            result = {\"error\": f\"Unknown command: {command}\"}\n\n        print(json.dumps(result, ensure_ascii=False))\n\n    except Exception as e:\n        # On exception, mark as failed\n        if command == \"generate\":\n            log_step(entity_id, f\"Fehler: {e}\", \"error\")\n            update_generation_status(entity_id, \"failed\", str(e))\n        print(json.dumps({\"error\": str(e)}))\n\n\nif __name__ == \"__main__\":\n    main()\n",
        "structuredPatch": [
            {
                "oldStart": 91,
                "oldLines": 6,
                "newStart": 91,
                "newLines": 68,
                "lines": [
                    "         print(f\"DB update failed: {e}\", file=sys.stderr)",
                    " ",
                    " ",
                    "+def log_critique_step(order_id: int, message: str, step: str | None = None) -> None:",
                    "+    \"\"\"Append a log line for critique and optionally update current step.\"\"\"",
                    "+    timestamp = datetime.now().strftime(\"%H:%M:%S\")",
                    "+    log_line = f\"[{timestamp}] {message}\"",
                    "+",
                    "+    try:",
                    "+        conn = mysql.connector.connect(**DB_CONFIG)",
                    "+        cursor = conn.cursor()",
                    "+        cursor.execute(\"SELECT critique_log FROM content_orders WHERE id = %s\", (order_id,))",
                    "+        row = cursor.fetchone()",
                    "+        current_log = row[0] if row and row[0] else \"\"",
                    "+",
                    "+        lines = current_log.split(\"\\n\") if current_log else []",
                    "+        lines.append(log_line)",
                    "+        if len(lines) > MAX_LOG_LINES:",
                    "+            lines = lines[-MAX_LOG_LINES:]",
                    "+        new_log = \"\\n\".join(lines)",
                    "+",
                    "+        if step:",
                    "+            cursor.execute(",
                    "+                \"UPDATE content_orders SET critique_log = %s, critique_step = %s, updated_at = NOW() WHERE id = %s\",",
                    "+                (new_log, step, order_id),",
                    "+            )",
                    "+        else:",
                    "+            cursor.execute(",
                    "+                \"UPDATE content_orders SET critique_log = %s, updated_at = NOW() WHERE id = %s\",",
                    "+                (new_log, order_id),",
                    "+            )",
                    "+        conn.commit()",
                    "+        cursor.close()",
                    "+        conn.close()",
                    "+    except Exception as e:",
                    "+        print(f\"Critique log update failed: {e}\", file=sys.stderr)",
                    "+",
                    "+",
                    "+def update_critique_status(order_id: int, status: str, error: str | None = None) -> None:",
                    "+    \"\"\"Update critique_status in content_orders table.\"\"\"",
                    "+    try:",
                    "+        conn = mysql.connector.connect(**DB_CONFIG)",
                    "+        cursor = conn.cursor()",
                    "+        if status == \"critiquing\":",
                    "+            cursor.execute(",
                    "+                \"UPDATE content_orders SET critique_status = %s, critique_started_at = NOW(), critique_log = NULL, updated_at = NOW() WHERE id = %s\",",
                    "+                (status, order_id),",
                    "+            )",
                    "+        elif error:",
                    "+            cursor.execute(",
                    "+                \"UPDATE content_orders SET critique_status = %s, critique_error = %s, updated_at = NOW() WHERE id = %s\",",
                    "+                (status, error, order_id),",
                    "+            )",
                    "+        else:",
                    "+            cursor.execute(",
                    "+                \"UPDATE content_orders SET critique_status = %s, critique_error = NULL, updated_at = NOW() WHERE id = %s\",",
                    "+                (status, order_id),",
                    "+            )",
                    "+        conn.commit()",
                    "+        cursor.close()",
                    "+        conn.close()",
                    "+    except Exception as e:",
                    "+        print(f\"Critique DB update failed: {e}\", file=sys.stderr)",
                    "+",
                    "+",
                    " def main():",
                    "     \"\"\"Route CLI commands to content generation functions.\"\"\"",
                    "     if len(sys.argv) < 3:"
                ]
            }
        ],
        "userModified": false,
        "replaceAll": false
    }
}
← Vorheriger Zur Liste Nächster →