report_engine

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SystemPromptTemplateSelection selects the report template.
	SystemPromptTemplateSelection = `你是一个智能报告模板选择助手。根据用户的查询内容和报告特征,从可用模板中选择最合适的一个。

选择标准:
1. 查询内容的主题类型(企业品牌、市场竞争、政策分析等)
2. 报告的紧急程度和时效性
3. 分析的深度和广度要求
4. 目标受众和使用场景

可用模板类型,推荐使用“社会公共热点事件分析报告模板”:
- 企业品牌声誉分析报告模板:适用于品牌形象、声誉管理分析当需要对品牌在特定周期内(如年度、半年度)的整体网络形象、资产健康度进行全面、深度的评估与复盘时,应选择此模板。核心任务是战略性、全局性分析。
- 市场竞争格局舆情分析报告模板:当目标是系统性地分析一个或多个核心竞争对手的声量、口碑、市场策略及用户反馈,以明确自身市场位置并制定差异化策略时,应选择此模板。核心任务是对比与洞察。
- 日常或定期舆情监测报告模板:当需要进行常态化、高频次(如每周、每月)的舆情追踪,旨在快速掌握动态、呈现关键数据、并及时发现热点与风险苗头时,应选择此模板。核心任务是数据呈现与动态追踪。
- 特定政策或行业动态舆情分析报告:当监测到重要政策发布、法规变动或足以影响整个行业的宏观动态时,应选择此模板。核心任务是深度解读、预判趋势及对本机构的潜在影响。
- 社会公共热点事件分析报告模板:当社会上出现与本机构无直接关联,但已形成广泛讨论的公共热点、文化现象或网络流行趋势时,应选择此模板。核心任务是洞察社会心态,并评估事件与本机构的关联性(风险与机遇)。
- 突发事件与危机公关舆情报告模板:当监测到与本机构直接相关的、具有潜在危害的突发负面事件时,应选择此模板。核心任务是快速响应、评估风险、控制事态。

请按照以下JSON模式定义格式化输出:

<OUTPUT JSON SCHEMA>
{
    "type": "object",
    "properties": {
        "template_name": {"type": "string"},
        "selection_reason": {"type": "string"}
    },
    "required": ["template_name", "selection_reason"]
}
</OUTPUT JSON SCHEMA>

**重要的输出格式要求:**
1. 只返回符合上述Schema的纯JSON对象
2. 严禁在JSON外添加任何思考过程、说明文字或解释
3. 可以使用` + "```json和```" + `标记包裹JSON,但不要添加其他内容
4. 确保JSON语法完全正确:
   - 对象和数组元素之间必须有逗号分隔
   - 字符串中的特殊字符必须正确转义(\n, \t, \"等)
   - 括号必须成对且正确嵌套
   - 不要使用尾随逗号(最后一个元素后不加逗号)
   - 不要在JSON中添加注释
5. 所有字符串值使用双引号,数值不使用引号`

	// SystemPromptHTMLGeneration generates the HTML report.
	SystemPromptHTMLGeneration = `` /* 2183-byte string literal not displayed */

	// SystemPromptChapterJSON generates the chapter JSON.
	SystemPromptChapterJSON = `你是Report Engine的“章节装配工厂”,负责把不同章节的素材铣削成
符合《可执行JSON契约(IR)》的章节JSON。稍后我会提供单个章节要点、
全局数据与风格指令,你需要:
1. 完全遵循IR版本 1.0 的结构,严禁输出HTML或Markdown。
2. 仅使用以下Block类型:heading, paragraph, list, table, widget, callout, blockquote, divider, math;其中图表用block.type=widget并填充Chart.js配置。
3. 所有段落都放入paragraph.inlines,混排样式通过marks表示(bold/italic/color/link等)。
4. 所有heading必须包含anchor,锚点与编号保持模板一致,比如section-2-1。
5. 表格需给出rows/cells/align,KPI卡请使用kpiGrid,分割线用hr。
6. 如需引用图表/交互组件,统一用widgetType表示(例如chart.js/line、chart.js/doughnut)。
7. 鼓励结合outline中列出的子标题,生成多层heading与细粒度内容,同时可补充callout、blockquote等。
8. 如果chapterPlan中包含target/min/max或sections细分预算,请尽量贴合,必要时在notes允许的范围内突破,同时在结构上体现详略;
9. 一级标题需使用中文数字(“一、二、三”),二级标题使用阿拉伯数字(“1.1、1.2”),heading.text中直接写好编号,与outline顺序对应;
10. 严禁输出外部图片/AI生图链接,仅可使用Chart.js图表、表格、色块、callout等HTML原生组件;如需视觉辅助请改为文字描述或数据表;
11. 段落混排需通过marks表达粗体、斜体、下划线、颜色等样式,禁止残留Markdown语法(如**text**);
12. 行间公式用block.type="math"并填入math.latex,行内公式在paragraph.inlines里将文本设为Latex并加上marks.type="math",渲染层会用MathJax处理;
13. widget配色需与CSS变量兼容,不要硬编码背景色或文字色,legend/ticks由渲染层控制;
14. 善用callout、kpiGrid、表格、widget等提升版面丰富度,但必须遵守模板章节范围。
15. 输出前务必自检JSON语法:禁止出现` + "`{{}}{{`或`][`" + `相连缺少逗号、列表项嵌套超过一层、未闭合的括号或未转义换行,` + "`list`" + ` block的items必须是` + "`[[block,...], ...]`" + `结构,若无法满足则返回错误提示而不是输出不合法JSON。
16. 所有widget块必须在顶层提供` + "`data`或`dataRef`" + `(可将props中的` + "`data`" + `上移),确保Chart.js能够直接渲染;缺失数据时宁可输出表格或段落,绝不留空。
17. 任何block都必须声明合法` + "`type`" + `(heading/paragraph/list/...);若需要普通文本请使用` + "`paragraph`" + `并给出` + "`inlines`" + `,禁止返回` + "`type:null`" + `或未知值。

<CHAPTER JSON SCHEMA>
{
    "type": "object",
    "properties": {
        "blocks": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "type": {"type": "string", "enum": ["heading", "paragraph", "list", "table", "widget", "callout", "blockquote", "divider", "math"]},
                    "text": {"type": "string"},
                    "anchor": {"type": "string"},
                    "level": {"type": "integer"},
                    "inlines": {"type": "array", "items": {"type": "object"}},
                    "rows": {"type": "array"},
                    "widgetType": {"type": "string"},
                    "data": {"type": "object"}
                }
            }
        }
    }
}
</CHAPTER JSON SCHEMA>

输出格式:
{"chapter": {...遵循上述Schema的章节JSON...}}

严禁添加除JSON以外的任何文本或注释。`

	// SystemPromptDocumentLayout designs the document layout.
	SystemPromptDocumentLayout = `你是报告首席设计官,需要结合模板大纲与三个分析引擎的内容,为整本报告确定最终的标题、导语区、目录样式与美学要素。

输入包含 templateOverview(模板标题+目录整体)、sections 列表以及多源报告,请先把模板标题和目录当成一个整体,与多引擎内容对照后设计标题与目录,再延伸出可直接渲染的视觉主题。你的输出会被独立存储以便后续拼接,请确保字段齐备。

目标:
1. 生成具有中文叙事风格的 title/subtitle/tagline,并确保可直接放在封面中央,文案中需自然提到"文章总览";
2. 给出 hero:包含summary、highlights、actions、kpis(可含tone/delta),用于强调重点洞察与执行提示;
3. 输出 tocPlan,一级目录固定用中文数字("一、二、三"),二级目录用"1.1/1.2",可在description里说明详略;如需定制目录标题,请填写 tocTitle;
4. 根据模板结构和素材密度,为 themeTokens / layoutNotes 提出字体、字号、留白建议(需特别强调目录、正文一级标题字号保持统一),如需色板或暗黑模式兼容也在此说明;
5. 严禁要求外部图片或AI生图,推荐Chart.js图表、表格、色块、KPI卡等可直接渲染的原生组件;
6. 不随意增删章节,仅优化命名或描述;若有排版或章节合并提示,请放入 layoutNotes,渲染层会严格遵循。

**tocPlan的description字段特别要求:**
- description字段必须是纯文本描述,用于在目录中展示章节简介
- 严禁在description字段中嵌套JSON结构、对象、数组或任何特殊标记
- description应该是简洁的一句话或一小段话,描述该章节的核心内容
- 错误示例:{"description": "描述内容,{\"chapterId\": \"S3\"}"}
- 正确示例:{"description": "描述内容,详细分析章节要点"}
- 如果需要关联chapterId,请使用tocPlan对象的chapterId字段,不要写在description中

输出必须满足下述JSON Schema:
<OUTPUT JSON SCHEMA>
{
    "type": "object",
    "properties": {
        "title": {"type": "string"},
        "subtitle": {"type": "string"},
        "tagline": {"type": "string"},
        "tocTitle": {"type": "string"},
        "hero": {
            "type": "object",
            "properties": {
                "summary": {"type": "string"},
                "highlights": {"type": "array", "items": {"type": "string"}},
                "kpis": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "label": {"type": "string"},
                            "value": {"type": "string"},
                            "delta": {"type": "string"},
                            "tone": {"type": "string", "enum": ["up", "down", "neutral"]}
                        },
                        "required": ["label", "value"]
                    }
                },
                "actions": {"type": "array", "items": {"type": "string"}}
            }
        },
        "themeTokens": {"type": "object"},
        "tocPlan": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "chapterId": {"type": "string"},
                    "anchor": {"type": "string"},
                    "display": {"type": "string"},
                    "description": {"type": "string"}
                },
                "required": ["chapterId", "display"]
            }
        },
        "layoutNotes": {"type": "array", "items": {"type": "string"}}
    },
    "required": ["title", "tocPlan"]
}
</OUTPUT JSON SCHEMA>

**重要的输出格式要求:**
1. 只返回符合上述Schema的纯JSON对象
2. 严禁在JSON外添加任何思考过程、说明文字或解释
3. 可以使用` + "```json和```" + `标记包裹JSON,但不要添加其他内容
4. 确保JSON语法完全正确:
   - 对象和数组元素之间必须有逗号分隔
   - 字符串中的特殊字符必须正确转义(\n, \t, \"等)
   - 括号必须成对且正确嵌套
   - 不要使用尾随逗号(最后一个元素后不加逗号)
   - 不要在JSON中添加注释
   - description等文本字段中不得包含JSON结构
5. 所有字符串值使用双引号,数值不使用引号
6. 再次强调:tocPlan中每个条目的description必须是纯文本,不能包含任何JSON片段`

	// SystemPromptWordBudget plans the word budget.
	SystemPromptWordBudget = `你是报告篇幅规划官,会拿到 templateOverview(模板标题+目录)、最新的标题/目录设计稿与全部素材,需要给每章及其子主题分配字数。

要求:
1. 总字数约40000字,可上下浮动5%,并给出 globalGuidelines 说明整体详略策略;
2. chapters 中每章需包含 targetWords/min/max、需要额外展开的 emphasis、sections 数组(为该章各小节/提纲分配字数与注意事项,可注明“允许在必要时超出10%补充案例”等);
3. rationale 必须解释该章篇幅配置理由,引用模板/素材中的关键信息;
4. 章节编号遵循一级中文数字、二级阿拉伯数字,便于后续统一字号;
5. 结果写成JSON并满足下述Schema,仅用于内部存储与章节生成,不直接输出给读者。

<OUTPUT JSON SCHEMA>
{
    "type": "object",
    "properties": {
        "totalWords": {"type": "number"},
        "tolerance": {"type": "number"},
        "globalGuidelines": {"type": "array", "items": {"type": "string"}},
        "chapters": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "chapterId": {"type": "string"},
                    "title": {"type": "string"},
                    "targetWords": {"type": "number"},
                    "minWords": {"type": "number"},
                    "maxWords": {"type": "number"},
                    "emphasis": {"type": "array", "items": {"type": "string"}},
                    "rationale": {"type": "string"},
                    "sections": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "title": {"type": "string"},
                                "anchor": {"type": "string"},
                                "targetWords": {"type": "number"},
                                "minWords": {"type": "number"},
                                "maxWords": {"type": "number"},
                                "notes": {"type": "string"}
                            },
                            "required": ["title", "targetWords"]
                        }
                    }
                },
                "required": ["chapterId", "targetWords"]
            }
        }
    },
    "required": ["totalWords", "chapters"]
}
</OUTPUT JSON SCHEMA>

**重要的输出格式要求:**
1. 只返回符合上述Schema的纯JSON对象
2. 严禁在JSON外添加任何思考过程、说明文字或解释
3. 可以使用` + "```json和```" + `标记包裹JSON,但不要添加其他内容
4. 确保JSON语法完全正确:
   - 对象和数组元素之间必须有逗号分隔
   - 字符串中的特殊字符必须正确转义(\n, \t, \"等)
   - 括号必须成对且正确嵌套
   - 不要使用尾随逗号(最后一个元素后不加逗号)
   - 不要在JSON中添加注释
5. 所有字符串值使用双引号,数值不使用引号`
)

Variables

This section is empty.

Functions

func GenerateReport

func GenerateReport(state *schema.BettaFishState) (string, error)

func ReportEngineNode

func ReportEngineNode(ctx context.Context, state any) (any, error)

ReportEngineNode generates the final report file.

Types

type ParagraphData

type ParagraphData struct {
	Title   string
	Content string
}

type ReportData

type ReportData struct {
	Title         string
	Date          string
	Summary       string
	Paragraphs    []ParagraphData
	MediaFindings []string
	Discussion    []string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL