feat: Workflow Engine Part 3 - Inline Prompts (v0.9q)
Ermöglicht Analysis Nodes zwischen zwei Prompt-Modi zu wählen: - Reference Mode: Basis-Prompt aus DB referenzieren (bestehend) - Inline Mode: Template direkt im Node editieren (NEU) Frontend: - InlineTemplateEditor Component (~80 Zeilen) - Radio Buttons in WorkflowEditorPage für Mode-Auswahl - Placeholder Picker für beide Modi (End Node + Inline Template) - Cursor-Position Tracking mit textareaRef - Conditional Rendering basierend auf promptSource - Validation: Entweder prompt_slug ODER inline_template Backend: - load_prompt_template() akzeptiert ganzen WorkflowNode (statt nur slug) - Unterstützt inline_template (Mode 1) und prompt_slug (Mode 2) - WorkflowNode.inline_template Feld hinzugefügt - Validation: HTTPException wenn weder slug noch template Serialization: - inline_template in graph_data speichern/laden - Backward-compatible mit bestehenden Workflows Version: 0.9q Module: workflow 0.7.0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
b453ce63c6
commit
a1723db387
7 files changed
+295
-79
No files matched your search
@@ -278,9 +278,10 @@ async def execute_node(
|
||||
|
||||
# Analysis Nodes
|
||||
if node.type == "analysis":
|
||||
# 1. Lade Prompt
|
||||
prompt_template = await load_prompt_template(node.prompt_slug, context)
|
||||
logger.debug(f"Node {node.id}: Loaded prompt '{node.prompt_slug}'")
|
||||
# 1. Lade Prompt (Part 3: inline_template support)
|
||||
prompt_template = await load_prompt_template(node, context)
|
||||
source_type = "inline" if node.inline_template else "reference"
|
||||
logger.debug(f"Node {node.id}: Loaded prompt from {source_type}")
|
||||
|
||||
# 2. Parse question_augmentations
|
||||
questions = []
|
||||
@@ -812,39 +813,64 @@ def _has_active_incoming_edge(node, graph: WorkflowGraph, context: Dict[str, Any
|
||||
return False
|
||||
|
||||
|
||||
async def load_prompt_template(prompt_slug: str, context: Dict[str, Any]) -> str:
|
||||
async def load_prompt_template(node: WorkflowNode, context: Dict[str, Any]) -> str:
|
||||
"""
|
||||
Lädt Prompt-Template aus DB und resolved Platzhalter.
|
||||
Lädt Prompt-Template aus DB (reference mode) oder direkt vom Node (inline mode).
|
||||
|
||||
Part 3: Inline Prompts - Unterstützt zwei Modi:
|
||||
- Reference Mode: prompt_slug → Template aus ai_prompts Tabelle
|
||||
- Inline Mode: inline_template → Template direkt vom Node
|
||||
|
||||
Args:
|
||||
prompt_slug: Slug des Prompts (z.B. "pipeline_body")
|
||||
node: WorkflowNode mit prompt_slug ODER inline_template
|
||||
context: {"variables": {"name": "Lars", ...}, "profile_id": "..."}
|
||||
|
||||
Returns:
|
||||
Resolved prompt template
|
||||
|
||||
Raises:
|
||||
HTTPException: Wenn weder prompt_slug noch inline_template gesetzt
|
||||
|
||||
Beispiel:
|
||||
>>> template = await load_prompt_template("pipeline_body", {"profile_id": "123"})
|
||||
>>> node = WorkflowNode(id="n1", prompt_slug="pipeline_body")
|
||||
>>> template = await load_prompt_template(node, {"profile_id": "123"})
|
||||
>>> "{{name}}" not in template
|
||||
True
|
||||
"""
|
||||
from placeholder_resolver import get_placeholder_example_values, get_placeholder_catalog
|
||||
from prompt_executor import resolve_placeholders
|
||||
from fastapi import HTTPException
|
||||
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"SELECT template FROM ai_prompts WHERE slug = %s AND active = true",
|
||||
(prompt_slug,)
|
||||
# Mode 1: Inline Template (NEU)
|
||||
if node.inline_template:
|
||||
logger.debug(f"Node {node.id}: Using inline template ({len(node.inline_template)} chars)")
|
||||
template = node.inline_template
|
||||
|
||||
# Mode 2: Reference (bestehend)
|
||||
elif node.prompt_slug:
|
||||
logger.debug(f"Node {node.id}: Loading prompt '{node.prompt_slug}' from DB")
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"SELECT template FROM ai_prompts WHERE slug = %s AND active = true",
|
||||
(node.prompt_slug,)
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail=f"Prompt not found: {node.prompt_slug}")
|
||||
template = row['template']
|
||||
|
||||
# Mode 3: Error - weder inline noch reference
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Node {node.id}: Either prompt_slug or inline_template required"
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise ValueError(f"Prompt not found: {prompt_slug}")
|
||||
|
||||
template = row['template']
|
||||
|
||||
# Resolve Placeholders using modern prompt_executor method
|
||||
profile_id = context.get("profile_id")
|
||||
if not profile_id:
|
||||
raise HTTPException(status_code=400, detail="profile_id required in context")
|
||||
|
||||
# Build variables dict with ALL registered placeholders
|
||||
variables = {}
|
||||
|
||||
Reference in new issue
Block a user