Files
madomeda/core/template.py
T
2025-10-23 19:29:26 +02:00

49 lines
1.4 KiB
Python

"""
Template management
"""
import json
from pathlib import Path
from typing import Optional
class TemplateManager:
def __init__(self, templates_dir: Path):
self.templates_dir = templates_dir
def load_template(self, name: str) -> dict:
"""Load template by name"""
template_path = self.templates_dir / f'{name}.json'
if not template_path.exists():
# Fallback to default
template_path = self.templates_dir / 'default.json'
with open(template_path, 'r', encoding='utf-8') as f:
return json.load(f)
def get_structured_output_schema(self, template: dict) -> dict:
"""Generate JSON schema for structured output"""
properties = {}
required = []
for field in template.keys():
if field == 'tags':
properties[field] = {
"type": "array",
"items": {"type": "string"},
"description": f"Field: {field}"
}
else:
properties[field] = {
"type": "string",
"description": f"Field: {field}"
}
required.append(field)
return {
"type": "object",
"properties": properties,
"required": required,
"additionalProperties": False
}