test_prompts.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. from decimal import Decimal
  2. from finrep_algo_agent.prompts.builders import (
  3. build_outline_l1_user_prompt,
  4. build_outline_l2_user_prompt,
  5. build_section_user_prompt,
  6. )
  7. from finrep_algo_agent.schemas.outline import ChapterCandidate, OutlineL1Request, OutlineL2Request
  8. from finrep_algo_agent.schemas.section import SectionRequest
  9. def test_outline_l1_template_renders() -> None:
  10. req = OutlineL1Request(
  11. report_type="项目融资",
  12. agreement_amount=Decimal("100"),
  13. chapter_candidates=[ChapterCandidate(chapter_id="c1", chapter_name="测试章")],
  14. )
  15. text = build_outline_l1_user_prompt(req)
  16. assert "项目融资" in text
  17. assert "c1" in text
  18. assert "一级章节候选清单" in text
  19. assert "presentation_enum" in text
  20. def test_outline_l2_template_renders() -> None:
  21. l1 = OutlineL1Request(
  22. report_type="项目融资",
  23. agreement_amount=Decimal("50"),
  24. chapter_candidates=[],
  25. )
  26. req = OutlineL2Request(
  27. chapter_name="融资方案",
  28. chapter_no="3",
  29. chapter_presentation_enum="S1",
  30. chapter_paragraph_count_enum="P2",
  31. chapter_reason="保留",
  32. overall_logic="总逻辑",
  33. leaf_chapter_candidates=[{"name": "末级1", "知识单元类型": "单元呈现型"}],
  34. l1_task_snapshot=l1,
  35. )
  36. text = build_outline_l2_user_prompt(req)
  37. assert "融资方案" in text
  38. assert "末级1" in text
  39. assert "判断说明" in text
  40. assert "呈现方式" in text
  41. assert "S1" in text
  42. def test_section_template_renders() -> None:
  43. req = SectionRequest(
  44. knowledge_unit_id="ku1",
  45. report_type="财务顾问",
  46. template_type="info",
  47. overall_logic="整体",
  48. chapter_logic="章逻辑",
  49. paragraph_position="定位",
  50. task_input={"a": 1},
  51. data_package={"b": 2},
  52. paragraph_logic="撰写",
  53. )
  54. text = build_section_user_prompt(req)
  55. assert "财务顾问" in text
  56. assert "撰写" in text
  57. def test_section_request_accepts_legacy_data_package_1() -> None:
  58. req = SectionRequest.model_validate(
  59. {
  60. "knowledge_unit_id": "ku-x",
  61. "template_type": "info",
  62. "data_package_1": {"auto": {"k": "v"}},
  63. }
  64. )
  65. assert req.auto_data_package == {"auto": {"k": "v"}}
  66. def test_builtin_l1_embedded_in_template() -> None:
  67. req = OutlineL1Request(report_type="项目融资", chapter_candidates=[])
  68. text = build_outline_l1_user_prompt(req)
  69. assert "pf-l1-01" in text
  70. assert "企业基本情况分析" in text
  71. assert "融资方案设计" in text
  72. def test_builtin_l2_embedded_branch() -> None:
  73. l1 = OutlineL1Request(report_type="项目融资", agreement_amount=Decimal("1"))
  74. req = OutlineL2Request(
  75. chapter_name="企业财务情况分析",
  76. chapter_no="2",
  77. l1_chapter_id="pf-l1-02",
  78. chapter_presentation_enum="S1",
  79. chapter_paragraph_count_enum="P2",
  80. chapter_reason="r",
  81. overall_logic="g",
  82. leaf_chapter_candidates=[],
  83. l1_task_snapshot=l1,
  84. )
  85. text = build_outline_l2_user_prompt(req)
  86. assert "pf-02-ku-1" in text or "财务概况" in text
  87. def test_builtin_l2_pf_l1_01_matches_requirement_doc_list() -> None:
  88. l1 = OutlineL1Request(
  89. report_type="项目融资",
  90. agreement_amount=Decimal("40"),
  91. enterprise_type="集团企业",
  92. group_business_segments=["系统建设", "AI产品", "硬件设施"],
  93. )
  94. req = OutlineL2Request(
  95. chapter_name="企业基本情况分析",
  96. chapter_no="1",
  97. l1_chapter_id="pf-l1-01",
  98. chapter_presentation_enum="S1",
  99. chapter_paragraph_count_enum="P2",
  100. chapter_reason="无独立报告且为集团企业",
  101. overall_logic="写作蓝图示例",
  102. leaf_chapter_candidates=[],
  103. l1_task_snapshot=l1,
  104. )
  105. text = build_outline_l2_user_prompt(req)
  106. assert "企业基本情况概述" in text
  107. assert "批次处理类" in text
  108. assert "pf-01-ku-03" in text
  109. assert "核心决策规则" in text