fabricatio 0.2.8.dev3__tar.gz → 0.2.8.dev4__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 (146) hide show
  1. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/PKG-INFO +1 -1
  2. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/write_article/write_article.py +9 -10
  3. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/pyproject.toml +1 -1
  4. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/actions/article.py +60 -85
  5. fabricatio-0.2.8.dev4/python/fabricatio/actions/article_rag.py +100 -0
  6. fabricatio-0.2.8.dev4/python/fabricatio/capabilities/censor.py +87 -0
  7. fabricatio-0.2.8.dev4/python/fabricatio/capabilities/check.py +194 -0
  8. fabricatio-0.2.8.dev4/python/fabricatio/capabilities/correct.py +209 -0
  9. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/capabilities/rating.py +61 -13
  10. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/config.py +9 -3
  11. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/action.py +4 -5
  12. fabricatio-0.2.8.dev4/python/fabricatio/models/adv_kwargs_types.py +25 -0
  13. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/extra/advanced_judge.py +5 -2
  14. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/extra/article_base.py +3 -20
  15. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/extra/article_main.py +2 -3
  16. fabricatio-0.2.8.dev4/python/fabricatio/models/extra/patches.py +7 -0
  17. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/extra/problem.py +41 -8
  18. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/extra/rule.py +2 -4
  19. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/generic.py +45 -6
  20. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/kwargs_types.py +23 -17
  21. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/usages.py +11 -16
  22. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/parser.py +7 -8
  23. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/check_string.hbs +4 -0
  24. fabricatio-0.2.8.dev4/templates/built-in/fix_troubled_obj.hbs +14 -0
  25. fabricatio-0.2.8.dev4/templates/built-in/fix_troubled_string.hbs +19 -0
  26. fabricatio-0.2.8.dev4/templates/built-in/ruleset_requirement_breakdown.hbs +7 -0
  27. fabricatio-0.2.8.dev4/templates.tar.gz +0 -0
  28. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/uv.lock +53 -53
  29. fabricatio-0.2.8.dev3/python/fabricatio/actions/article_rag.py +0 -89
  30. fabricatio-0.2.8.dev3/python/fabricatio/capabilities/check.py +0 -97
  31. fabricatio-0.2.8.dev3/python/fabricatio/capabilities/correct.py +0 -166
  32. fabricatio-0.2.8.dev3/templates/built-in/correct.hbs +0 -15
  33. fabricatio-0.2.8.dev3/templates.tar.gz +0 -0
  34. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/.github/workflows/build-package.yaml +0 -0
  35. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/.github/workflows/ruff.yaml +0 -0
  36. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/.github/workflows/tests.yaml +0 -0
  37. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/.gitignore +0 -0
  38. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/.python-version +0 -0
  39. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/Cargo.lock +0 -0
  40. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/Cargo.toml +0 -0
  41. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/LICENSE +0 -0
  42. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/Makefile +0 -0
  43. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/README.md +0 -0
  44. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/correct/correct.py +0 -0
  45. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/correct/correct_loop.py +0 -0
  46. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/extract_and_inject/.gitignore +0 -0
  47. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/extract_and_inject/article_rag.py +0 -0
  48. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/extract_and_inject/ask.py +0 -0
  49. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/extract_and_inject/extract_and_inject.py +0 -0
  50. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/extract_article/extract.py +0 -0
  51. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/llm_usages/llm_usage.py +0 -0
  52. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/make_a_rating/rating.py +0 -0
  53. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/make_diary/commits.json +0 -0
  54. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/make_diary/diary.py +0 -0
  55. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/minor/hello_fabricatio.py +0 -0
  56. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/minor/write_a_poem.py +0 -0
  57. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/propose_task/propose.py +0 -0
  58. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/reviewer/review.py +0 -0
  59. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/search_bibtex/.gitignore +0 -0
  60. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/search_bibtex/search.py +0 -0
  61. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/simple_chat/chat.py +0 -0
  62. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/simple_rag/simple_rag.py +0 -0
  63. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/task_handle/handle_task.py +0 -0
  64. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/write_article/.gitignore +0 -0
  65. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/write_article/article_rag.py +0 -0
  66. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/write_outline/.gitignore +0 -0
  67. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/write_outline/write_outline.py +0 -0
  68. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/examples/write_outline/write_outline_corrected.py +0 -0
  69. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/__init__.py +0 -0
  70. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/_rust.pyi +0 -0
  71. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/_rust_instances.py +0 -0
  72. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/actions/output.py +0 -0
  73. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/actions/rag.py +0 -0
  74. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/capabilities/advanced_judge.py +0 -0
  75. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/capabilities/propose.py +0 -0
  76. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/capabilities/rag.py +0 -0
  77. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/capabilities/review.py +0 -0
  78. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/capabilities/task.py +0 -0
  79. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/core.py +0 -0
  80. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/decorators.py +0 -0
  81. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/fs/__init__.py +0 -0
  82. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/fs/curd.py +0 -0
  83. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/fs/readers.py +0 -0
  84. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/journal.py +0 -0
  85. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/events.py +0 -0
  86. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/extra/article_essence.py +0 -0
  87. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/extra/article_outline.py +0 -0
  88. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/extra/article_proposal.py +0 -0
  89. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/role.py +0 -0
  90. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/task.py +0 -0
  91. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/tool.py +0 -0
  92. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/models/utils.py +0 -0
  93. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/py.typed +0 -0
  94. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/toolboxes/__init__.py +0 -0
  95. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  96. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/toolboxes/fs.py +0 -0
  97. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/utils.py +0 -0
  98. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/workflows/articles.py +0 -0
  99. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/python/fabricatio/workflows/rag.py +0 -0
  100. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/src/bib_tools.rs +0 -0
  101. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/src/hash.rs +0 -0
  102. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/src/hbs_helpers.rs +0 -0
  103. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/src/lib.rs +0 -0
  104. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/src/templates.rs +0 -0
  105. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/as_prompt.hbs +0 -0
  106. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  107. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/claude-xml.hbs +0 -0
  108. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/clean-up-code.hbs +0 -0
  109. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/co_validation.hbs +0 -0
  110. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/create_json_obj.hbs +0 -0
  111. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  112. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/dependencies.hbs +0 -0
  113. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/document-the-code.hbs +0 -0
  114. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/draft_rating_criteria.hbs +0 -0
  115. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/draft_rating_manual.hbs +0 -0
  116. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  117. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  118. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  119. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  120. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  121. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/fix-bugs.hbs +0 -0
  122. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/generic_string.hbs +0 -0
  123. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/improve-performance.hbs +0 -0
  124. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/liststr.hbs +0 -0
  125. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/make_choice.hbs +0 -0
  126. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/make_judgment.hbs +0 -0
  127. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/pathstr.hbs +0 -0
  128. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/rate_fine_grind.hbs +0 -0
  129. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/refactor.hbs +0 -0
  130. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/refined_query.hbs +0 -0
  131. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/retrieved_display.hbs +0 -0
  132. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  133. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/review_string.hbs +0 -0
  134. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/task_briefing.hbs +0 -0
  135. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/web-ctf-solver.hbs +0 -0
  136. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/write-git-commit.hbs +0 -0
  137. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/write-github-pull-request.hbs +0 -0
  138. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/templates/built-in/write-github-readme.hbs +0 -0
  139. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/tests/test_config.py +0 -0
  140. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/tests/test_models/test_action.py +0 -0
  141. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/tests/test_models/test_advanced.py +0 -0
  142. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/tests/test_models/test_generic.py +0 -0
  143. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/tests/test_models/test_role.py +0 -0
  144. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/tests/test_models/test_task.py +0 -0
  145. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/tests/test_models/test_tool.py +0 -0
  146. {fabricatio-0.2.8.dev3 → fabricatio-0.2.8.dev4}/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.8.dev4
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -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
  ),
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.8-dev3"
3
+ version = "0.2.8-dev4"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -5,21 +5,24 @@ from pathlib import Path
5
5
  from typing import Any, Callable, List, Optional
6
6
 
7
7
  from fabricatio._rust import BibManager
8
- from fabricatio.capabilities.advanced_judge import AdvancedJudge
8
+ from fabricatio.capabilities.censor import Censor
9
+ from fabricatio.capabilities.correct import Correct
10
+ from fabricatio.capabilities.propose import Propose
9
11
  from fabricatio.fs import safe_text_read
10
12
  from fabricatio.journal import logger
11
13
  from fabricatio.models.action import Action
12
- from fabricatio.models.extra.article_base import ArticleRefPatch
14
+ from fabricatio.models.extra.article_base import ArticleRefSequencePatch
13
15
  from fabricatio.models.extra.article_essence import ArticleEssence
14
16
  from fabricatio.models.extra.article_main import Article
15
17
  from fabricatio.models.extra.article_outline import ArticleOutline
16
18
  from fabricatio.models.extra.article_proposal import ArticleProposal
19
+ from fabricatio.models.extra.rule import RuleSet
17
20
  from fabricatio.models.task import Task
18
21
  from fabricatio.utils import ok
19
22
  from more_itertools import filter_map
20
23
 
21
24
 
22
- class ExtractArticleEssence(Action):
25
+ class ExtractArticleEssence(Action, Propose):
23
26
  """Extract the essence of article(s) in text format from the paths specified in the task dependencies.
24
27
 
25
28
  Notes:
@@ -47,11 +50,11 @@ class ExtractArticleEssence(Action):
47
50
  out = []
48
51
 
49
52
  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
- ],
53
+ ArticleEssence,
54
+ [
55
+ f"{c}\n\n\nBased the provided academic article above, you need to extract the essence from it."
56
+ for c in contents
57
+ ],
55
58
  ):
56
59
  if ess is None:
57
60
  logger.warning("Could not extract article essence")
@@ -91,7 +94,7 @@ class FixArticleEssence(Action):
91
94
  return out
92
95
 
93
96
 
94
- class GenerateArticleProposal(Action):
97
+ class GenerateArticleProposal(Action, Propose):
95
98
  """Generate an outline for the article based on the extracted essence."""
96
99
 
97
100
  output_key: str = "article_proposal"
@@ -133,7 +136,7 @@ class GenerateArticleProposal(Action):
133
136
  return proposal
134
137
 
135
138
 
136
- class GenerateInitialOutline(Action):
139
+ class GenerateInitialOutline(Action, Propose):
137
140
  """Generate the initial article outline based on the article proposal."""
138
141
 
139
142
  output_key: str = "initial_article_outline"
@@ -153,38 +156,29 @@ class GenerateInitialOutline(Action):
153
156
  ).update_ref(article_proposal)
154
157
 
155
158
 
156
- class FixIntrospectedErrors(Action):
159
+ class FixIntrospectedErrors(Action, Censor):
157
160
  """Fix introspected errors in the article outline."""
158
161
 
159
162
  output_key: str = "introspected_errors_fixed_outline"
160
163
  """The key of the output data."""
161
164
 
165
+ ruleset: Optional[RuleSet] = None
166
+ """The ruleset to use to fix the introspected errors."""
167
+
162
168
  async def _execute(
163
169
  self,
164
170
  article_outline: ArticleOutline,
165
- supervisor_check: bool = False,
171
+ ruleset: Optional[RuleSet] = None,
166
172
  **_,
167
173
  ) -> 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
174
  while pack := article_outline.find_introspected():
179
175
  component, err = ok(pack)
180
176
  logger.warning(f"Found introspected error: {err}")
181
177
  corrected = ok(
182
- await self.correct_obj(
178
+ await self.censor_obj(
183
179
  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,
180
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
181
+ 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
182
  ),
189
183
  "Could not correct the component.",
190
184
  )
@@ -193,38 +187,29 @@ class FixIntrospectedErrors(Action):
193
187
  return article_outline
194
188
 
195
189
 
196
- class FixIllegalReferences(Action):
190
+ class FixIllegalReferences(Action, Censor):
197
191
  """Fix illegal references in the article outline."""
198
192
 
199
193
  output_key: str = "illegal_references_fixed_outline"
200
194
  """The key of the output data."""
201
195
 
196
+ ruleset: Optional[RuleSet] = None
197
+ """Ruleset to use to fix the illegal references."""
198
+
202
199
  async def _execute(
203
200
  self,
204
201
  article_outline: ArticleOutline,
205
- supervisor_check: bool = False,
202
+ ruleset: Optional[RuleSet] = None,
206
203
  **_,
207
204
  ) -> 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
205
  while pack := article_outline.find_illegal_ref(gather_identical=True):
219
206
  refs, err = ok(pack)
220
207
  logger.warning(f"Found illegal referring error: {err}")
221
208
  corrected_ref = ok(
222
- await self.correct_obj(
209
+ await self.censor_obj(
223
210
  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,
211
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
212
+ reference=f"# Original Article Outline\n{article_outline.display()}\n# Some Basic errors found that need to be fixed\n{err}",
228
213
  )
229
214
  )
230
215
  for ref in refs:
@@ -233,43 +218,40 @@ class FixIllegalReferences(Action):
233
218
  return article_outline.update_ref(article_outline)
234
219
 
235
220
 
236
- class TweakOutlineForwardRef(Action, AdvancedJudge):
221
+ class TweakOutlineForwardRef(Action, Censor):
237
222
  """Tweak the forward references in the article outline.
238
223
 
239
224
  Ensures that the conclusions of the current chapter effectively support the analysis of subsequent chapters.
240
225
  """
241
226
 
242
227
  output_key: str = "article_outline_fw_ref_checked"
228
+ ruleset: Optional[RuleSet] = None
229
+ """Ruleset to use to fix the illegal references."""
243
230
 
244
- async def _execute(self, article_outline: ArticleOutline, supervisor_check: bool = False, **cxt) -> ArticleOutline:
231
+ async def _execute(
232
+ self, article_outline: ArticleOutline, ruleset: Optional[RuleSet] = None, **cxt
233
+ ) -> ArticleOutline:
245
234
  return await self._inner(
246
235
  article_outline,
247
- supervisor_check,
248
- topic="Ensure conclusions support the analysis of subsequent chapters, sections or subsections.",
236
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
249
237
  field_name="support_to",
250
238
  )
251
239
 
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
- )
240
+ async def _inner(self, article_outline: ArticleOutline, ruleset: RuleSet, field_name: str) -> ArticleOutline:
259
241
  for a in article_outline.iter_dfs():
260
- if await self.evidently_judge(
242
+ if judge := await self.evidently_judge(
261
243
  f"{article_outline.as_prompt()}\n\n{a.display()}\n"
262
244
  f"Does the `{a.__class__.__name__}`'s `{field_name}` field need to be extended or tweaked?"
263
245
  ):
264
- patch = ArticleRefPatch.default()
246
+ patch = ArticleRefSequencePatch.default()
265
247
  patch.tweaked = getattr(a, field_name)
266
248
 
267
- await self.correct_obj_inplace(
249
+ await self.censor_obj_inplace(
268
250
  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,
251
+ ruleset=ruleset,
252
+ reference=f"{article_outline.as_prompt()}\n"
253
+ f"The Article component titled `{a.title}` whose `{field_name}` field needs to be extended or tweaked.\n"
254
+ f"# Judgement\n{judge.display()}",
273
255
  )
274
256
  return article_outline
275
257
 
@@ -281,44 +263,41 @@ class TweakOutlineBackwardRef(TweakOutlineForwardRef):
281
263
  """
282
264
 
283
265
  output_key: str = "article_outline_bw_ref_checked"
266
+ ruleset: Optional[RuleSet] = None
284
267
 
285
- async def _execute(self, article_outline: ArticleOutline, supervisor_check: bool = False, **cxt) -> ArticleOutline:
268
+ async def _execute(
269
+ self, article_outline: ArticleOutline, ruleset: Optional[RuleSet] = None, **cxt
270
+ ) -> ArticleOutline:
286
271
  return await self._inner(
287
272
  article_outline,
288
- supervisor_check,
289
- topic="Ensure the dependencies of the current chapter are neither abused nor missing.",
273
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
290
274
  field_name="depend_on",
291
275
  )
292
276
 
293
277
 
294
- class GenerateArticle(Action):
278
+ class GenerateArticle(Action, Censor):
295
279
  """Generate the article based on the outline."""
296
280
 
297
281
  output_key: str = "article"
298
282
  """The key of the output data."""
283
+ ruleset: Optional[RuleSet] = None
299
284
 
300
285
  async def _execute(
301
286
  self,
302
287
  article_outline: ArticleOutline,
303
- supervisor_check: bool = False,
288
+ ruleset: Optional[RuleSet] = None,
304
289
  **_,
305
290
  ) -> Optional[Article]:
306
291
  article: Article = Article.from_outline(ok(article_outline, "Article outline not specified.")).update_ref(
307
292
  article_outline
308
293
  )
309
294
 
310
- write_para_manual = ok(
311
- await self.draft_rating_manual(w_topic := "write the following paragraph in the subsection.")
312
- )
313
-
314
295
  await gather(
315
296
  *[
316
- self.correct_obj_inplace(
297
+ self.censor_obj_inplace(
317
298
  subsec,
299
+ ruleset=ok(ruleset or self.ruleset, "No ruleset provided"),
318
300
  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
301
  )
323
302
  for _, __, subsec in article.iter_subsections()
324
303
  if (err := subsec.introspect())
@@ -329,18 +308,16 @@ class GenerateArticle(Action):
329
308
  return article
330
309
 
331
310
 
332
- class CorrectProposal(Action):
311
+ class CorrectProposal(Action, Censor):
333
312
  """Correct the proposal of the article."""
334
313
 
335
314
  output_key: str = "corrected_proposal"
336
315
 
337
316
  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
- )
317
+ raise NotImplementedError("Not implemented.")
341
318
 
342
319
 
343
- class CorrectOutline(Action):
320
+ class CorrectOutline(Action, Correct):
344
321
  """Correct the outline of the article."""
345
322
 
346
323
  output_key: str = "corrected_outline"
@@ -351,12 +328,10 @@ class CorrectOutline(Action):
351
328
  article_outline: ArticleOutline,
352
329
  **_,
353
330
  ) -> ArticleOutline:
354
- return (await self.censor_obj(article_outline, reference=article_outline.referenced.as_prompt())).update_ref(
355
- article_outline
356
- )
331
+ raise NotImplementedError("Not implemented.")
357
332
 
358
333
 
359
- class CorrectArticle(Action):
334
+ class CorrectArticle(Action, Correct):
360
335
  """Correct the article based on the outline."""
361
336
 
362
337
  output_key: str = "corrected_article"
@@ -368,4 +343,4 @@ class CorrectArticle(Action):
368
343
  article_outline: ArticleOutline,
369
344
  **_,
370
345
  ) -> Article:
371
- return await self.censor_obj(article, reference=article_outline.referenced.as_prompt())
346
+ 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
+ )
@@ -0,0 +1,87 @@
1
+ """Module for censoring objects and strings based on provided rulesets.
2
+
3
+ This module includes the Censor class which inherits from both Correct and Check classes.
4
+ It provides methods to censor objects and strings by first checking them against a ruleset and then correcting them if necessary.
5
+ """
6
+
7
+ from typing import Optional, Unpack
8
+
9
+ from fabricatio.capabilities.check import Check
10
+ from fabricatio.capabilities.correct import Correct
11
+ from fabricatio.models.extra.rule import RuleSet
12
+ from fabricatio.models.generic import ProposedUpdateAble, SketchedAble
13
+ from fabricatio.models.kwargs_types import ReferencedKwargs
14
+ from fabricatio.utils import override_kwargs
15
+
16
+
17
+ class Censor(Correct, Check):
18
+ """Class to censor objects and strings based on provided rulesets.
19
+
20
+ Inherits from both Correct and Check classes.
21
+ Provides methods to censor objects and strings by first checking them against a ruleset and then correcting them if necessary.
22
+ """
23
+
24
+ async def censor_obj[M: SketchedAble](
25
+ self, obj: M, ruleset: RuleSet, **kwargs: Unpack[ReferencedKwargs[M]]
26
+ ) -> Optional[M]:
27
+ """Censors an object based on the provided ruleset.
28
+
29
+ Args:
30
+ obj (M): The object to be censored.
31
+ ruleset (RuleSet): The ruleset to apply for censoring.
32
+ **kwargs: Additional keyword arguments to be passed to the check and correct methods.
33
+
34
+ Returns:
35
+ Optional[M]: The censored object if corrections were made, otherwise None.
36
+
37
+ Note:
38
+ This method first checks the object against the ruleset and then corrects it if necessary.
39
+ """
40
+ imp = await self.check_obj(obj, ruleset, **override_kwargs(kwargs, default=None))
41
+ if imp is None:
42
+ return imp
43
+ return await self.correct_obj(obj, imp, **kwargs)
44
+
45
+ async def censor_string(
46
+ self, input_text: str, ruleset: RuleSet, **kwargs: Unpack[ReferencedKwargs[str]]
47
+ ) -> Optional[str]:
48
+ """Censors a string based on the provided ruleset.
49
+
50
+ Args:
51
+ input_text (str): The string to be censored.
52
+ ruleset (RuleSet): The ruleset to apply for censoring.
53
+ **kwargs: Additional keyword arguments to be passed to the check and correct methods.
54
+
55
+ Returns:
56
+ Optional[str]: The censored string if corrections were made, otherwise None.
57
+
58
+ Note:
59
+ This method first checks the string against the ruleset and then corrects it if necessary.
60
+ """
61
+ imp = await self.check_string(input_text, ruleset, **override_kwargs(kwargs, default=None))
62
+ if imp is None:
63
+ return imp
64
+ return await self.correct_string(input_text, imp, **kwargs)
65
+
66
+ async def censor_obj_inplace[M: ProposedUpdateAble](
67
+ self, obj: M, ruleset: RuleSet, **kwargs: Unpack[ReferencedKwargs[M]]
68
+ ) -> Optional[M]:
69
+ """Censors an object in-place based on the provided ruleset.
70
+
71
+ This method modifies the object directly if corrections are needed.
72
+
73
+ Args:
74
+ obj (M): The object to be censored.
75
+ ruleset (RuleSet): The ruleset to apply for censoring.
76
+ **kwargs: Additional keyword arguments to be passed to the check and correct methods.
77
+
78
+ Returns:
79
+ Optional[M]: The censored object if corrections were made, otherwise None.
80
+
81
+ Note:
82
+ This method first checks the object against the ruleset and then corrects it in-place if necessary.
83
+ """
84
+ imp = await self.check_obj(obj, ruleset, **override_kwargs(kwargs, default=None))
85
+ if imp is None:
86
+ return imp
87
+ return await self.correct_obj_inplace(obj, improvement=imp, **kwargs)