mirror of
https://github.com/reconurge/flowsint.git
synced 2026-03-09 07:17:07 -05:00
fix(core): template generator chat prompt
This commit is contained in:
@@ -26,20 +26,6 @@ DEFAULT_SYSTEM_PROMPT = (
|
||||
)
|
||||
|
||||
|
||||
def clean_context(context: List[Dict]) -> List[Dict]:
|
||||
"""Remove unnecessary keys from context data."""
|
||||
cleaned = []
|
||||
for item in context:
|
||||
if isinstance(item, dict):
|
||||
cleaned_item = item.get("data", item).copy()
|
||||
cleaned_item.pop("id", None)
|
||||
cleaned_item.pop("sketch_id", None)
|
||||
if "data" in cleaned_item and isinstance(cleaned_item["data"], dict):
|
||||
cleaned_item["data"].pop("sketch_id", None)
|
||||
cleaned_item.pop("measured", None)
|
||||
cleaned.append(cleaned_item)
|
||||
return cleaned
|
||||
|
||||
|
||||
class ChatService(BaseService):
|
||||
"""
|
||||
@@ -153,15 +139,10 @@ class ChatService(BaseService):
|
||||
) -> Dict[str, Any]:
|
||||
context_message = None
|
||||
if context:
|
||||
try:
|
||||
cleaned_context = clean_context(context)
|
||||
if cleaned_context:
|
||||
context_str = ";".join(context)
|
||||
context_str = "; ".join(context)
|
||||
context_message = f"Context: {context_str}"
|
||||
if len(context_message) > 2000:
|
||||
context_message = context_message[:2000] + "..."
|
||||
except Exception as e:
|
||||
print(f"Context processing error: {e}")
|
||||
|
||||
sorted_messages = sorted(chat.messages, key=lambda x: x.created_at)
|
||||
recent_messages = (
|
||||
|
||||
@@ -127,6 +127,7 @@ response:
|
||||
- Use realistic field mappings based on common API response structures.
|
||||
- If the API likely requires authentication, include a `secrets` section.
|
||||
- Keep the template simple and focused on what the user asked for.
|
||||
- IMPORTANT: Always quote values that contain {{...}} placeholders, e.g. `x-apikey: "{{secrets.API_KEY}}"`. Unquoted curly braces are invalid YAML.
|
||||
"""
|
||||
|
||||
|
||||
@@ -139,6 +140,16 @@ def _extract_yaml(text: str) -> str:
|
||||
return text.strip()
|
||||
|
||||
|
||||
def _quote_template_placeholders(yaml_str: str) -> str:
|
||||
"""Quote unquoted {{...}} placeholders that would break YAML parsing."""
|
||||
return re.sub(
|
||||
r"(:\s+)(\{\{[^}]+\}\})\s*$",
|
||||
r'\1"\2"',
|
||||
yaml_str,
|
||||
flags=re.MULTILINE,
|
||||
)
|
||||
|
||||
|
||||
class TemplateGeneratorService(BaseService):
|
||||
"""Generates enricher template YAML from a free-text prompt using an LLM."""
|
||||
|
||||
@@ -175,6 +186,7 @@ class TemplateGeneratorService(BaseService):
|
||||
|
||||
response = await provider.complete(messages)
|
||||
yaml_str = _extract_yaml(response)
|
||||
yaml_str = _quote_template_placeholders(yaml_str)
|
||||
|
||||
# Validate the YAML
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user