Implementation:666ghj BettaFish TemplateSelectionNode run
| Knowledge Sources | |
|---|---|
| Domains | Report_Generation, LLM_Prompting |
| Last Updated | 2026-10-08 00:00 GMT |
Overview
Concrete node that uses an LLM to select the best report template from a library of 6 Markdown templates based on the user query, engine reports, and forum logs.
Description
The TemplateSelectionNode reads available templates from the `ReportEngine/report_template/` directory (6 templates: brand reputation, market competition, routine monitoring, policy/industry, social events, crisis PR), passes them with the query and reports to an LLM, and asks it to select the most appropriate one. The LLM returns the template name, content, and selection reasoning. If LLM selection fails, it falls back to a built-in default template.
Usage
Import this node when you need to select a report template. It is the first step in the ReportEngine pipeline after normalization.
Code Reference
Source Location
- Repository: BettaFish
- File: `ReportEngine/nodes/template_selection_node.py:L18-286`
Signature
class TemplateSelectionNode(BaseNode):
def __init__(self, llm_client, template_dir: str = "ReportEngine/report_template"):
"""
Args:
llm_client: LLMClient
template_dir: Directory containing Markdown templates
"""
def run(self, input_data: Dict[str, Any], **kwargs) -> Dict[str, Any]:
"""
Select best template for the query and reports.
Args:
input_data: Dict with 'query', 'reports', 'forum_logs' keys
Returns:
Dict with 'template_name', 'template_content', 'selection_reason'
"""
Import
from ReportEngine.nodes import TemplateSelectionNode
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| query | str | Yes | User research query |
| reports | List | Yes | 3-engine reports |
| forum_logs | str | No | Forum debate logs |
Outputs
| Name | Type | Description |
|---|---|---|
| template_name | str | Selected template file name |
| template_content | str | Full Markdown template content |
| selection_reason | str | LLM's reasoning for selection |
Usage Examples
Select Template
from ReportEngine.nodes import TemplateSelectionNode
from ReportEngine.llms import LLMClient
llm = LLMClient(api_key="sk-...", model_name="deepseek-chat", base_url="https://api.deepseek.com/v1")
node = TemplateSelectionNode(llm)
result = node.run({
"query": "某品牌近期公关危机分析",
"reports": [report1, report2, report3],
"forum_logs": ""
})
print(f"Selected: {result['template_name']}")
print(f"Reason: {result['selection_reason']}")