refactor(csv-import): Enhance nutrition data processing and template rendering
- Updated the nutrition import logic to utilize a new row processing specification, improving data aggregation and validation. - Refactored the template rendering process in the workflow executor to use Jinja2's Environment with ChainableUndefined for better handling of missing attributes. - Added backward-compatible shortcuts for accessing decision signals in node contexts, enhancing flexibility in template usage. - Introduced import row processing options in CSV templates, allowing for more customizable data handling during imports.
This commit is contained in:
1 parent
8b67f7ab55
commit
c0fcdea1fe
9 files changed
+357
-22
No files matched your search
@@ -15,7 +15,7 @@ from datetime import datetime
|
||||
import uuid
|
||||
import logging
|
||||
import json
|
||||
from jinja2 import Template, TemplateError
|
||||
from jinja2 import Environment, ChainableUndefined, TemplateError
|
||||
|
||||
from workflow_models import (
|
||||
WorkflowGraph, NodeExecutionState, ExecutionResult,
|
||||
@@ -618,6 +618,11 @@ def execute_end_node(
|
||||
"reasoning_anchors": node_state.reasoning_anchors or "",
|
||||
"status": node_state.status.value if node_state.status else "unknown",
|
||||
}
|
||||
# Backward-compatible shortcut:
|
||||
# allow {{node_id.relevanz}} in addition to {{node_id.decision_signals.relevanz}}
|
||||
if node_state.decision_signals:
|
||||
for signal_key, signal_value in node_state.decision_signals.items():
|
||||
node_context[signal_key] = signal_value
|
||||
|
||||
# Add normalized signals as {{node_id.signal_ID}}
|
||||
# NOTE: question_type now IS the ID (not the type!)
|
||||
@@ -660,7 +665,10 @@ def execute_end_node(
|
||||
|
||||
# Render template
|
||||
try:
|
||||
jinja_template = Template(node.template)
|
||||
# ChainableUndefined keeps missing nested attributes renderable
|
||||
# so Jinja's default filter can handle them.
|
||||
jinja_env = Environment(undefined=ChainableUndefined)
|
||||
jinja_template = jinja_env.from_string(node.template)
|
||||
final_output = jinja_template.render(template_context)
|
||||
logger.info(f"End node {node.id}: Template rendered successfully ({len(final_output)} chars)")
|
||||
except TemplateError as te:
|
||||
|
||||
Reference in new issue
Block a user