test_prompts.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_builtin_l1_embedded_in_template() -> None:
  58. req = OutlineL1Request(report_type="项目融资", chapter_candidates=[])
  59. text = build_outline_l1_user_prompt(req)
  60. assert "pf-l1-01" in text
  61. assert "企业基本情况分析" in text
  62. assert "融资方案设计" in text
  63. def test_builtin_l2_embedded_branch() -> None:
  64. l1 = OutlineL1Request(report_type="项目融资", agreement_amount=Decimal("1"))
  65. req = OutlineL2Request(
  66. chapter_name="企业财务情况分析",
  67. chapter_no="2",
  68. l1_chapter_id="pf-l1-02",
  69. chapter_presentation_enum="S1",
  70. chapter_paragraph_count_enum="P2",
  71. chapter_reason="r",
  72. overall_logic="g",
  73. leaf_chapter_candidates=[],
  74. l1_task_snapshot=l1,
  75. )
  76. text = build_outline_l2_user_prompt(req)
  77. assert "pf-02-ku-1" in text or "财务概况" in text
  78. def test_builtin_l2_pf_l1_01_matches_requirement_doc_list() -> None:
  79. l1 = OutlineL1Request(
  80. report_type="项目融资",
  81. agreement_amount=Decimal("40"),
  82. enterprise_type="集团企业",
  83. group_business_segments=["系统建设", "AI产品", "硬件设施"],
  84. )
  85. req = OutlineL2Request(
  86. chapter_name="企业基本情况分析",
  87. chapter_no="1",
  88. l1_chapter_id="pf-l1-01",
  89. chapter_presentation_enum="S1",
  90. chapter_paragraph_count_enum="P2",
  91. chapter_reason="无独立报告且为集团企业",
  92. overall_logic="写作蓝图示例",
  93. leaf_chapter_candidates=[],
  94. l1_task_snapshot=l1,
  95. )
  96. text = build_outline_l2_user_prompt(req)
  97. assert "企业基本情况概述" in text
  98. assert "批次处理类" in text
  99. assert "pf-01-ku-03" in text
  100. assert "核心决策规则" in text