fabricatio 0.2.9.dev3__tar.gz → 0.2.10.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/PKG-INFO +1 -1
  2. fabricatio-0.2.10.dev0/examples/write_article/write_article.py +241 -0
  3. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/pyproject.toml +1 -1
  4. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/actions/article.py +13 -113
  5. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/actions/article_rag.py +9 -2
  6. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/check.py +15 -9
  7. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/correct.py +5 -6
  8. fabricatio-0.2.10.dev0/python/fabricatio/capabilities/rag.py +229 -0
  9. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/rating.py +46 -40
  10. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/config.py +2 -2
  11. fabricatio-0.2.10.dev0/python/fabricatio/constants.py +20 -0
  12. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/decorators.py +23 -0
  13. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/fs/readers.py +20 -1
  14. fabricatio-0.2.10.dev0/python/fabricatio/models/adv_kwargs_types.py +67 -0
  15. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/events.py +6 -6
  16. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/advanced_judge.py +4 -4
  17. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/article_base.py +25 -211
  18. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/article_main.py +69 -95
  19. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/article_proposal.py +15 -14
  20. fabricatio-0.2.10.dev0/python/fabricatio/models/extra/patches.py +20 -0
  21. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/problem.py +12 -17
  22. fabricatio-0.2.10.dev0/python/fabricatio/models/extra/rag.py +72 -0
  23. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/rule.py +1 -2
  24. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/generic.py +34 -10
  25. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/kwargs_types.py +1 -38
  26. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/task.py +3 -3
  27. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/usages.py +78 -8
  28. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/parser.py +5 -5
  29. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/rust.pyi +27 -12
  30. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/src/bib_tools.rs +21 -25
  31. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/src/hash.rs +1 -1
  32. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/src/hbs_helpers.rs +1 -1
  33. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/src/language.rs +1 -2
  34. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/src/templates.rs +1 -0
  35. fabricatio-0.2.10.dev0/src/word_split.rs +86 -0
  36. fabricatio-0.2.10.dev0/templates/built-in/check_string.hbs +22 -0
  37. fabricatio-0.2.10.dev0/templates/built-in/co_validation.hbs +7 -0
  38. fabricatio-0.2.10.dev0/templates/built-in/create_json_obj.hbs +26 -0
  39. fabricatio-0.2.10.dev0/templates/built-in/draft_rating_weights_klee.hbs +37 -0
  40. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/extract_criteria_from_reasons.hbs +3 -3
  41. fabricatio-0.2.10.dev0/templates/built-in/extract_reasons_from_examples.hbs +41 -0
  42. fabricatio-0.2.10.dev0/templates/built-in/rate_fine_grind.hbs +15 -0
  43. fabricatio-0.2.10.dev0/templates.tar.gz +0 -0
  44. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_models/test_action.py +1 -1
  45. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_models/test_problem.py +7 -7
  46. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_models/test_task.py +1 -1
  47. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/uv.lock +78 -78
  48. fabricatio-0.2.9.dev3/examples/write_article/write_article.py +0 -64
  49. fabricatio-0.2.9.dev3/python/fabricatio/capabilities/rag.py +0 -422
  50. fabricatio-0.2.9.dev3/python/fabricatio/models/adv_kwargs_types.py +0 -25
  51. fabricatio-0.2.9.dev3/python/fabricatio/models/extra/patches.py +0 -20
  52. fabricatio-0.2.9.dev3/python/fabricatio/models/utils.py +0 -148
  53. fabricatio-0.2.9.dev3/src/word_split.rs +0 -27
  54. fabricatio-0.2.9.dev3/templates/built-in/check_string.hbs +0 -19
  55. fabricatio-0.2.9.dev3/templates/built-in/co_validation.hbs +0 -26
  56. fabricatio-0.2.9.dev3/templates/built-in/create_json_obj.hbs +0 -74
  57. fabricatio-0.2.9.dev3/templates/built-in/draft_rating_weights_klee.hbs +0 -44
  58. fabricatio-0.2.9.dev3/templates/built-in/extract_reasons_from_examples.hbs +0 -49
  59. fabricatio-0.2.9.dev3/templates/built-in/rate_fine_grind.hbs +0 -43
  60. fabricatio-0.2.9.dev3/templates.tar.gz +0 -0
  61. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/.github/workflows/build-package.yaml +0 -0
  62. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/.github/workflows/ruff.yaml +0 -0
  63. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/.github/workflows/tests.yaml +0 -0
  64. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/.gitignore +0 -0
  65. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/.python-version +0 -0
  66. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/Cargo.lock +0 -0
  67. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/Cargo.toml +0 -0
  68. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/LICENSE +0 -0
  69. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/Makefile +0 -0
  70. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/README.md +0 -0
  71. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/correct/correct.py +0 -0
  72. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/correct/correct_loop.py +0 -0
  73. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/extract_and_inject/.gitignore +0 -0
  74. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/extract_and_inject/article_rag.py +0 -0
  75. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/extract_and_inject/ask.py +0 -0
  76. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/extract_and_inject/extract_and_inject.py +0 -0
  77. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/extract_article/extract.py +0 -0
  78. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/llm_usages/llm_usage.py +0 -0
  79. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/make_a_rating/rating.py +0 -0
  80. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/make_diary/commits.json +0 -0
  81. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/make_diary/diary.py +0 -0
  82. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/minor/hello_fabricatio.py +0 -0
  83. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/minor/write_a_poem.py +0 -0
  84. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/propose_task/propose.py +0 -0
  85. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/reviewer/censor.py +0 -0
  86. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/reviewer/review.py +0 -0
  87. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/rules/.gitignore +0 -0
  88. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/rules/draft_ruleset.py +0 -0
  89. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/search_bibtex/.gitignore +0 -0
  90. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/search_bibtex/search.py +0 -0
  91. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/simple_chat/chat.py +0 -0
  92. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/simple_rag/simple_rag.py +0 -0
  93. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/task_handle/handle_task.py +0 -0
  94. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/write_article/.gitignore +0 -0
  95. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/write_article/article_rag.py +0 -0
  96. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/write_outline/.gitignore +0 -0
  97. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/write_outline/write_outline.py +0 -0
  98. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/examples/write_outline/write_outline_corrected.py +0 -0
  99. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/__init__.py +0 -0
  100. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/actions/__init__.py +0 -0
  101. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/actions/output.py +0 -0
  102. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/actions/rag.py +0 -0
  103. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/actions/rules.py +0 -0
  104. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/__init__.py +0 -0
  105. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/advanced_judge.py +0 -0
  106. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/censor.py +0 -0
  107. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/propose.py +0 -0
  108. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/review.py +0 -0
  109. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/capabilities/task.py +0 -0
  110. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/core.py +0 -0
  111. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/fs/__init__.py +0 -0
  112. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/fs/curd.py +0 -0
  113. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/journal.py +0 -0
  114. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/action.py +0 -0
  115. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/__init__.py +0 -0
  116. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/article_essence.py +0 -0
  117. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/extra/article_outline.py +0 -0
  118. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/role.py +0 -0
  119. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/models/tool.py +0 -0
  120. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/py.typed +0 -0
  121. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/rust_instances.py +0 -0
  122. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/toolboxes/__init__.py +0 -0
  123. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  124. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/toolboxes/fs.py +0 -0
  125. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/utils.py +0 -0
  126. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/workflows/__init__.py +0 -0
  127. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/workflows/articles.py +0 -0
  128. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/python/fabricatio/workflows/rag.py +0 -0
  129. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/src/lib.rs +0 -0
  130. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/as_prompt.hbs +0 -0
  131. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  132. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/claude-xml.hbs +0 -0
  133. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/clean-up-code.hbs +0 -0
  134. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  135. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/dependencies.hbs +0 -0
  136. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/document-the-code.hbs +0 -0
  137. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/draft_rating_criteria.hbs +0 -0
  138. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/draft_rating_manual.hbs +0 -0
  139. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  140. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  141. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/fix-bugs.hbs +0 -0
  142. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/fix_troubled_obj.hbs +0 -0
  143. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/fix_troubled_string.hbs +0 -0
  144. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/generic_string.hbs +0 -0
  145. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/improve-performance.hbs +0 -0
  146. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/liststr.hbs +0 -0
  147. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/make_choice.hbs +0 -0
  148. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/make_judgment.hbs +0 -0
  149. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/pathstr.hbs +0 -0
  150. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/refactor.hbs +0 -0
  151. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/refined_query.hbs +0 -0
  152. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/retrieved_display.hbs +0 -0
  153. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  154. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/review_string.hbs +0 -0
  155. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/rule_requirement.hbs +0 -0
  156. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/ruleset_requirement_breakdown.hbs +0 -0
  157. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/task_briefing.hbs +0 -0
  158. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/web-ctf-solver.hbs +0 -0
  159. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/write-git-commit.hbs +0 -0
  160. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/write-github-pull-request.hbs +0 -0
  161. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/templates/built-in/write-github-readme.hbs +0 -0
  162. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_config.py +0 -0
  163. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_models/test_advanced.py +0 -0
  164. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_models/test_generic.py +0 -0
  165. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_models/test_role.py +0 -0
  166. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_models/test_tool.py +0 -0
  167. {fabricatio-0.2.9.dev3 → fabricatio-0.2.10.dev0}/tests/test_models/test_usages.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.9.dev3
3
+ Version: 0.2.10.dev0
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -0,0 +1,241 @@
1
+ """Example of using the library."""
2
+
3
+ import asyncio
4
+ from pathlib import Path
5
+ from typing import List
6
+
7
+ from fabricatio import Event, Role, WorkFlow, logger
8
+ from fabricatio.actions.article import (
9
+ FixIntrospectedErrors,
10
+ GenerateArticle,
11
+ GenerateArticleProposal,
12
+ GenerateInitialOutline,
13
+ )
14
+ from fabricatio.actions.article_rag import TweakArticleRAG
15
+ from fabricatio.actions.output import DumpFinalizedOutput, GatherAsList, PersistentAll, RetrieveFromLatest
16
+ from fabricatio.actions.rules import DraftRuleSet, GatherRuleset
17
+ from fabricatio.models.action import Action
18
+ from fabricatio.models.extra.article_main import Article
19
+ from fabricatio.models.extra.article_outline import ArticleOutline
20
+ from fabricatio.models.extra.article_proposal import ArticleProposal
21
+ from fabricatio.models.extra.rule import RuleSet
22
+ from fabricatio.models.task import Task
23
+ from fabricatio.utils import ok
24
+
25
+
26
+ class Connect(Action):
27
+ """Connect the article with the article_outline and article_proposal."""
28
+
29
+ output_key: str = "article"
30
+ """Connect the article with the article_outline and article_proposal."""
31
+
32
+ async def _execute(
33
+ self,
34
+ article_briefing: str,
35
+ article_proposal: ArticleProposal,
36
+ article_outline: ArticleOutline,
37
+ article: Article,
38
+ **cxt,
39
+ ) -> Article:
40
+ """Connect the article with the article_outline and article_proposal."""
41
+ return article.update_ref(article_outline.update_ref(article_proposal.update_ref(article_briefing)))
42
+
43
+
44
+ async def main(article: bool, rule: bool = False, fintune: bool = False) -> None:
45
+ """Main function."""
46
+ Role(
47
+ name="Undergraduate Researcher",
48
+ description="Write an outline for an article in typst format.",
49
+ llm_model="openai/deepseek-v3-250324",
50
+ llm_temperature=1.3,
51
+ llm_top_p=1.0,
52
+ llm_max_tokens=8191,
53
+ llm_rpm=1000,
54
+ llm_tpm=5000000,
55
+ registry={
56
+ Event.quick_instantiate(ns := "article"): WorkFlow(
57
+ name="Generate Article Outline",
58
+ description="Generate an outline for an article. dump the outline to the given path. in typst format.",
59
+ steps=(
60
+ RetrieveFromLatest(
61
+ retrieve_cls=RuleSet,
62
+ load_path="persistent_ruleset/outline_ruleset",
63
+ output_key="outline_ruleset",
64
+ ),
65
+ RetrieveFromLatest(
66
+ retrieve_cls=RuleSet,
67
+ load_path="persistent_ruleset/dep_ref_ruleset",
68
+ output_key="dep_ref_ruleset",
69
+ ),
70
+ RetrieveFromLatest(
71
+ retrieve_cls=RuleSet,
72
+ load_path="persistent_ruleset/rev_dep_ref_ruleset",
73
+ output_key="rev_dep_ref_ruleset",
74
+ ),
75
+ RetrieveFromLatest(
76
+ retrieve_cls=RuleSet, load_path="persistent_ruleset/cite_ruleset", output_key="cite_ruleset"
77
+ ),
78
+ RetrieveFromLatest(
79
+ retrieve_cls=RuleSet, load_path="persistent_ruleset/para_ruleset", output_key="para_ruleset"
80
+ ),
81
+ RetrieveFromLatest(
82
+ retrieve_cls=RuleSet, load_path="persistent_ruleset/ref_ruleset", output_key="ref_ruleset"
83
+ ),
84
+ RetrieveFromLatest(
85
+ retrieve_cls=RuleSet, load_path="persistent_ruleset/lang_ruleset", output_key="lang_ruleset"
86
+ ),
87
+ GenerateArticleProposal(llm_temperature=1.3),
88
+ GenerateInitialOutline(
89
+ output_key="article_outline",
90
+ ),
91
+ GatherRuleset(output_key="intro_fix_ruleset", to_gather=["para_ruleset"]),
92
+ FixIntrospectedErrors(
93
+ output_key="article_outline",
94
+ ),
95
+ PersistentAll,
96
+ GatherRuleset(output_key="ref_fix_ruleset", to_gather=["ref_ruleset"]),
97
+ GatherRuleset(output_key="ref_twk_ruleset", to_gather=["dep_ref_ruleset", "ref_ruleset"]),
98
+ GatherRuleset(output_key="article_gen_ruleset", to_gather=["para_ruleset"]),
99
+ GenerateArticle(
100
+ output_key="article",
101
+ ),
102
+ PersistentAll,
103
+ GatherRuleset(
104
+ output_key="twk_rag_ruleset", to_gather=["para_ruleset", "cite_ruleset", "lang_ruleset"]
105
+ ),
106
+ TweakArticleRAG(output_key="to_dump"),
107
+ DumpFinalizedOutput(output_key="task_output"),
108
+ PersistentAll,
109
+ ),
110
+ ).update_init_context(
111
+ article_briefing=Path("./article_briefing.txt").read_text(),
112
+ dump_path="out.typ",
113
+ persist_dir="persistent",
114
+ collection_name="article_essence_0324",
115
+ ),
116
+ Event.quick_instantiate(finetune := "article_finetune"): WorkFlow(
117
+ name="Generate Article Outline",
118
+ description="Generate an outline for an article. dump the outline to the given path. in typst format.",
119
+ steps=(
120
+ RetrieveFromLatest(
121
+ retrieve_cls=RuleSet,
122
+ load_path="persistent_ruleset/outline_ruleset",
123
+ output_key="outline_ruleset",
124
+ ),
125
+ RetrieveFromLatest(
126
+ retrieve_cls=RuleSet,
127
+ load_path="persistent_ruleset/dep_ref_ruleset",
128
+ output_key="dep_ref_ruleset",
129
+ ),
130
+ RetrieveFromLatest(
131
+ retrieve_cls=RuleSet,
132
+ load_path="persistent_ruleset/rev_dep_ref_ruleset",
133
+ output_key="rev_dep_ref_ruleset",
134
+ ),
135
+ RetrieveFromLatest(
136
+ retrieve_cls=RuleSet, load_path="persistent_ruleset/cite_ruleset", output_key="cite_ruleset"
137
+ ),
138
+ RetrieveFromLatest(
139
+ retrieve_cls=RuleSet, load_path="persistent_ruleset/para_ruleset", output_key="para_ruleset"
140
+ ),
141
+ RetrieveFromLatest(
142
+ retrieve_cls=RuleSet, load_path="persistent_ruleset/ref_ruleset", output_key="ref_ruleset"
143
+ ),
144
+ RetrieveFromLatest(
145
+ retrieve_cls=ArticleProposal,
146
+ load_path="persistent/article_proposal",
147
+ output_key="article_proposal",
148
+ ),
149
+ RetrieveFromLatest(
150
+ retrieve_cls=ArticleOutline,
151
+ load_path="persistent/article_outline",
152
+ output_key="article_outline",
153
+ ),
154
+ RetrieveFromLatest(retrieve_cls=Article, load_path="persistent/article", output_key="article"),
155
+ Connect,
156
+ GatherRuleset(output_key="intro_fix_ruleset", to_gather=["para_ruleset"]),
157
+ GatherRuleset(output_key="ref_fix_ruleset", to_gather=["ref_ruleset"]),
158
+ GatherRuleset(output_key="article_gen_ruleset", to_gather=["para_ruleset"]),
159
+ GatherRuleset(output_key="twk_rag_ruleset", to_gather=["para_ruleset", "cite_ruleset"]),
160
+ TweakArticleRAG(
161
+ output_key="to_dump",
162
+ ),
163
+ DumpFinalizedOutput(output_key="task_output"),
164
+ PersistentAll,
165
+ ),
166
+ ).update_init_context(
167
+ article_briefing=Path("./article_briefing.txt").read_text(),
168
+ dump_path="out_fix.typ",
169
+ persist_dir="persistent_fix",
170
+ collection_name="article_essence_0324",
171
+ ),
172
+ Event.quick_instantiate(rule_ns := "rule"): WorkFlow(
173
+ name="Generate Draft Rule Set",
174
+ description="Generate a draft rule set for the article.",
175
+ llm_model="openai/deepseek-v3-250324",
176
+ llm_stream=False,
177
+ steps=(
178
+ # 精简后的para_ruleset规则
179
+ DraftRuleSet(
180
+ ruleset_requirement="如果`paragraphs`字段为空列表,那么你就需要按照`expected_word_count`来为章节补充内容",
181
+ output_key="para_ruleset",
182
+ rule_count=1,
183
+ ),
184
+ # 精简后的cite_ruleset规则
185
+ DraftRuleSet(
186
+ ruleset_requirement="1. 参考文献引用格式:(作者等, 年份)#cite(<bibtex_key>)\n"
187
+ "2. #cite()必须用尖括号包裹单个BibTeX键,多引用需重复使用",
188
+ output_key="cite_ruleset",
189
+ rule_count=1,
190
+ ),
191
+ # 新增中文检测规则集
192
+ DraftRuleSet(
193
+ ruleset_requirement="1. 所有标题和正文内容必须使用中文,如果不为中文你需要翻译过来\n"
194
+ "2. 术语和专业词汇需使用中文表述,英文缩写第一次出现的时候需要在其后面‘()’来辅助说明",
195
+ output_key="lang_ruleset",
196
+ rule_count=1,
197
+ ),
198
+ # 其他规则集保持原有结构但简化内容
199
+ DraftRuleSet(
200
+ ruleset_requirement="章节的`depend_on`字段的`ArticleRef`只能引用当前章节之前的元素。\n",
201
+ output_key="dep_ref_ruleset",
202
+ rule_count=1,
203
+ ),
204
+ DraftRuleSet(
205
+ ruleset_requirement="章节的`support_to`字段的`ArticleRef`只能引用当前章节之后的元素。\n",
206
+ output_key="rev_dep_ref_ruleset",
207
+ rule_count=1,
208
+ ),
209
+ DraftRuleSet(
210
+ ruleset_requirement="ArticleRef必须指向已定义元素",
211
+ output_key="ref_ruleset",
212
+ rule_count=1,
213
+ ),
214
+ DraftRuleSet(
215
+ ruleset_requirement="标题使用学术术语",
216
+ output_key="outline_ruleset",
217
+ rule_count=1,
218
+ ),
219
+ GatherAsList(gather_suffix="ruleset").to_task_output(),
220
+ PersistentAll(persist_dir="persistent_ruleset"),
221
+ ),
222
+ ),
223
+ },
224
+ )
225
+
226
+ if rule:
227
+ draft_rule_task: Task[List[RuleSet]] = Task(name="draft a rule set")
228
+ rule_set = ok(await draft_rule_task.delegate(rule_ns), "Failed to generate ruleset")
229
+ logger.success(f"Ruleset:\n{len(rule_set)}")
230
+ if article:
231
+ proposed_task = Task(name="write an article")
232
+ path = ok(await proposed_task.delegate(ns), "Failed to generate ruleset")
233
+ logger.success(f"The outline is saved in:\n{path}")
234
+ if fintune:
235
+ proposed_task = Task(name="finetune an article")
236
+ path = ok(await proposed_task.delegate(finetune), "Failed to generate ruleset")
237
+ logger.success(f"The outline is saved in:\n{path}")
238
+
239
+
240
+ if __name__ == "__main__":
241
+ asyncio.run(main(True, False, False))
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.9-dev3"
3
+ version = "0.2.10-dev0"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -11,7 +11,6 @@ from fabricatio.capabilities.propose import Propose
11
11
  from fabricatio.fs import safe_text_read
12
12
  from fabricatio.journal import logger
13
13
  from fabricatio.models.action import Action
14
- from fabricatio.models.extra.article_base import SubSectionBase
15
14
  from fabricatio.models.extra.article_essence import ArticleEssence
16
15
  from fabricatio.models.extra.article_main import Article
17
16
  from fabricatio.models.extra.article_outline import ArticleOutline
@@ -105,7 +104,6 @@ class GenerateArticleProposal(Action, Propose):
105
104
  task_input: Optional[Task] = None,
106
105
  article_briefing: Optional[str] = None,
107
106
  article_briefing_path: Optional[str] = None,
108
- langauge: Optional[str] = None,
109
107
  **_,
110
108
  ) -> Optional[ArticleProposal]:
111
109
  if article_briefing is None and article_briefing_path is None and task_input is None:
@@ -122,17 +120,14 @@ class GenerateArticleProposal(Action, Propose):
122
120
  )
123
121
  )
124
122
 
125
- proposal = ok(
123
+ logger.info("Start generating the proposal.")
124
+ return ok(
126
125
  await self.propose(
127
126
  ArticleProposal,
128
- f"{briefing}\n\nWrite the value string using `{detect_language(briefing)}`",
127
+ f"{briefing}\n\nWrite the value string using `{detect_language(briefing)}` as written language.",
129
128
  ),
130
129
  "Could not generate the proposal.",
131
130
  ).update_ref(briefing)
132
- if langauge:
133
- proposal.language = langauge
134
-
135
- return proposal
136
131
 
137
132
 
138
133
  class GenerateInitialOutline(Action, Propose):
@@ -146,11 +141,17 @@ class GenerateInitialOutline(Action, Propose):
146
141
  article_proposal: ArticleProposal,
147
142
  **_,
148
143
  ) -> Optional[ArticleOutline]:
144
+ raw_outline = await self.aask(
145
+ f"{(article_proposal.as_prompt())}\n\nNote that you should use `{article_proposal.language}` to write the `ArticleOutline`\n"
146
+ f"Design each chapter of a proper and academic and ready for release manner.\n"
147
+ f"You Must make sure every chapter have sections, and every section have subsections.\n"
148
+ f"Make the chapter and sections and subsections bing divided into a specific enough article component.",
149
+ )
150
+
149
151
  return ok(
150
152
  await self.propose(
151
153
  ArticleOutline,
152
- f"{(p := article_proposal.as_prompt())}\n\nNote that you should use `{detect_language(p)}` to write the `ArticleOutline`\n"
153
- f"You Must make sure every chapter have sections, and every section have subsections.",
154
+ f"{raw_outline}\n\n\n\noutline provided above is the outline i need to extract to a JSON,",
154
155
  ),
155
156
  "Could not generate the initial outline.",
156
157
  ).update_ref(article_proposal)
@@ -182,7 +183,7 @@ class FixIntrospectedErrors(Action, Censor):
182
183
  await self.censor_obj(
183
184
  article_outline,
184
185
  ruleset=ok(intro_fix_ruleset or self.ruleset, "No ruleset provided"),
185
- reference=f"{article_outline.as_prompt()}\n # Fatal Error of the Original Article Outline\n{pack}",
186
+ reference=f"{article_outline.display()}\n # Fatal Error of the Original Article Outline\n{pack}",
186
187
  ),
187
188
  "Could not correct the component.",
188
189
  ).update_ref(origin)
@@ -195,107 +196,6 @@ class FixIntrospectedErrors(Action, Censor):
195
196
  return article_outline
196
197
 
197
198
 
198
- class FixIllegalReferences(Action, Censor):
199
- """Fix illegal references in the article outline."""
200
-
201
- output_key: str = "illegal_references_fixed_outline"
202
- """The key of the output data."""
203
-
204
- ruleset: Optional[RuleSet] = None
205
- """Ruleset to use to fix the illegal references."""
206
- max_error_count: Optional[int] = None
207
- """The maximum number of errors to fix."""
208
-
209
- async def _execute(
210
- self,
211
- article_outline: ArticleOutline,
212
- ref_fix_ruleset: Optional[RuleSet] = None,
213
- **_,
214
- ) -> Optional[ArticleOutline]:
215
- counter = 0
216
- while pack := article_outline.find_illegal_ref(gather_identical=True):
217
- logger.info(f"Found {counter}th illegal references")
218
- ref_seq, err = ok(pack)
219
- logger.warning(f"Found illegal referring error: {err}")
220
- new = ok(
221
- await self.censor_obj(
222
- ref_seq[0],
223
- ruleset=ok(ref_fix_ruleset or self.ruleset, "No ruleset provided"),
224
- reference=f"{article_outline.as_prompt()}\n# Some Basic errors found that need to be fixed\n{err}",
225
- ),
226
- "Could not correct the component",
227
- )
228
- for r in ref_seq:
229
- r.update_from(new)
230
- if self.max_error_count and counter > self.max_error_count:
231
- logger.warning("Max error count reached, stopping.")
232
- break
233
- counter += 1
234
-
235
- return article_outline
236
-
237
-
238
- class TweakOutlineForwardRef(Action, Censor):
239
- """Tweak the forward references in the article outline.
240
-
241
- Ensures that the conclusions of the current chapter effectively support the analysis of subsequent chapters.
242
- """
243
-
244
- output_key: str = "article_outline_fw_ref_checked"
245
- ruleset: Optional[RuleSet] = None
246
- """Ruleset to use to fix the illegal references."""
247
-
248
- async def _execute(
249
- self, article_outline: ArticleOutline, ref_twk_ruleset: Optional[RuleSet] = None, **cxt
250
- ) -> ArticleOutline:
251
- return await self._inner(
252
- article_outline,
253
- ruleset=ok(ref_twk_ruleset or self.ruleset, "No ruleset provided"),
254
- field_name="support_to",
255
- )
256
-
257
- async def _inner(self, article_outline: ArticleOutline, ruleset: RuleSet, field_name: str) -> ArticleOutline:
258
- await gather(
259
- *[self._loop(a[-1], article_outline, field_name, ruleset) for a in article_outline.iter_subsections()],
260
- )
261
-
262
- return article_outline
263
-
264
- async def _loop(
265
- self, a: SubSectionBase, article_outline: ArticleOutline, field_name: str, ruleset: RuleSet
266
- ) -> None:
267
- if judge := await self.evidently_judge(
268
- f"{article_outline.as_prompt()}\n\n{a.display()}\n"
269
- f"Does the `{a.__class__.__name__}`'s `{field_name}` field need to be extended or tweaked?"
270
- ):
271
- await self.censor_obj_inplace(
272
- a,
273
- ruleset=ruleset,
274
- reference=f"{article_outline.as_prompt()}\n"
275
- f"The Article component titled `{a.title}` whose `{field_name}` field needs to be extended or tweaked.\n"
276
- f"# Judgement\n{judge.display()}",
277
- )
278
-
279
-
280
- class TweakOutlineBackwardRef(TweakOutlineForwardRef):
281
- """Tweak the backward references in the article outline.
282
-
283
- Ensures that the prerequisites of the current chapter are correctly referenced in the `depend_on` field.
284
- """
285
-
286
- output_key: str = "article_outline_bw_ref_checked"
287
- ruleset: Optional[RuleSet] = None
288
-
289
- async def _execute(
290
- self, article_outline: ArticleOutline, ref_twk_ruleset: Optional[RuleSet] = None, **cxt
291
- ) -> ArticleOutline:
292
- return await self._inner(
293
- article_outline,
294
- ruleset=ok(ref_twk_ruleset or self.ruleset, "No ruleset provided"),
295
- field_name="depend_on",
296
- )
297
-
298
-
299
199
  class GenerateArticle(Action, Censor):
300
200
  """Generate the article based on the outline."""
301
201
 
@@ -318,7 +218,7 @@ class GenerateArticle(Action, Censor):
318
218
  self.censor_obj_inplace(
319
219
  subsec,
320
220
  ruleset=ok(article_gen_ruleset or self.ruleset, "No ruleset provided"),
321
- reference=f"{article_outline.as_prompt()}\n# Error Need to be fixed\n{err}",
221
+ reference=f"{article_outline.as_prompt()}\n# Error Need to be fixed\n{err}\nYou should use `{subsec.language}` to write the new `Subsection`.",
322
222
  )
323
223
  for _, _, subsec in article.iter_subsections()
324
224
  if (err := subsec.introspect()) and logger.warning(f"Found Introspection Error:\n{err}") is None
@@ -29,6 +29,9 @@ class TweakArticleRAG(Action, RAG, Censor):
29
29
  ruleset: Optional[RuleSet] = None
30
30
  """The ruleset to be used for censoring the article."""
31
31
 
32
+ ref_limit: int = 30
33
+ """The limit of references to be retrieved"""
34
+
32
35
  async def _execute(
33
36
  self,
34
37
  article: Article,
@@ -88,11 +91,15 @@ class TweakArticleRAG(Action, RAG, Censor):
88
91
  f"{subsec.display()}\n"
89
92
  f"# Requirement\n"
90
93
  f"Search related articles in the base to find reference candidates, "
91
- f"prioritizing both original article language and English usage, which can return multiple candidates.",
94
+ f"provide queries in both `English` and `{subsec.language}` can get more accurate results.",
92
95
  )
93
96
  )
94
97
  await self.censor_obj_inplace(
95
98
  subsec,
96
99
  ruleset=ruleset,
97
- reference=await self.aretrieve_compact(refind_q, final_limit=30),
100
+ reference=f"{await self.aretrieve_compact(refind_q, final_limit=self.ref_limit)}\n\n"
101
+ f"You can use Reference above to rewrite the `{subsec.__class__.__name__}`.\n"
102
+ f"You should Always use `{subsec.language}` as written language, "
103
+ f"which is the original language of the `{subsec.title}`. "
104
+ f"since rewrite a `{subsec.__class__.__name__}` in a different language is usually a bad choice",
98
105
  )
@@ -8,7 +8,7 @@ from fabricatio.capabilities.advanced_judge import AdvancedJudge
8
8
  from fabricatio.capabilities.propose import Propose
9
9
  from fabricatio.config import configs
10
10
  from fabricatio.journal import logger
11
- from fabricatio.models.extra.patches import RuleSetBriefingPatch
11
+ from fabricatio.models.extra.patches import RuleSetMetadata
12
12
  from fabricatio.models.extra.problem import Improvement
13
13
  from fabricatio.models.extra.rule import Rule, RuleSet
14
14
  from fabricatio.models.generic import Display, WithBriefing
@@ -42,12 +42,17 @@ class Check(AdvancedJudge, Propose):
42
42
  - Returns None if any step in rule generation fails
43
43
  - Uses `alist_str` for requirement breakdown and iterative rule proposal
44
44
  """
45
- rule_reqs = await self.alist_str(
46
- TEMPLATE_MANAGER.render_template(
47
- configs.templates.ruleset_requirement_breakdown_template, {"ruleset_requirement": ruleset_requirement}
48
- ),
49
- rule_count,
50
- **override_kwargs(kwargs, default=None),
45
+ rule_reqs = (
46
+ await self.alist_str(
47
+ TEMPLATE_MANAGER.render_template(
48
+ configs.templates.ruleset_requirement_breakdown_template,
49
+ {"ruleset_requirement": ruleset_requirement},
50
+ ),
51
+ rule_count,
52
+ **override_kwargs(kwargs, default=None),
53
+ )
54
+ if rule_count > 1
55
+ else [ruleset_requirement]
51
56
  )
52
57
 
53
58
  if rule_reqs is None:
@@ -65,7 +70,7 @@ class Check(AdvancedJudge, Propose):
65
70
  return None
66
71
 
67
72
  ruleset_patch = await self.propose(
68
- RuleSetBriefingPatch,
73
+ RuleSetMetadata,
69
74
  f"{ruleset_requirement}\n\nYou should use `{detect_language(ruleset_requirement)}`!",
70
75
  **override_kwargs(kwargs, default=None),
71
76
  )
@@ -99,7 +104,8 @@ class Check(AdvancedJudge, Propose):
99
104
  - Proposes Improvement only when violation is confirmed
100
105
  """
101
106
  if judge := await self.evidently_judge(
102
- f"# Content to exam\n{input_text}\n\n# Rule Must to follow\n{rule.display()}\nDoes `Content to exam` provided above violate the `Rule Must to follow` provided above?",
107
+ f"# Content to exam\n{input_text}\n\n# Rule Must to follow\n{rule.display()}\nDoes `Content to exam` provided above violate the `{rule.name}` provided above?"
108
+ f"should I take some measure to fix that violation? true for I do need, false for I don't need.",
103
109
  **override_kwargs(kwargs, default=None),
104
110
  ):
105
111
  logger.info(f"Rule `{rule.name}` violated: \n{judge.display()}")
@@ -57,7 +57,7 @@ class Correct(Rating, Propose):
57
57
  self.decide_solution(
58
58
  ps,
59
59
  **fallback_kwargs(
60
- kwargs, topic=f"which solution is better to deal this problem {ps.problem.compact()}\n\n"
60
+ kwargs, topic=f"which solution is better to deal this problem {ps.problem.description}\n\n"
61
61
  ),
62
62
  )
63
63
  for ps in improvement.problem_solutions
@@ -167,13 +167,12 @@ class Correct(Rating, Propose):
167
167
  logger.info(f"Improvement {improvement.focused_on} not decided, start deciding...")
168
168
  improvement = await self.decide_improvement(improvement, **override_kwargs(kwargs, default=None))
169
169
 
170
- for ps in improvement.problem_solutions:
171
- logger.info(f"Fixing troubling obj {obj.__class__.__name__} when deal with problem: {ps.problem.name}")
170
+ total = len(improvement.problem_solutions)
171
+ for idx, ps in enumerate(improvement.problem_solutions):
172
+ logger.info(f"[{idx + 1}/{total}] Fixing {obj.__class__.__name__} for problem `{ps.problem.name}`")
172
173
  fixed_obj = await self.fix_troubled_obj(obj, ps, reference, **kwargs)
173
174
  if fixed_obj is None:
174
- logger.error(
175
- f"Failed to fix troubling obj {obj.__class__.__name__} when deal with problem: {ps.problem.name}",
176
- )
175
+ logger.error(f"[{idx + 1}/{total}] Failed to fix problem `{ps.problem.name}`")
177
176
  return None
178
177
  obj = fixed_obj
179
178
  return obj