fabricatio 0.2.8.dev3__tar.gz → 0.2.9.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 (155) hide show
  1. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/PKG-INFO +1 -1
  2. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/make_diary/diary.py +2 -2
  3. fabricatio-0.2.9.dev0/examples/rules/draft_ruleset.py +50 -0
  4. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/task_handle/handle_task.py +2 -2
  5. fabricatio-0.2.9.dev0/examples/write_article/.gitignore +3 -0
  6. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/write_article/write_article.py +10 -11
  7. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/write_outline/write_outline.py +3 -2
  8. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/write_outline/write_outline_corrected.py +2 -2
  9. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/pyproject.toml +2 -2
  10. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/__init__.py +4 -11
  11. fabricatio-0.2.9.dev0/python/fabricatio/actions/__init__.py +1 -0
  12. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/actions/article.py +63 -87
  13. fabricatio-0.2.9.dev0/python/fabricatio/actions/article_rag.py +100 -0
  14. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/actions/rag.py +2 -1
  15. fabricatio-0.2.9.dev0/python/fabricatio/actions/rules.py +39 -0
  16. fabricatio-0.2.9.dev0/python/fabricatio/capabilities/__init__.py +1 -0
  17. fabricatio-0.2.9.dev0/python/fabricatio/capabilities/censor.py +90 -0
  18. fabricatio-0.2.9.dev0/python/fabricatio/capabilities/check.py +195 -0
  19. fabricatio-0.2.9.dev0/python/fabricatio/capabilities/correct.py +209 -0
  20. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/capabilities/rag.py +5 -4
  21. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/capabilities/rating.py +65 -16
  22. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/capabilities/review.py +1 -1
  23. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/capabilities/task.py +2 -1
  24. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/config.py +11 -3
  25. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/action.py +14 -7
  26. fabricatio-0.2.9.dev0/python/fabricatio/models/adv_kwargs_types.py +25 -0
  27. fabricatio-0.2.9.dev0/python/fabricatio/models/extra/__init__.py +1 -0
  28. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/extra/advanced_judge.py +5 -2
  29. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/extra/article_base.py +3 -20
  30. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/extra/article_main.py +2 -3
  31. fabricatio-0.2.9.dev0/python/fabricatio/models/extra/patches.py +20 -0
  32. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/extra/problem.py +41 -8
  33. fabricatio-0.2.9.dev0/python/fabricatio/models/extra/rule.py +40 -0
  34. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/generic.py +310 -55
  35. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/kwargs_types.py +23 -17
  36. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/task.py +1 -1
  37. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/tool.py +149 -14
  38. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/usages.py +50 -42
  39. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/parser.py +7 -8
  40. fabricatio-0.2.8.dev3/python/fabricatio/_rust_instances.py → fabricatio-0.2.9.dev0/python/fabricatio/rust_instances.py +1 -1
  41. fabricatio-0.2.9.dev0/python/fabricatio/workflows/__init__.py +1 -0
  42. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/src/lib.rs +1 -1
  43. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/check_string.hbs +4 -0
  44. fabricatio-0.2.9.dev0/templates/built-in/fix_troubled_obj.hbs +14 -0
  45. fabricatio-0.2.9.dev0/templates/built-in/fix_troubled_string.hbs +19 -0
  46. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/liststr.hbs +3 -2
  47. fabricatio-0.2.9.dev0/templates/built-in/rule_requirement.hbs +12 -0
  48. fabricatio-0.2.9.dev0/templates/built-in/ruleset_requirement_breakdown.hbs +19 -0
  49. fabricatio-0.2.9.dev0/templates.tar.gz +0 -0
  50. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/uv.lock +53 -53
  51. fabricatio-0.2.8.dev3/python/fabricatio/actions/article_rag.py +0 -89
  52. fabricatio-0.2.8.dev3/python/fabricatio/capabilities/check.py +0 -97
  53. fabricatio-0.2.8.dev3/python/fabricatio/capabilities/correct.py +0 -166
  54. fabricatio-0.2.8.dev3/python/fabricatio/models/extra/rule.py +0 -23
  55. fabricatio-0.2.8.dev3/templates/built-in/correct.hbs +0 -15
  56. fabricatio-0.2.8.dev3/templates.tar.gz +0 -0
  57. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/.github/workflows/build-package.yaml +0 -0
  58. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/.github/workflows/ruff.yaml +0 -0
  59. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/.github/workflows/tests.yaml +0 -0
  60. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/.gitignore +0 -0
  61. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/.python-version +0 -0
  62. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/Cargo.lock +0 -0
  63. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/Cargo.toml +0 -0
  64. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/LICENSE +0 -0
  65. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/Makefile +0 -0
  66. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/README.md +0 -0
  67. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/correct/correct.py +0 -0
  68. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/correct/correct_loop.py +0 -0
  69. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/extract_and_inject/.gitignore +0 -0
  70. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/extract_and_inject/article_rag.py +0 -0
  71. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/extract_and_inject/ask.py +0 -0
  72. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/extract_and_inject/extract_and_inject.py +0 -0
  73. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/extract_article/extract.py +0 -0
  74. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/llm_usages/llm_usage.py +0 -0
  75. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/make_a_rating/rating.py +0 -0
  76. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/make_diary/commits.json +0 -0
  77. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/minor/hello_fabricatio.py +0 -0
  78. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/minor/write_a_poem.py +0 -0
  79. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/propose_task/propose.py +0 -0
  80. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/reviewer/review.py +0 -0
  81. {fabricatio-0.2.8.dev3/examples/write_article → fabricatio-0.2.9.dev0/examples/rules}/.gitignore +0 -0
  82. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/search_bibtex/.gitignore +0 -0
  83. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/search_bibtex/search.py +0 -0
  84. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/simple_chat/chat.py +0 -0
  85. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/simple_rag/simple_rag.py +0 -0
  86. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/write_article/article_rag.py +0 -0
  87. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/examples/write_outline/.gitignore +0 -0
  88. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/actions/output.py +0 -0
  89. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/capabilities/advanced_judge.py +0 -0
  90. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/capabilities/propose.py +0 -0
  91. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/core.py +0 -0
  92. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/decorators.py +0 -0
  93. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/fs/__init__.py +0 -0
  94. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/fs/curd.py +0 -0
  95. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/fs/readers.py +0 -0
  96. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/journal.py +0 -0
  97. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/events.py +0 -0
  98. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/extra/article_essence.py +0 -0
  99. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/extra/article_outline.py +0 -0
  100. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/extra/article_proposal.py +0 -0
  101. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/role.py +0 -0
  102. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/models/utils.py +0 -0
  103. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/py.typed +0 -0
  104. /fabricatio-0.2.8.dev3/python/fabricatio/_rust.pyi → /fabricatio-0.2.9.dev0/python/fabricatio/rust.pyi +0 -0
  105. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/toolboxes/__init__.py +0 -0
  106. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  107. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/toolboxes/fs.py +0 -0
  108. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/utils.py +0 -0
  109. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/workflows/articles.py +0 -0
  110. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/python/fabricatio/workflows/rag.py +0 -0
  111. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/src/bib_tools.rs +0 -0
  112. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/src/hash.rs +0 -0
  113. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/src/hbs_helpers.rs +0 -0
  114. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/src/templates.rs +0 -0
  115. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/as_prompt.hbs +0 -0
  116. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  117. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/claude-xml.hbs +0 -0
  118. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/clean-up-code.hbs +0 -0
  119. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/co_validation.hbs +0 -0
  120. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/create_json_obj.hbs +0 -0
  121. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  122. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/dependencies.hbs +0 -0
  123. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/document-the-code.hbs +0 -0
  124. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/draft_rating_criteria.hbs +0 -0
  125. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/draft_rating_manual.hbs +0 -0
  126. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  127. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  128. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  129. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  130. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  131. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/fix-bugs.hbs +0 -0
  132. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/generic_string.hbs +0 -0
  133. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/improve-performance.hbs +0 -0
  134. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/make_choice.hbs +0 -0
  135. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/make_judgment.hbs +0 -0
  136. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/pathstr.hbs +0 -0
  137. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/rate_fine_grind.hbs +0 -0
  138. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/refactor.hbs +0 -0
  139. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/refined_query.hbs +0 -0
  140. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/retrieved_display.hbs +0 -0
  141. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  142. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/review_string.hbs +0 -0
  143. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/task_briefing.hbs +0 -0
  144. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/web-ctf-solver.hbs +0 -0
  145. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/write-git-commit.hbs +0 -0
  146. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/write-github-pull-request.hbs +0 -0
  147. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/templates/built-in/write-github-readme.hbs +0 -0
  148. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/tests/test_config.py +0 -0
  149. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/tests/test_models/test_action.py +0 -0
  150. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/tests/test_models/test_advanced.py +0 -0
  151. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/tests/test_models/test_generic.py +0 -0
  152. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/tests/test_models/test_role.py +0 -0
  153. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/tests/test_models/test_task.py +0 -0
  154. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.dev0}/tests/test_models/test_tool.py +0 -0
  155. {fabricatio-0.2.8.dev3 → fabricatio-0.2.9.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.8.dev3
3
+ Version: 0.2.9.dev0
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -4,7 +4,7 @@ import asyncio
4
4
  from datetime import datetime
5
5
  from typing import Optional, Set, Unpack
6
6
 
7
- from fabricatio import Action, Event, Role, Task, WorkFlow, fs_toolbox, logger
7
+ from fabricatio import Action, Event, Role, Task, WorkFlow, logger, toolboxes
8
8
  from fabricatio.fs.readers import safe_json_read
9
9
  from fabricatio.models.tool import ToolBox
10
10
  from pydantic import Field
@@ -48,7 +48,7 @@ class WriteDiary(Action):
48
48
  class DumpText(Action):
49
49
  """Dump the text to a file."""
50
50
 
51
- toolboxes: Set[ToolBox] = Field(default_factory=lambda: {fs_toolbox})
51
+ toolboxes: Set[ToolBox] = Field(default_factory=lambda: {toolboxes.fs_toolbox})
52
52
  output_key: str = "task_output"
53
53
 
54
54
  async def _execute(self, task_input: Task, dump_text: str, **_: Unpack) -> Optional[str]:
@@ -0,0 +1,50 @@
1
+ """Example of using the library."""
2
+
3
+ import asyncio
4
+ from typing import TYPE_CHECKING
5
+
6
+ from fabricatio import Event, Role, WorkFlow, logger
7
+ from fabricatio.actions.output import PersistentAll
8
+ from fabricatio.actions.rules import DraftRuleSet
9
+ from fabricatio.models.task import Task
10
+ from fabricatio.utils import ok
11
+
12
+ if TYPE_CHECKING:
13
+ from fabricatio.models.extra.rule import RuleSet
14
+
15
+
16
+ async def main() -> None:
17
+ """Main function."""
18
+ Role(
19
+ name="Undergraduate Researcher",
20
+ llm_temperature=1.15,
21
+ llm_model="openai/deepseek-v3-250324",
22
+ llm_rpm=1000,
23
+ llm_tpm=3000000,
24
+ llm_max_tokens=8190,
25
+ registry={
26
+ Event.quick_instantiate(ns := "article"): WorkFlow(
27
+ name="write ruleset",
28
+ description="Generate an outline for an article. dump the outline to the given path. in typst format.",
29
+ steps=(
30
+ DraftRuleSet(
31
+ ruleset_requirement="1.when try to use an article as reference cited in our article, you should obey the format like (author1, author2 et al., YYYY)\n"
32
+ "2.we use typst to generate numeric citation. For example, for an article whose `bibtex_key` is `YanWindEnergy2018`, you can create a numeric citation by typing `#cite(<YanWindEnergy2018>)`(note that `bibtex_key` with `<` and `>` wrapped is needed), those notations could automatically be processed and output by compiler as a numeric citation like `[1]` in the upper right corner of text.\n"
33
+ "3.in addition, since `#cite()` can ONLY cite ONE article at once, we need use multiple `#cite()` notations to cite multiple articles, for example, there are three articles whose `bibtex_key` are `YanWindEnergy2018`, `YanWindEnergy2019`, `YanWindEnergy2020, you can cite them three as numeric citation by typing `#cite(<YanWindEnergy2018>)#cite(<YanWindEnergy2019>)#cite(<YanWindEnergy2020>)` those notations could automatically be processed and output by compiler as a numeric citation like `[1,2,3]` in the upper right corner of text.\n"
34
+ "4.to cover more references, we usually cite more than one articles that have similar opinions in a single sentence if possible.\n"
35
+ "5.when using `#cite()` notation, you must be aware of the cite key should be wrapped by `<` and `>`, compiler wont let it pass compilation otherwise.",
36
+ rule_count=5,
37
+ ).to_task_output(),
38
+ PersistentAll(persist_dir="persistent"),
39
+ ),
40
+ )
41
+ },
42
+ )
43
+
44
+ proposed_task: Task[RuleSet] = Task(name="write an ruleset")
45
+ ruleset = ok(await proposed_task.delegate(ns), "Failed to generate ruleset")
46
+ logger.success(f"The rule is: \n{ruleset.display()}")
47
+
48
+
49
+ if __name__ == "__main__":
50
+ asyncio.run(main())
@@ -3,7 +3,7 @@
3
3
  import asyncio
4
4
  from typing import Any, Set, Unpack
5
5
 
6
- from fabricatio import Action, Event, PythonCapture, Role, Task, ToolBox, WorkFlow, fs_toolbox, logger
6
+ from fabricatio import Action, Event, PythonCapture, Role, Task, ToolBox, WorkFlow, logger, toolboxes
7
7
  from pydantic import Field
8
8
 
9
9
 
@@ -23,7 +23,7 @@ class WriteCode(Action):
23
23
  class DumpText(Action):
24
24
  """Dump the text to a file."""
25
25
 
26
- toolboxes: Set[ToolBox] = Field(default_factory=lambda: {fs_toolbox})
26
+ toolboxes: Set[ToolBox] = Field(default_factory=lambda: {toolboxes.fs_toolbox})
27
27
  output_key: str = "task_output"
28
28
 
29
29
  async def _execute(self, task_input: Task, dump_text: str, **_: Unpack) -> Any:
@@ -0,0 +1,3 @@
1
+ article_briefing.txt
2
+ out.typ
3
+ persistent
@@ -23,11 +23,10 @@ async def main() -> None:
23
23
  Role(
24
24
  name="Undergraduate Researcher",
25
25
  description="Write an outline for an article in typst format.",
26
- llm_top_p=0.8,
27
26
  llm_temperature=1.15,
28
27
  llm_model="openai/deepseek-v3-250324",
29
28
  llm_rpm=1000,
30
- llm_tpm=1000000,
29
+ llm_tpm=3000000,
31
30
  llm_max_tokens=8190,
32
31
  registry={
33
32
  Event.quick_instantiate(ns := "article"): WorkFlow(
@@ -35,15 +34,15 @@ async def main() -> None:
35
34
  description="Generate an outline for an article. dump the outline to the given path. in typst format.",
36
35
  steps=(
37
36
  GenerateArticleProposal(llm_temperature=1.18),
38
- GenerateInitialOutline(output_key="article_outline",llm_temperature=1.21, llm_top_p=0.5),
39
- FixIntrospectedErrors(output_key="article_outline"),
40
- FixIllegalReferences(output_key="article_outline"),
41
- TweakOutlineBackwardRef(output_key="article_outline"),
42
- TweakOutlineForwardRef(output_key="article_outline"),
43
- FixIllegalReferences(output_key="article_outline"),
44
- GenerateArticle(output_key="article", llm_temperature=1.2, llm_top_p=0.45),
37
+ GenerateInitialOutline(output_key="article_outline",llm_temperature=1.21),
38
+ FixIntrospectedErrors(output_key="article_outline",),
39
+ FixIllegalReferences(output_key="article_outline",),
40
+ TweakOutlineBackwardRef(output_key="article_outline",),
41
+ TweakOutlineForwardRef(output_key="article_outline",),
42
+ FixIllegalReferences(output_key="article_outline",),
43
+ GenerateArticle(output_key="article", llm_temperature=1.2),
45
44
  PersistentAll,
46
- TweakArticleRAG(output_key="to_dump", llm_temperature=1.2, llm_top_p=0.45),
45
+ TweakArticleRAG(output_key="to_dump", llm_temperature=1.2),
47
46
  DumpFinalizedOutput(output_key="task_output"),
48
47
  PersistentAll,
49
48
  ),
@@ -51,7 +50,7 @@ async def main() -> None:
51
50
  article_briefing=Path("./article_briefing.txt").read_text(),
52
51
  dump_path="out.typ",
53
52
  persist_dir="persistent",
54
- collection_name="article_essence"
53
+ collection_name="article_essence_0324"
55
54
  )
56
55
  },
57
56
  )
@@ -2,7 +2,8 @@
2
2
 
3
3
  import asyncio
4
4
 
5
- from fabricatio import Event, Role, WriteOutlineWorkFlow, logger
5
+ from fabricatio import Event, Role, logger
6
+ from fabricatio.workflows.articles import WriteOutlineCorrectedWorkFlow
6
7
 
7
8
 
8
9
  async def main() -> None:
@@ -10,7 +11,7 @@ async def main() -> None:
10
11
  role = Role(
11
12
  name="Undergraduate Researcher",
12
13
  description="Write an outline for an article in typst format.",
13
- registry={Event.quick_instantiate(ns := "article"): WriteOutlineWorkFlow},
14
+ registry={Event.quick_instantiate(ns := "article"): WriteOutlineCorrectedWorkFlow},
14
15
  )
15
16
 
16
17
  proposed_task = await role.propose_task(
@@ -3,7 +3,7 @@
3
3
  import asyncio
4
4
 
5
5
  from fabricatio import Event, Role, WorkFlow, logger
6
- from fabricatio.actions.article import CorrectOutline, CorrectProposal, GenerateArticleProposal, GenerateOutline
6
+ from fabricatio.actions.article import CorrectOutline, CorrectProposal, GenerateArticleProposal, GenerateInitialOutline
7
7
  from fabricatio.actions.output import DumpFinalizedOutput
8
8
 
9
9
 
@@ -25,7 +25,7 @@ async def main() -> None:
25
25
  llm_model="deepseek/deepseek-reasoner",
26
26
  llm_temperature=1.3,
27
27
  ),
28
- GenerateOutline(llm_model="deepseek/deepseek-chat", llm_temperature=1.4, llm_top_p=0.5),
28
+ GenerateInitialOutline(llm_model="deepseek/deepseek-chat", llm_temperature=1.4, llm_top_p=0.5),
29
29
  CorrectOutline(output_key="to_dump", llm_temperature=1.4, llm_top_p=0.45),
30
30
  DumpFinalizedOutput(output_key="task_output"),
31
31
  ),
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.8-dev3"
3
+ version = "0.2.9-dev0"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -57,7 +57,7 @@ build-backend = "maturin"
57
57
 
58
58
  [tool.maturin]
59
59
  python-source = "python"
60
- module-name = "fabricatio._rust"
60
+ module-name = "fabricatio.rust"
61
61
  data = "extra"
62
62
  [dependency-groups]
63
63
  dev = [
@@ -1,10 +1,6 @@
1
1
  """Fabricatio is a Python library for building llm app using event-based agent structure."""
2
2
 
3
- from importlib.util import find_spec
4
-
5
- from fabricatio import actions, toolboxes, workflows
6
- from fabricatio._rust import BibManager
7
- from fabricatio._rust_instances import TEMPLATE_MANAGER
3
+ from fabricatio import actions, capabilities, toolboxes, workflows
8
4
  from fabricatio.core import env
9
5
  from fabricatio.journal import logger
10
6
  from fabricatio.models import extra
@@ -14,6 +10,8 @@ from fabricatio.models.role import Role
14
10
  from fabricatio.models.task import Task
15
11
  from fabricatio.models.tool import ToolBox
16
12
  from fabricatio.parser import Capture, GenericCapture, JsonCapture, PythonCapture
13
+ from fabricatio.rust import BibManager
14
+ from fabricatio.rust_instances import TEMPLATE_MANAGER
17
15
 
18
16
  __all__ = [
19
17
  "TEMPLATE_MANAGER",
@@ -29,15 +27,10 @@ __all__ = [
29
27
  "ToolBox",
30
28
  "WorkFlow",
31
29
  "actions",
30
+ "capabilities",
32
31
  "env",
33
32
  "extra",
34
33
  "logger",
35
34
  "toolboxes",
36
35
  "workflows",
37
36
  ]
38
-
39
-
40
- if find_spec("pymilvus"):
41
- from fabricatio.capabilities.rag import RAG
42
-
43
- __all__ += ["RAG"]
@@ -0,0 +1 @@
1
+ """A module containing some builtin actins."""
@@ -4,22 +4,26 @@ from asyncio import gather
4
4
  from pathlib import Path
5
5
  from typing import Any, Callable, List, Optional
6
6
 
7
- from fabricatio._rust import BibManager
8
- from fabricatio.capabilities.advanced_judge import AdvancedJudge
7
+ from more_itertools import filter_map
8
+
9
+ from fabricatio.capabilities.censor import Censor
10
+ from fabricatio.capabilities.correct import Correct
11
+ from fabricatio.capabilities.propose import Propose
9
12
  from fabricatio.fs import safe_text_read
10
13
  from fabricatio.journal import logger
11
14
  from fabricatio.models.action import Action
12
- from fabricatio.models.extra.article_base import ArticleRefPatch
15
+ from fabricatio.models.extra.article_base import ArticleRefSequencePatch
13
16
  from fabricatio.models.extra.article_essence import ArticleEssence
14
17
  from fabricatio.models.extra.article_main import Article
15
18
  from fabricatio.models.extra.article_outline import ArticleOutline
16
19
  from fabricatio.models.extra.article_proposal import ArticleProposal
20
+ from fabricatio.models.extra.rule import RuleSet
17
21
  from fabricatio.models.task import Task
22
+ from fabricatio.rust import BibManager
18
23
  from fabricatio.utils import ok
19
- from more_itertools import filter_map
20
24
 
21
25
 
22
- class ExtractArticleEssence(Action):
26
+ class ExtractArticleEssence(Action, Propose):
23
27
  """Extract the essence of article(s) in text format from the paths specified in the task dependencies.
24
28
 
25
29
  Notes:
@@ -47,11 +51,11 @@ class ExtractArticleEssence(Action):
47
51
  out = []
48
52
 
49
53
  for ess in await self.propose(
50
- ArticleEssence,
51
- [
52
- f"{c}\n\n\nBased the provided academic article above, you need to extract the essence from it."
53
- for c in contents
54
- ],
54
+ ArticleEssence,
55
+ [
56
+ f"{c}\n\n\nBased the provided academic article above, you need to extract the essence from it."
57
+ for c in contents
58
+ ],
55
59
  ):
56
60
  if ess is None:
57
61
  logger.warning("Could not extract article essence")
@@ -91,7 +95,7 @@ class FixArticleEssence(Action):
91
95
  return out
92
96
 
93
97
 
94
- class GenerateArticleProposal(Action):
98
+ class GenerateArticleProposal(Action, Propose):
95
99
  """Generate an outline for the article based on the extracted essence."""
96
100
 
97
101
  output_key: str = "article_proposal"
@@ -133,7 +137,7 @@ class GenerateArticleProposal(Action):
133
137
  return proposal
134
138
 
135
139
 
136
- class GenerateInitialOutline(Action):
140
+ class GenerateInitialOutline(Action, Propose):
137
141
  """Generate the initial article outline based on the article proposal."""
138
142
 
139
143
  output_key: str = "initial_article_outline"
@@ -153,38 +157,29 @@ class GenerateInitialOutline(Action):
153
157
  ).update_ref(article_proposal)
154
158
 
155
159
 
156
- class FixIntrospectedErrors(Action):
160
+ class FixIntrospectedErrors(Action, Censor):
157
161
  """Fix introspected errors in the article outline."""
158
162
 
159
163
  output_key: str = "introspected_errors_fixed_outline"
160
164
  """The key of the output data."""
161
165
 
166
+ ruleset: Optional[RuleSet] = None
167
+ """The ruleset to use to fix the introspected errors."""
168
+
162
169
  async def _execute(
163
170
  self,
164
171
  article_outline: ArticleOutline,
165
- supervisor_check: bool = False,
172
+ ruleset: Optional[RuleSet] = None,
166
173
  **_,
167
174
  ) -> Optional[ArticleOutline]:
168
- introspect_manual = ok(
169
- await self.draft_rating_manual(
170
- topic=(
171
- intro_topic
172
- := "Fix the error in the article outline, make sure there is no more error in the article outline."
173
- ),
174
- ),
175
- "Could not generate the rating manual.",
176
- )
177
-
178
175
  while pack := article_outline.find_introspected():
179
176
  component, err = ok(pack)
180
177
  logger.warning(f"Found introspected error: {err}")
181
178
  corrected = ok(
182
- await self.correct_obj(
179
+ await self.censor_obj(
183
180
  component,
184
- reference=f"# Original Article Outline\n{article_outline.display()}\n# Error Need to be fixed\n{err}",
185
- topic=intro_topic,
186
- rating_manual=introspect_manual,
187
- supervisor_check=supervisor_check,
181
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
182
+ reference=f"# Original Article Outline\n{article_outline.display()}\n# Some Basic errors found from `{component.title}` that need to be fixed\n{err}",
188
183
  ),
189
184
  "Could not correct the component.",
190
185
  )
@@ -193,38 +188,29 @@ class FixIntrospectedErrors(Action):
193
188
  return article_outline
194
189
 
195
190
 
196
- class FixIllegalReferences(Action):
191
+ class FixIllegalReferences(Action, Censor):
197
192
  """Fix illegal references in the article outline."""
198
193
 
199
194
  output_key: str = "illegal_references_fixed_outline"
200
195
  """The key of the output data."""
201
196
 
197
+ ruleset: Optional[RuleSet] = None
198
+ """Ruleset to use to fix the illegal references."""
199
+
202
200
  async def _execute(
203
201
  self,
204
202
  article_outline: ArticleOutline,
205
- supervisor_check: bool = False,
203
+ ruleset: Optional[RuleSet] = None,
206
204
  **_,
207
205
  ) -> Optional[ArticleOutline]:
208
- ref_manual = ok(
209
- await self.draft_rating_manual(
210
- topic=(
211
- ref_topic
212
- := "Fix the internal referring error, make sure there is no more `ArticleRef` pointing to a non-existing article component."
213
- ),
214
- ),
215
- "Could not generate the rating manual.",
216
- )
217
-
218
206
  while pack := article_outline.find_illegal_ref(gather_identical=True):
219
207
  refs, err = ok(pack)
220
208
  logger.warning(f"Found illegal referring error: {err}")
221
209
  corrected_ref = ok(
222
- await self.correct_obj(
210
+ await self.censor_obj(
223
211
  refs[0], # pyright: ignore [reportIndexIssue]
224
- reference=f"# Original Article Outline\n{article_outline.display()}\n# Error Need to be fixed\n{err}",
225
- topic=ref_topic,
226
- rating_manual=ref_manual,
227
- supervisor_check=supervisor_check,
212
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
213
+ reference=f"# Original Article Outline\n{article_outline.display()}\n# Some Basic errors found that need to be fixed\n{err}",
228
214
  )
229
215
  )
230
216
  for ref in refs:
@@ -233,43 +219,40 @@ class FixIllegalReferences(Action):
233
219
  return article_outline.update_ref(article_outline)
234
220
 
235
221
 
236
- class TweakOutlineForwardRef(Action, AdvancedJudge):
222
+ class TweakOutlineForwardRef(Action, Censor):
237
223
  """Tweak the forward references in the article outline.
238
224
 
239
225
  Ensures that the conclusions of the current chapter effectively support the analysis of subsequent chapters.
240
226
  """
241
227
 
242
228
  output_key: str = "article_outline_fw_ref_checked"
229
+ ruleset: Optional[RuleSet] = None
230
+ """Ruleset to use to fix the illegal references."""
243
231
 
244
- async def _execute(self, article_outline: ArticleOutline, supervisor_check: bool = False, **cxt) -> ArticleOutline:
232
+ async def _execute(
233
+ self, article_outline: ArticleOutline, ruleset: Optional[RuleSet] = None, **cxt
234
+ ) -> ArticleOutline:
245
235
  return await self._inner(
246
236
  article_outline,
247
- supervisor_check,
248
- topic="Ensure conclusions support the analysis of subsequent chapters, sections or subsections.",
237
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
249
238
  field_name="support_to",
250
239
  )
251
240
 
252
- async def _inner(
253
- self, article_outline: ArticleOutline, supervisor_check: bool, topic: str, field_name: str
254
- ) -> ArticleOutline:
255
- tweak_support_to_manual = ok(
256
- await self.draft_rating_manual(topic),
257
- "Could not generate the rating manual.",
258
- )
241
+ async def _inner(self, article_outline: ArticleOutline, ruleset: RuleSet, field_name: str) -> ArticleOutline:
259
242
  for a in article_outline.iter_dfs():
260
- if await self.evidently_judge(
243
+ if judge := await self.evidently_judge(
261
244
  f"{article_outline.as_prompt()}\n\n{a.display()}\n"
262
245
  f"Does the `{a.__class__.__name__}`'s `{field_name}` field need to be extended or tweaked?"
263
246
  ):
264
- patch = ArticleRefPatch.default()
247
+ patch = ArticleRefSequencePatch.default()
265
248
  patch.tweaked = getattr(a, field_name)
266
249
 
267
- await self.correct_obj_inplace(
250
+ await self.censor_obj_inplace(
268
251
  patch,
269
- topic=topic,
270
- reference=f"{article_outline.as_prompt()}\nThe Article component whose `{field_name}` field needs to be extended or tweaked",
271
- rating_manual=tweak_support_to_manual,
272
- supervisor_check=supervisor_check,
252
+ ruleset=ruleset,
253
+ reference=f"{article_outline.as_prompt()}\n"
254
+ f"The Article component titled `{a.title}` whose `{field_name}` field needs to be extended or tweaked.\n"
255
+ f"# Judgement\n{judge.display()}",
273
256
  )
274
257
  return article_outline
275
258
 
@@ -281,44 +264,41 @@ class TweakOutlineBackwardRef(TweakOutlineForwardRef):
281
264
  """
282
265
 
283
266
  output_key: str = "article_outline_bw_ref_checked"
267
+ ruleset: Optional[RuleSet] = None
284
268
 
285
- async def _execute(self, article_outline: ArticleOutline, supervisor_check: bool = False, **cxt) -> ArticleOutline:
269
+ async def _execute(
270
+ self, article_outline: ArticleOutline, ruleset: Optional[RuleSet] = None, **cxt
271
+ ) -> ArticleOutline:
286
272
  return await self._inner(
287
273
  article_outline,
288
- supervisor_check,
289
- topic="Ensure the dependencies of the current chapter are neither abused nor missing.",
274
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
290
275
  field_name="depend_on",
291
276
  )
292
277
 
293
278
 
294
- class GenerateArticle(Action):
279
+ class GenerateArticle(Action, Censor):
295
280
  """Generate the article based on the outline."""
296
281
 
297
282
  output_key: str = "article"
298
283
  """The key of the output data."""
284
+ ruleset: Optional[RuleSet] = None
299
285
 
300
286
  async def _execute(
301
287
  self,
302
288
  article_outline: ArticleOutline,
303
- supervisor_check: bool = False,
289
+ ruleset: Optional[RuleSet] = None,
304
290
  **_,
305
291
  ) -> Optional[Article]:
306
292
  article: Article = Article.from_outline(ok(article_outline, "Article outline not specified.")).update_ref(
307
293
  article_outline
308
294
  )
309
295
 
310
- write_para_manual = ok(
311
- await self.draft_rating_manual(w_topic := "write the following paragraph in the subsection.")
312
- )
313
-
314
296
  await gather(
315
297
  *[
316
- self.correct_obj_inplace(
298
+ self.censor_obj_inplace(
317
299
  subsec,
300
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
318
301
  reference=f"# Original Article Outline\n{article_outline.display()}\n# Error Need to be fixed\n{err}",
319
- topic=w_topic,
320
- rating_manual=write_para_manual,
321
- supervisor_check=supervisor_check,
322
302
  )
323
303
  for _, __, subsec in article.iter_subsections()
324
304
  if (err := subsec.introspect())
@@ -329,18 +309,16 @@ class GenerateArticle(Action):
329
309
  return article
330
310
 
331
311
 
332
- class CorrectProposal(Action):
312
+ class CorrectProposal(Action, Censor):
333
313
  """Correct the proposal of the article."""
334
314
 
335
315
  output_key: str = "corrected_proposal"
336
316
 
337
317
  async def _execute(self, article_proposal: ArticleProposal, **_) -> Any:
338
- return (await self.censor_obj(article_proposal, reference=article_proposal.referenced)).update_ref(
339
- article_proposal
340
- )
318
+ raise NotImplementedError("Not implemented.")
341
319
 
342
320
 
343
- class CorrectOutline(Action):
321
+ class CorrectOutline(Action, Correct):
344
322
  """Correct the outline of the article."""
345
323
 
346
324
  output_key: str = "corrected_outline"
@@ -351,12 +329,10 @@ class CorrectOutline(Action):
351
329
  article_outline: ArticleOutline,
352
330
  **_,
353
331
  ) -> ArticleOutline:
354
- return (await self.censor_obj(article_outline, reference=article_outline.referenced.as_prompt())).update_ref(
355
- article_outline
356
- )
332
+ raise NotImplementedError("Not implemented.")
357
333
 
358
334
 
359
- class CorrectArticle(Action):
335
+ class CorrectArticle(Action, Correct):
360
336
  """Correct the article based on the outline."""
361
337
 
362
338
  output_key: str = "corrected_article"
@@ -368,4 +344,4 @@ class CorrectArticle(Action):
368
344
  article_outline: ArticleOutline,
369
345
  **_,
370
346
  ) -> Article:
371
- return await self.censor_obj(article, reference=article_outline.referenced.as_prompt())
347
+ raise NotImplementedError("Not implemented.")
@@ -0,0 +1,100 @@
1
+ """A module for writing articles using RAG (Retrieval-Augmented Generation) capabilities."""
2
+
3
+ from asyncio import gather
4
+ from typing import Optional
5
+
6
+ from fabricatio.capabilities.censor import Censor
7
+ from fabricatio.capabilities.rag import RAG
8
+ from fabricatio.models.action import Action
9
+ from fabricatio.models.extra.article_main import Article, ArticleParagraphSequencePatch, ArticleSubsection
10
+ from fabricatio.models.extra.rule import RuleSet
11
+ from fabricatio.utils import ok
12
+
13
+
14
+ class TweakArticleRAG(Action, RAG, Censor):
15
+ """Write an article based on the provided outline.
16
+
17
+ This class inherits from `Action`, `RAG`, and `Censor` to provide capabilities for writing and refining articles
18
+ using Retrieval-Augmented Generation (RAG) techniques. It processes an article outline, enhances subsections by
19
+ searching for related references, and applies censoring rules to ensure compliance with the provided ruleset.
20
+
21
+ Attributes:
22
+ output_key (str): The key used to store the output of the action.
23
+ ruleset (Optional[RuleSet]): The ruleset to be used for censoring the article.
24
+ """
25
+
26
+ output_key: str = "rag_tweaked_article"
27
+ """The key used to store the output of the action."""
28
+
29
+ ruleset: Optional[RuleSet] = None
30
+ """The ruleset to be used for censoring the article."""
31
+
32
+ async def _execute(
33
+ self,
34
+ article: Article,
35
+ collection_name: str = "article_essence",
36
+ ruleset: Optional[RuleSet] = None,
37
+ parallel: bool = False,
38
+ **cxt,
39
+ ) -> Optional[Article]:
40
+ """Write an article based on the provided outline.
41
+
42
+ This method processes the article outline, either in parallel or sequentially, by enhancing each subsection
43
+ with relevant references and applying censoring rules.
44
+
45
+ Args:
46
+ article (Article): The article to be processed.
47
+ collection_name (str): The name of the collection to view for processing.
48
+ ruleset (Optional[RuleSet]): The ruleset to apply for censoring. If not provided, the class's ruleset is used.
49
+ parallel (bool): If True, process subsections in parallel. Otherwise, process them sequentially.
50
+ **cxt: Additional context parameters.
51
+
52
+ Returns:
53
+ Optional[Article]: The processed article with enhanced subsections and applied censoring rules.
54
+ """
55
+ self.view(collection_name)
56
+
57
+ if parallel:
58
+ await gather(
59
+ *[
60
+ self._inner(article, subsec, ok(ruleset or self.ruleset, "No ruleset provided!"))
61
+ for _, __, subsec in article.iter_subsections()
62
+ ],
63
+ return_exceptions=True,
64
+ )
65
+ else:
66
+ for _, __, subsec in article.iter_subsections():
67
+ await self._inner(article, subsec, ok(ruleset or self.ruleset, "No ruleset provided!"))
68
+ return article
69
+
70
+ async def _inner(self, article: Article, subsec: ArticleSubsection, ruleset: RuleSet) -> None:
71
+ """Enhance a subsection of the article with references and apply censoring rules.
72
+
73
+ This method refines the query for the subsection, retrieves related references, and applies censoring rules
74
+ to the subsection's paragraphs.
75
+
76
+ Args:
77
+ article (Article): The article containing the subsection.
78
+ subsec (ArticleSubsection): The subsection to be enhanced.
79
+ ruleset (RuleSet): The ruleset to apply for censoring.
80
+
81
+ Returns:
82
+ None
83
+ """
84
+ refind_q = ok(
85
+ await self.arefined_query(
86
+ f"{article.referenced.as_prompt()}\n"
87
+ f"# Subsection requiring reference enhancement\n"
88
+ f"{subsec.display()}\n"
89
+ f"# Requirement\n"
90
+ f"Search related articles in the base to find reference candidates, "
91
+ f"prioritizing both original article language and English usage",
92
+ )
93
+ )
94
+ patch = ArticleParagraphSequencePatch.default()
95
+ patch.tweaked = subsec.paragraphs
96
+ await self.censor_obj_inplace(
97
+ patch,
98
+ ruleset=ruleset,
99
+ reference=await self.aretrieve_compact(refind_q, final_limit=30),
100
+ )