formatter
¶
Full name: tenets.core.distiller.formatter
formatter¶
Context formatting for different output formats.
The formatter takes aggregated context and formats it for consumption by LLMs or humans in various formats (markdown, XML, JSON).
Classes¶
ContextFormatter¶
Formats aggregated context for output.
Initialize the formatter.
PARAMETER | DESCRIPTION |
---|---|
config | Tenets configuration TYPE: |
Source code in tenets/core/distiller/formatter.py
Functions¶
format¶
Python
format(aggregated: Dict[str, Any], format: str, prompt_context: PromptContext, session_name: Optional[str] = None) -> str
Format aggregated context for output.
PARAMETER | DESCRIPTION |
---|---|
aggregated | Aggregated context data containing files and statistics. |
format | Output format (markdown, xml, json, html). TYPE: |
prompt_context | Original prompt context with task analysis. TYPE: |
session_name | Optional session name for context tracking. |
RETURNS | DESCRIPTION |
---|---|
str | Formatted context string in the requested format. |
RAISES | DESCRIPTION |
---|---|
ValueError | If format is not supported. |
Source code in tenets/core/distiller/formatter.py
Python
def format(
self,
aggregated: Dict[str, Any],
format: str,
prompt_context: PromptContext,
session_name: Optional[str] = None,
) -> str:
"""Format aggregated context for output.
Args:
aggregated: Aggregated context data containing files and statistics.
format: Output format (markdown, xml, json, html).
prompt_context: Original prompt context with task analysis.
session_name: Optional session name for context tracking.
Returns:
Formatted context string in the requested format.
Raises:
ValueError: If format is not supported.
"""
self.logger.debug(f"Formatting context as {format}")
if format == "markdown":
return self._format_markdown(aggregated, prompt_context, session_name)
elif format == "xml":
return self._format_xml(aggregated, prompt_context, session_name)
elif format == "json":
return self._format_json(aggregated, prompt_context, session_name)
elif format == "html":
return self._format_html(aggregated, prompt_context, session_name)
else:
raise ValueError(f"Unknown format: {format}")