fabricatio 0.2.7.dev5__tar.gz → 0.2.8.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 (132) hide show
  1. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/PKG-INFO +1 -1
  2. {fabricatio-0.2.7.dev5/examples/write_outline → fabricatio-0.2.8.dev0/examples/write_article}/.gitignore +2 -1
  3. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/write_article/write_article.py +8 -5
  4. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/pyproject.toml +1 -1
  5. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/actions/article.py +87 -70
  6. fabricatio-0.2.8.dev0/python/fabricatio/actions/output.py +69 -0
  7. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/capabilities/correct.py +26 -6
  8. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/action.py +2 -0
  9. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/extra/article_base.py +177 -86
  10. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/extra/article_main.py +21 -49
  11. fabricatio-0.2.8.dev0/python/fabricatio/models/extra/article_outline.py +32 -0
  12. fabricatio-0.2.8.dev0/python/fabricatio/models/extra/article_proposal.py +33 -0
  13. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/generic.py +12 -16
  14. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/usages.py +5 -1
  15. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/create_json_obj.hbs +1 -1
  16. fabricatio-0.2.8.dev0/templates.tar.gz +0 -0
  17. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/uv.lock +281 -289
  18. fabricatio-0.2.7.dev5/python/fabricatio/actions/output.py +0 -34
  19. fabricatio-0.2.7.dev5/python/fabricatio/models/extra/article_outline.py +0 -187
  20. fabricatio-0.2.7.dev5/python/fabricatio/models/extra/article_proposal.py +0 -35
  21. fabricatio-0.2.7.dev5/templates.tar.gz +0 -0
  22. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/.github/workflows/build-package.yaml +0 -0
  23. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/.github/workflows/ruff.yaml +0 -0
  24. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/.github/workflows/tests.yaml +0 -0
  25. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/.gitignore +0 -0
  26. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/.python-version +0 -0
  27. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/Cargo.lock +0 -0
  28. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/Cargo.toml +0 -0
  29. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/LICENSE +0 -0
  30. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/Makefile +0 -0
  31. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/README.md +0 -0
  32. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/correct/correct.py +0 -0
  33. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/correct/correct_loop.py +0 -0
  34. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/extract_and_inject/.gitignore +0 -0
  35. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/extract_and_inject/article_rag.py +0 -0
  36. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/extract_and_inject/ask.py +0 -0
  37. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/extract_and_inject/extract_and_inject.py +0 -0
  38. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/extract_article/extract.py +0 -0
  39. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/llm_usages/llm_usage.py +0 -0
  40. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/make_a_rating/rating.py +0 -0
  41. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/make_diary/commits.json +0 -0
  42. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/make_diary/diary.py +0 -0
  43. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/minor/hello_fabricatio.py +0 -0
  44. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/minor/write_a_poem.py +0 -0
  45. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/propose_task/propose.py +0 -0
  46. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/reviewer/review.py +0 -0
  47. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/search_bibtex/.gitignore +0 -0
  48. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/search_bibtex/search.py +0 -0
  49. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/simple_chat/chat.py +0 -0
  50. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/simple_rag/simple_rag.py +0 -0
  51. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/task_handle/handle_task.py +0 -0
  52. {fabricatio-0.2.7.dev5/examples/write_article → fabricatio-0.2.8.dev0/examples/write_outline}/.gitignore +0 -0
  53. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/write_outline/write_outline.py +0 -0
  54. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/examples/write_outline/write_outline_corrected.py +0 -0
  55. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/__init__.py +0 -0
  56. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/_rust.pyi +0 -0
  57. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/_rust_instances.py +0 -0
  58. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/actions/article_rag.py +0 -0
  59. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/actions/rag.py +0 -0
  60. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/capabilities/propose.py +0 -0
  61. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/capabilities/rag.py +0 -0
  62. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/capabilities/rating.py +0 -0
  63. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/capabilities/review.py +0 -0
  64. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/capabilities/task.py +0 -0
  65. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/config.py +0 -0
  66. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/core.py +0 -0
  67. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/decorators.py +0 -0
  68. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/fs/__init__.py +0 -0
  69. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/fs/curd.py +0 -0
  70. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/fs/readers.py +0 -0
  71. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/journal.py +0 -0
  72. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/events.py +0 -0
  73. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/extra/article_essence.py +0 -0
  74. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/kwargs_types.py +0 -0
  75. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/role.py +0 -0
  76. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/task.py +0 -0
  77. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/tool.py +0 -0
  78. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/models/utils.py +0 -0
  79. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/parser.py +0 -0
  80. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/py.typed +0 -0
  81. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/toolboxes/__init__.py +0 -0
  82. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  83. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/toolboxes/fs.py +0 -0
  84. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/workflows/articles.py +0 -0
  85. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/python/fabricatio/workflows/rag.py +0 -0
  86. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/src/bib_tools.rs +0 -0
  87. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/src/hash.rs +0 -0
  88. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/src/hbs_helpers.rs +0 -0
  89. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/src/lib.rs +0 -0
  90. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/src/templates.rs +0 -0
  91. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/as_prompt.hbs +0 -0
  92. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  93. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/claude-xml.hbs +0 -0
  94. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/clean-up-code.hbs +0 -0
  95. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/co_validation.hbs +0 -0
  96. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/correct.hbs +0 -0
  97. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  98. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/dependencies.hbs +0 -0
  99. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/document-the-code.hbs +0 -0
  100. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/draft_rating_criteria.hbs +0 -0
  101. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/draft_rating_manual.hbs +0 -0
  102. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  103. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  104. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  105. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  106. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  107. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/fix-bugs.hbs +0 -0
  108. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/generic_string.hbs +0 -0
  109. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/improve-performance.hbs +0 -0
  110. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/liststr.hbs +0 -0
  111. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/make_choice.hbs +0 -0
  112. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/make_judgment.hbs +0 -0
  113. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/pathstr.hbs +0 -0
  114. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/rate_fine_grind.hbs +0 -0
  115. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/refactor.hbs +0 -0
  116. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/refined_query.hbs +0 -0
  117. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/retrieved_display.hbs +0 -0
  118. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  119. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/review_string.hbs +0 -0
  120. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/task_briefing.hbs +0 -0
  121. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/web-ctf-solver.hbs +0 -0
  122. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/write-git-commit.hbs +0 -0
  123. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/write-github-pull-request.hbs +0 -0
  124. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/templates/built-in/write-github-readme.hbs +0 -0
  125. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/tests/test_config.py +0 -0
  126. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/tests/test_models/test_action.py +0 -0
  127. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/tests/test_models/test_advanced.py +0 -0
  128. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/tests/test_models/test_generic.py +0 -0
  129. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/tests/test_models/test_role.py +0 -0
  130. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/tests/test_models/test_task.py +0 -0
  131. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev0}/tests/test_models/test_tool.py +0 -0
  132. {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.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.7.dev5
3
+ Version: 0.2.8.dev0
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,2 +1,3 @@
1
1
  article_briefing.txt
2
- out.typ
2
+ out.typ
3
+ persistent
@@ -9,7 +9,7 @@ from fabricatio.actions.article import (
9
9
  GenerateArticleProposal,
10
10
  GenerateOutline,
11
11
  )
12
- from fabricatio.actions.output import DumpFinalizedOutput
12
+ from fabricatio.actions.output import DumpFinalizedOutput, PersistentAll
13
13
  from fabricatio.models.task import Task
14
14
 
15
15
 
@@ -20,9 +20,7 @@ async def main() -> None:
20
20
  description="Write an outline for an article in typst format.",
21
21
  llm_top_p=0.8,
22
22
  llm_temperature=1.15,
23
- llm_max_tokens=8192,
24
- llm_model="openai/qwen-max",
25
- llm_stream=True,
23
+ llm_model="litellm_proxy/qwen-max",
26
24
  registry={
27
25
  Event.quick_instantiate(ns := "article"): WorkFlow(
28
26
  name="Generate Article Outline",
@@ -32,8 +30,13 @@ async def main() -> None:
32
30
  GenerateOutline(llm_temperature=1.21, llm_top_p=0.3),
33
31
  GenerateArticle(output_key="to_dump", llm_temperature=1.2, llm_top_p=0.45),
34
32
  DumpFinalizedOutput(output_key="task_output"),
33
+ PersistentAll,
35
34
  ),
36
- ).update_init_context(article_briefing=Path("./article_briefing.txt").read_text(), dump_path="out.typ")
35
+ ).update_init_context(
36
+ article_briefing=Path("./article_briefing.txt").read_text(),
37
+ dump_path="out.typ",
38
+ persist_dir="persistent",
39
+ )
37
40
  },
38
41
  )
39
42
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.7-dev5"
3
+ version = "0.2.8-dev0"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -1,5 +1,6 @@
1
1
  """Actions for transmitting tasks to targets."""
2
2
 
3
+ from asyncio import gather
3
4
  from pathlib import Path
4
5
  from typing import Any, Callable, List, Optional
5
6
 
@@ -55,13 +56,14 @@ class GenerateArticleProposal(Action):
55
56
  task_input: Optional[Task] = None,
56
57
  article_briefing: Optional[str] = None,
57
58
  article_briefing_path: Optional[str] = None,
59
+ langauge: Optional[str] = None,
58
60
  **_,
59
61
  ) -> Optional[ArticleProposal]:
60
62
  if article_briefing is None and article_briefing_path is None and task_input is None:
61
63
  logger.error("Task not approved, since all inputs are None.")
62
64
  return None
63
65
 
64
- return ok(
66
+ proposal = ok(
65
67
  await self.propose(
66
68
  ArticleProposal,
67
69
  briefing := (
@@ -78,8 +80,12 @@ class GenerateArticleProposal(Action):
78
80
  ),
79
81
  **self.prepend_sys_msg(),
80
82
  ),
81
- "Could not generate the proposal."
83
+ "Could not generate the proposal.",
82
84
  ).update_ref(briefing)
85
+ if langauge:
86
+ proposal.language = langauge
87
+
88
+ return proposal
83
89
 
84
90
 
85
91
  class GenerateOutline(Action):
@@ -102,27 +108,92 @@ class GenerateOutline(Action):
102
108
  "Could not generate the outline.",
103
109
  )
104
110
 
105
- manual = ok(await self.draft_rating_manual(
106
- topic=(
107
- topic
108
- := "Fix the internal referring error, make sure there is no more `ArticleRef` pointing to a non-existing article component."
111
+ introspect_manual = ok(
112
+ await self.draft_rating_manual(
113
+ topic=(
114
+ intro_topic
115
+ := "Fix the error in the article outline, make sure there is no more error in the article outline."
116
+ ),
109
117
  ),
110
- ),"Could not generate the rating manual.")
118
+ "Could not generate the rating manual.",
119
+ )
111
120
 
112
- while pack := out.find_illegal():
121
+ while pack := out.find_introspected():
113
122
  component, err = ok(pack)
114
- logger.warning(f"Found error in the outline: \n{err}")
115
- corrected = ok(await self.correct_obj(
116
- component,
117
- reference=f"# Original Article Outline\n{out.display()}\n# Error Need to be fixed\n{err}",
118
- topic=topic,
119
- rating_manual=manual,
120
- supervisor_check=False,
121
- ),"Could not correct the component.")
123
+ logger.warning(f"Found introspected error: {err}")
124
+ corrected = ok(
125
+ await self.correct_obj(
126
+ component,
127
+ reference=f"# Original Article Outline\n{out.display()}\n# Error Need to be fixed\n{err}",
128
+ topic=intro_topic,
129
+ rating_manual=introspect_manual,
130
+ supervisor_check=False,
131
+ ),
132
+ "Could not correct the component.",
133
+ )
122
134
  component.update_from(corrected)
135
+
136
+ ref_manual = ok(
137
+ await self.draft_rating_manual(
138
+ topic=(
139
+ ref_topic
140
+ := "Fix the internal referring error, make sure there is no more `ArticleRef` pointing to a non-existing article component."
141
+ ),
142
+ ),
143
+ "Could not generate the rating manual.",
144
+ )
145
+
146
+ while pack := out.find_illegal_ref():
147
+ ref, err = ok(pack)
148
+ logger.warning(f"Found illegal referring error: {err}")
149
+ ok(
150
+ await self.correct_obj_inplace(
151
+ ref,
152
+ reference=f"# Original Article Outline\n{out.display()}\n# Error Need to be fixed\n{err}\n\n",
153
+ topic=ref_topic,
154
+ rating_manual=ref_manual,
155
+ supervisor_check=False,
156
+ )
157
+ )
123
158
  return out.update_ref(article_proposal)
124
159
 
125
160
 
161
+ class GenerateArticle(Action):
162
+ """Generate the article based on the outline."""
163
+
164
+ output_key: str = "article"
165
+ """The key of the output data."""
166
+
167
+ async def _execute(
168
+ self,
169
+ article_outline: ArticleOutline,
170
+ **_,
171
+ ) -> Optional[Article]:
172
+ article: Article = Article.from_outline(ok(article_outline, "Article outline not specified.")).update_ref(
173
+ article_outline
174
+ )
175
+
176
+ write_para_manual = ok(
177
+ await self.draft_rating_manual(w_topic := "write the following paragraph in the subsection.")
178
+ )
179
+
180
+ await gather(
181
+ *[
182
+ self.correct_obj_inplace(
183
+ subsec,
184
+ reference=f"# Original Article Outline\n{article_outline.display()}\n# Error Need to be fixed\n{err}",
185
+ topic=w_topic,
186
+ rating_manual=write_para_manual,
187
+ supervisor_check=False,
188
+ )
189
+ for _, __, subsec in article.iter_subsections()
190
+ if (err := subsec.introspect())
191
+ ],
192
+ return_exceptions=True,
193
+ )
194
+ return article
195
+
196
+
126
197
  class CorrectProposal(Action):
127
198
  """Correct the proposal of the article."""
128
199
 
@@ -150,60 +221,6 @@ class CorrectOutline(Action):
150
221
  )
151
222
 
152
223
 
153
- class GenerateArticle(Action):
154
- """Generate the article based on the outline."""
155
-
156
- output_key: str = "article"
157
- """The key of the output data."""
158
-
159
- async def _execute(
160
- self,
161
- article_outline: ArticleOutline,
162
- **_,
163
- ) -> Optional[Article]:
164
- article: Article = Article.from_outline(article_outline).update_ref(article_outline)
165
-
166
- writing_manual = ok(await self.draft_rating_manual(
167
- topic=(
168
- topic_1
169
- := "improve the content of the subsection to fit the outline. SHALL never add or remove any section or subsection, you can only add or delete paragraphs within the subsection."
170
- ),
171
- ))
172
- err_resolve_manual = ok(await self.draft_rating_manual(
173
- topic=(topic_2 := "this article component has violated the constrain, please correct it.")
174
- ))
175
- for c, deps in article.iter_dfs_with_deps(chapter=False):
176
- logger.info(f"Updating the article component: \n{c.display()}")
177
-
178
- out = ok(
179
- await self.correct_obj(
180
- c,
181
- reference=(
182
- ref := f"{article_outline.referenced.as_prompt()}\n" + "\n".join(d.display() for d in deps)
183
- ),
184
- topic=topic_1,
185
- rating_manual=writing_manual,
186
- supervisor_check=False,
187
- ),
188
- "Could not correct the article component.",
189
- )
190
- while err := c.resolve_update_conflict(out):
191
- logger.warning(f"Found error in the article component: \n{err}")
192
- out = ok(
193
- await self.correct_obj(
194
- out,
195
- reference=f"{ref}\n\n# Violated Error\n{err}",
196
- topic=topic_2,
197
- rating_manual=err_resolve_manual,
198
- supervisor_check=False,
199
- ),
200
- "Could not correct the article component.",
201
- )
202
-
203
- c.update_from(out)
204
- return article
205
-
206
-
207
224
  class CorrectArticle(Action):
208
225
  """Correct the article based on the outline."""
209
226
 
@@ -0,0 +1,69 @@
1
+ """Dump the finalized output to a file."""
2
+
3
+ from pathlib import Path
4
+ from typing import Optional
5
+
6
+ from fabricatio.journal import logger
7
+ from fabricatio.models.action import Action
8
+ from fabricatio.models.generic import FinalizedDumpAble, PersistentAble
9
+ from fabricatio.models.task import Task
10
+ from fabricatio.models.utils import ok
11
+
12
+
13
+ class DumpFinalizedOutput(Action):
14
+ """Dump the finalized output to a file."""
15
+
16
+ output_key: str = "dump_path"
17
+
18
+ async def _execute(
19
+ self,
20
+ to_dump: FinalizedDumpAble,
21
+ task_input: Optional[Task] = None,
22
+ dump_path: Optional[str | Path] = None,
23
+ **_,
24
+ ) -> str:
25
+ dump_path = Path(
26
+ dump_path
27
+ or ok(
28
+ await self.awhich_pathstr(
29
+ f"{ok(task_input, 'Neither `task_input` and `dump_path` is provided.').briefing}\n\nExtract a single path of the file, to which I will dump the data."
30
+ ),
31
+ "Could not find the path of file to dump the data.",
32
+ )
33
+ )
34
+ ok(to_dump, "Could not dump the data since the path is not specified.").finalized_dump_to(dump_path)
35
+ return dump_path.as_posix()
36
+
37
+
38
+ class PersistentAll(Action):
39
+ """Persist all the data to a file."""
40
+
41
+ output_key: str = "persistent_count"
42
+
43
+ async def _execute(
44
+ self,
45
+ task_input: Optional[Task] = None,
46
+ persist_dir: Optional[str | Path] = None,
47
+ **cxt,
48
+ ) -> int:
49
+ persist_dir = Path(
50
+ persist_dir
51
+ or ok(
52
+ await self.awhich_pathstr(
53
+ f"{ok(task_input, 'Neither `task_input` and `dump_path` is provided.').briefing}\n\nExtract a single path of the file, to which I will persist the data."
54
+ ),
55
+ "Can not find the path of file to persist the data.",
56
+ )
57
+ )
58
+
59
+ count = 0
60
+ if persist_dir.is_file():
61
+ logger.warning("Dump should be a directory, but it is a file. Skip dumping.")
62
+ return count
63
+ persist_dir.mkdir(parents=True, exist_ok=True)
64
+ for v in cxt.values():
65
+ if isinstance(v, PersistentAble):
66
+ v.persist(persist_dir)
67
+ count += 1
68
+
69
+ return count
@@ -10,7 +10,7 @@ from typing import Optional, Unpack, cast
10
10
  from fabricatio._rust_instances import TEMPLATE_MANAGER
11
11
  from fabricatio.capabilities.review import Review, ReviewResult
12
12
  from fabricatio.config import configs
13
- from fabricatio.models.generic import CensoredAble, Display, ProposedAble, WithBriefing
13
+ from fabricatio.models.generic import CensoredAble, Display, ProposedAble, ProposedUpdateAble, WithBriefing
14
14
  from fabricatio.models.kwargs_types import CensoredCorrectKwargs, CorrectKwargs, ReviewKwargs
15
15
  from fabricatio.models.task import Task
16
16
  from questionary import confirm, text
@@ -134,12 +134,32 @@ class Correct(Review):
134
134
  while await confirm("Begin to correct obj above with human censorship?").ask_async():
135
135
  while (topic := await text("What is the topic of the obj reviewing?").ask_async()) is not None and topic:
136
136
  ...
137
- if (modified_obj := await self.correct_obj(
138
- last_modified_obj,
139
- topic=topic,
140
- **kwargs,
141
- )) is None:
137
+ if (
138
+ modified_obj := await self.correct_obj(
139
+ last_modified_obj,
140
+ topic=topic,
141
+ **kwargs,
142
+ )
143
+ ) is None:
142
144
  break
143
145
  last_modified_obj = modified_obj
144
146
  rprint(last_modified_obj.finalized_dump())
145
147
  return modified_obj or last_modified_obj
148
+
149
+ async def correct_obj_inplace[M: ProposedUpdateAble](
150
+ self, obj: M, **kwargs: Unpack[CorrectKwargs[ReviewResult[str]]]
151
+ ) -> Optional[M]:
152
+ """Correct an object in place based on defined criteria and templates.
153
+
154
+ Args:
155
+ obj (M): The object to be corrected.
156
+ **kwargs (Unpack[CensoredCorrectKwargs]): Additional keyword arguments for the correction process.
157
+
158
+ Returns:
159
+ Optional[M]: The corrected object, or None if correction fails.
160
+ """
161
+ corrected_obj = await self.correct_obj(obj, **kwargs)
162
+ if corrected_obj is None:
163
+ return corrected_obj
164
+ obj.update_from(corrected_obj)
165
+ return obj
@@ -170,6 +170,8 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
170
170
  # Update context with modified values
171
171
  modified_ctx = await act_task
172
172
  logger.success(f"Step execution finished: {current_action}")
173
+ if step.output_key:
174
+ logger.success(f"Setting output: {step.output_key}")
173
175
  await self._context.put(modified_ctx)
174
176
 
175
177
  logger.success(f"Workflow execution finished: {self.name}")