fabricatio 0.2.5.dev5__tar.gz → 0.2.6.dev1__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 (113) hide show
  1. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/PKG-INFO +3 -3
  2. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/README.md +2 -2
  3. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/extract_and_review/extract_and_review.py +3 -1
  4. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/minor/hello_fabricatio.py +2 -2
  5. fabricatio-0.2.6.dev1/examples/minor/write_a_poem.py +36 -0
  6. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/reviewer/review.py +1 -1
  7. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/pyproject.toml +6 -5
  8. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/__init__.py +6 -6
  9. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/_rust_instances.py +1 -1
  10. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/actions/article.py +4 -4
  11. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/actions/output.py +1 -3
  12. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/actions/rag.py +2 -2
  13. fabricatio-0.2.6.dev1/python/fabricatio/capabilities/correct.py +103 -0
  14. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/capabilities/rag.py +20 -17
  15. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/capabilities/rating.py +8 -8
  16. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/capabilities/review.py +53 -16
  17. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/capabilities/task.py +3 -3
  18. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/config.py +37 -6
  19. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/fs/__init__.py +2 -2
  20. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/fs/readers.py +1 -1
  21. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/journal.py +0 -7
  22. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/action.py +4 -4
  23. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/generic.py +40 -10
  24. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/kwargs_types.py +2 -2
  25. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/role.py +2 -2
  26. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/task.py +2 -2
  27. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/usages.py +70 -23
  28. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/utils.py +21 -0
  29. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/parser.py +13 -5
  30. fabricatio-0.2.6.dev1/templates/built-in/correct.hbs +15 -0
  31. fabricatio-0.2.6.dev1/templates/built-in/generic_string.hbs +30 -0
  32. fabricatio-0.2.6.dev1/templates.tar.gz +0 -0
  33. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/uv.lock +30 -3
  34. fabricatio-0.2.5.dev5/templates.tar.gz +0 -0
  35. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/.github/workflows/build-package.yaml +0 -0
  36. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/.github/workflows/ruff.yaml +0 -0
  37. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/.github/workflows/tests.yaml +0 -0
  38. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/.gitignore +0 -0
  39. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/.python-version +0 -0
  40. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/Cargo.lock +0 -0
  41. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/Cargo.toml +0 -0
  42. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/LICENSE +0 -0
  43. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/Makefile +0 -0
  44. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/extract_and_review/.gitignore +0 -0
  45. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/extract_article/extract.py +0 -0
  46. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/llm_usages/llm_usage.py +0 -0
  47. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/make_a_rating/rating.py +0 -0
  48. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/make_diary/commits.json +0 -0
  49. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/make_diary/diary.py +0 -0
  50. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/propose_task/propose.py +0 -0
  51. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/simple_chat/chat.py +0 -0
  52. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/simple_rag/simple_rag.py +0 -0
  53. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/task_handle/handle_task.py +0 -0
  54. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/write_outline/.gitignore +0 -0
  55. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/examples/write_outline/write_outline.py +0 -0
  56. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/_rust.pyi +0 -0
  57. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/capabilities/propose.py +0 -0
  58. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/core.py +0 -0
  59. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/decorators.py +0 -0
  60. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/fs/curd.py +0 -0
  61. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/events.py +0 -0
  62. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/extra.py +0 -0
  63. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/models/tool.py +0 -0
  64. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/py.typed +0 -0
  65. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/toolboxes/__init__.py +0 -0
  66. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  67. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/toolboxes/fs.py +0 -0
  68. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/workflows/articles.py +0 -0
  69. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/python/fabricatio/workflows/rag.py +0 -0
  70. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/src/bib_tools.rs +0 -0
  71. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/src/hash.rs +0 -0
  72. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/src/hbs_helpers.rs +0 -0
  73. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/src/lib.rs +0 -0
  74. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/src/templates.rs +0 -0
  75. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  76. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/claude-xml.hbs +0 -0
  77. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/clean-up-code.hbs +0 -0
  78. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/create_json_obj.hbs +0 -0
  79. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  80. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/dependencies.hbs +0 -0
  81. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/document-the-code.hbs +0 -0
  82. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/draft_rating_criteria.hbs +0 -0
  83. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/draft_rating_manual.hbs +0 -0
  84. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  85. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  86. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  87. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  88. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  89. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/fix-bugs.hbs +0 -0
  90. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/improve-performance.hbs +0 -0
  91. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/liststr.hbs +0 -0
  92. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/make_choice.hbs +0 -0
  93. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/make_judgment.hbs +0 -0
  94. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/pathstr.hbs +0 -0
  95. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/rate_fine_grind.hbs +0 -0
  96. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/refactor.hbs +0 -0
  97. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/refined_query.hbs +0 -0
  98. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/retrieved_display.hbs +0 -0
  99. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  100. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/review_string.hbs +0 -0
  101. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/task_briefing.hbs +0 -0
  102. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/web-ctf-solver.hbs +0 -0
  103. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/write-git-commit.hbs +0 -0
  104. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/write-github-pull-request.hbs +0 -0
  105. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/templates/built-in/write-github-readme.hbs +0 -0
  106. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/tests/test_config.py +0 -0
  107. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/tests/test_models/test_action.py +0 -0
  108. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/tests/test_models/test_advanced.py +0 -0
  109. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/tests/test_models/test_generic.py +0 -0
  110. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/tests/test_models/test_role.py +0 -0
  111. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/tests/test_models/test_task.py +0 -0
  112. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/tests/test_models/test_tool.py +0 -0
  113. {fabricatio-0.2.5.dev5 → fabricatio-0.2.6.dev1}/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.5.dev5
3
+ Version: 0.2.6.dev1
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -176,7 +176,7 @@ if __name__ == "__main__":
176
176
  ### Template Management and Rendering
177
177
 
178
178
  ```python
179
- from fabricatio._rust_instances import template_manager
179
+ from fabricatio._rust_instances import TEMPLATE_MANAGER
180
180
 
181
181
  template_name = "claude-xml.hbs"
182
182
  data = {
@@ -185,7 +185,7 @@ data = {
185
185
  "files": [{"path": "file1.py", "code": "print('Hello')"}],
186
186
  }
187
187
 
188
- rendered_template = template_manager.render_template(template_name, data)
188
+ rendered_template = TEMPLATE_MANAGER.render_template(template_name, data)
189
189
  print(rendered_template)
190
190
  ```
191
191
 
@@ -137,7 +137,7 @@ if __name__ == "__main__":
137
137
  ### Template Management and Rendering
138
138
 
139
139
  ```python
140
- from fabricatio._rust_instances import template_manager
140
+ from fabricatio._rust_instances import TEMPLATE_MANAGER
141
141
 
142
142
  template_name = "claude-xml.hbs"
143
143
  data = {
@@ -146,7 +146,7 @@ data = {
146
146
  "files": [{"path": "file1.py", "code": "print('Hello')"}],
147
147
  }
148
148
 
149
- rendered_template = template_manager.render_template(template_name, data)
149
+ rendered_template = TEMPLATE_MANAGER.render_template(template_name, data)
150
150
  print(rendered_template)
151
151
  ```
152
152
 
@@ -27,8 +27,10 @@ async def main() -> None:
27
27
 
28
28
  unchecked_ess = await task.override_dependencies(gather_files("bpdf_out", "md")).delegate("article")
29
29
 
30
+ if unchecked_ess is None:
31
+ logger.error("No essence found")
32
+ return
30
33
  ess = list(filter(lambda x: x is not None, unchecked_ess))
31
-
32
34
  logger.success(f"Essence Count:{len(ess)}, invalid count: {len(unchecked_ess) - len(ess)}")
33
35
 
34
36
  Path("output").mkdir(exist_ok=True)
@@ -5,7 +5,7 @@ from typing import Any
5
5
 
6
6
  from fabricatio import Action, Role, Task, WorkFlow, logger
7
7
 
8
- task = Task(name="say hello", goals=["say hello"], description="say hello to the world")
8
+ task = Task(name="say hello")
9
9
 
10
10
 
11
11
  class Hello(Action):
@@ -13,7 +13,7 @@ class Hello(Action):
13
13
 
14
14
  output_key: str = "task_output"
15
15
 
16
- async def _execute(self, task_input: Task[str], **_) -> Any:
16
+ async def _execute(self, **_) -> Any:
17
17
  ret = "Hello fabricatio!"
18
18
  logger.info("executing talk action")
19
19
  return ret
@@ -0,0 +1,36 @@
1
+ """Example of a poem writing program using fabricatio."""
2
+
3
+ import asyncio
4
+ from typing import Any
5
+
6
+ from fabricatio import Action, Role, Task, WorkFlow, logger
7
+
8
+ task = Task(name="write poem")
9
+
10
+
11
+ class WritePoem(Action):
12
+ """Action that generates a poem."""
13
+
14
+ output_key: str = "task_output"
15
+
16
+ async def _execute(self, **_) -> Any:
17
+ logger.info("Generating poem about the sea")
18
+ return await self.ageneric_string(
19
+ "Write a poetic and evocative poem about the sea, its vastness, and mysteries.",
20
+ )
21
+
22
+
23
+ async def main() -> None:
24
+ """Main function."""
25
+ Role(
26
+ name="poet",
27
+ description="A role that creates poetic content",
28
+ registry={task.pending_label: WorkFlow(name="poetry_creation", steps=(WritePoem,))},
29
+ )
30
+
31
+ poem = await task.delegate()
32
+ logger.success(f"Poem:\n\n{poem}")
33
+
34
+
35
+ if __name__ == "__main__":
36
+ asyncio.run(main())
@@ -19,7 +19,7 @@ async def main() -> None:
19
19
  logger.success(f"Code: \n{code}")
20
20
  res = await role.review_string(code, "If the cli app is of good design")
21
21
  logger.success(f"Review: \n{res.display()}")
22
- await res.supervisor_check(True)
22
+ await res.supervisor_check()
23
23
  logger.success(f"Review: \n{res.display()}")
24
24
 
25
25
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.5-dev5"
3
+ version = "0.2.6-dev1"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -72,6 +72,7 @@ dev = [
72
72
  "pytest-mock>=3.14.0",
73
73
  "pytest-rerunfailures>=15.0",
74
74
  "pytest-xdist>=3.6.1",
75
+ "viztracer>=1.0.2",
75
76
  ]
76
77
 
77
78
  [project.optional-dependencies]
@@ -139,6 +140,10 @@ testpaths = [
139
140
  asyncio_mode = "auto"
140
141
  asyncio_default_fixture_loop_scope = "function"
141
142
 
143
+ [[tool.uv.index]]
144
+ url = "https://mirrors.bfsu.edu.cn/pypi/web/simple"
145
+ default = true
146
+
142
147
  [[tool.uv.index]]
143
148
  url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
144
149
 
@@ -148,7 +153,3 @@ url = "https://mirrors.huaweicloud.com/repository/pypi/simple"
148
153
  [[tool.uv.index]]
149
154
  url = "https://mirrors.aliyun.com/pypi/simple/"
150
155
 
151
- [[tool.uv.index]]
152
- url = "https://mirrors.bfsu.edu.cn/pypi/web/simple"
153
- default = true
154
-
@@ -3,11 +3,11 @@
3
3
  from importlib.util import find_spec
4
4
 
5
5
  from fabricatio._rust import BibManager
6
- from fabricatio._rust_instances import template_manager
6
+ from fabricatio._rust_instances import TEMPLATE_MANAGER
7
7
  from fabricatio.actions.article import ExtractArticleEssence, GenerateArticleProposal, GenerateOutline
8
8
  from fabricatio.actions.output import DumpFinalizedOutput
9
9
  from fabricatio.core import env
10
- from fabricatio.fs import magika, safe_json_read, safe_text_read
10
+ from fabricatio.fs import MAGIKA, safe_json_read, safe_text_read
11
11
  from fabricatio.journal import logger
12
12
  from fabricatio.models.action import Action, WorkFlow
13
13
  from fabricatio.models.events import Event
@@ -16,21 +16,23 @@ from fabricatio.models.role import Role
16
16
  from fabricatio.models.task import Task
17
17
  from fabricatio.models.tool import ToolBox
18
18
  from fabricatio.models.utils import Message, Messages
19
- from fabricatio.parser import Capture, CodeBlockCapture, JsonCapture, PythonCapture
19
+ from fabricatio.parser import Capture, GenericCapture, JsonCapture, PythonCapture
20
20
  from fabricatio.toolboxes import arithmetic_toolbox, basic_toolboxes, fs_toolbox
21
21
  from fabricatio.workflows.articles import WriteOutlineWorkFlow
22
22
 
23
23
  __all__ = [
24
+ "MAGIKA",
25
+ "TEMPLATE_MANAGER",
24
26
  "Action",
25
27
  "ArticleEssence",
26
28
  "BibManager",
27
29
  "Capture",
28
- "CodeBlockCapture",
29
30
  "DumpFinalizedOutput",
30
31
  "Event",
31
32
  "ExtractArticleEssence",
32
33
  "GenerateArticleProposal",
33
34
  "GenerateOutline",
35
+ "GenericCapture",
34
36
  "JsonCapture",
35
37
  "Message",
36
38
  "Messages",
@@ -45,10 +47,8 @@ __all__ = [
45
47
  "env",
46
48
  "fs_toolbox",
47
49
  "logger",
48
- "magika",
49
50
  "safe_json_read",
50
51
  "safe_text_read",
51
- "template_manager",
52
52
  ]
53
53
 
54
54
 
@@ -3,7 +3,7 @@
3
3
  from fabricatio._rust import TemplateManager
4
4
  from fabricatio.config import configs
5
5
 
6
- template_manager = TemplateManager(
6
+ TEMPLATE_MANAGER = TemplateManager(
7
7
  template_dirs=configs.templates.template_dir,
8
8
  suffix=configs.templates.template_suffix,
9
9
  active_loading=configs.templates.active_loading,
@@ -2,7 +2,7 @@
2
2
 
3
3
  from os import PathLike
4
4
  from pathlib import Path
5
- from typing import Callable, List
5
+ from typing import Callable, List, Optional
6
6
 
7
7
  from fabricatio.fs import safe_text_read
8
8
  from fabricatio.journal import logger
@@ -27,7 +27,7 @@ class ExtractArticleEssence(Action):
27
27
  task_input: Task,
28
28
  reader: Callable[[P], str] = lambda p: Path(p).read_text(encoding="utf-8"),
29
29
  **_,
30
- ) -> List[ArticleEssence]:
30
+ ) -> Optional[List[ArticleEssence]]:
31
31
  if not task_input.dependencies:
32
32
  logger.info(err := "Task not approved, since no dependencies are provided.")
33
33
  raise RuntimeError(err)
@@ -51,7 +51,7 @@ class GenerateArticleProposal(Action):
51
51
  self,
52
52
  task_input: Task,
53
53
  **_,
54
- ) -> ArticleProposal:
54
+ ) -> Optional[ArticleProposal]:
55
55
  input_path = await self.awhich_pathstr(
56
56
  f"{task_input.briefing}\nExtract the path of file, which contains the article briefing that I need to read."
57
57
  )
@@ -73,7 +73,7 @@ class GenerateOutline(Action):
73
73
  self,
74
74
  article_proposal: ArticleProposal,
75
75
  **_,
76
- ) -> ArticleOutline:
76
+ ) -> Optional[ArticleOutline]:
77
77
  return await self.propose(
78
78
  ArticleOutline,
79
79
  article_proposal.display(),
@@ -1,7 +1,5 @@
1
1
  """Dump the finalized output to a file."""
2
2
 
3
- from typing import Unpack
4
-
5
3
  from fabricatio.models.action import Action
6
4
  from fabricatio.models.generic import FinalizedDumpAble
7
5
  from fabricatio.models.task import Task
@@ -12,7 +10,7 @@ class DumpFinalizedOutput(Action):
12
10
 
13
11
  output_key: str = "dump_path"
14
12
 
15
- async def _execute(self, task_input: Task, to_dump: FinalizedDumpAble, **cxt: Unpack) -> str:
13
+ async def _execute(self, task_input: Task, to_dump: FinalizedDumpAble, **_) -> str:
16
14
  dump_path = await self.awhich_pathstr(
17
15
  f"{task_input.briefing}\n\nExtract a single path of the file, to which I will dump the data."
18
16
  )
@@ -1,6 +1,6 @@
1
1
  """Inject data into the database."""
2
2
 
3
- from typing import List, Optional, Unpack
3
+ from typing import List, Optional
4
4
 
5
5
  from fabricatio.capabilities.rag import RAG
6
6
  from fabricatio.models.action import Action
@@ -13,7 +13,7 @@ class InjectToDB(Action, RAG):
13
13
  output_key: str = "collection_name"
14
14
 
15
15
  async def _execute[T: PrepareVectorization](
16
- self, to_inject: T | List[T], collection_name: Optional[str] = "my_collection", **cxt: Unpack
16
+ self, to_inject: T | List[T], collection_name: Optional[str] = "my_collection", **_
17
17
  ) -> Optional[str]:
18
18
  if not isinstance(to_inject, list):
19
19
  to_inject = [to_inject]
@@ -0,0 +1,103 @@
1
+ """Correct capability module providing advanced review and validation functionality.
2
+
3
+ This module implements the Correct capability, which extends the Review functionality
4
+ to provide mechanisms for reviewing, validating, and correcting various objects and tasks
5
+ based on predefined criteria and templates.
6
+ """
7
+
8
+ from typing import Optional, Unpack
9
+
10
+ from fabricatio._rust_instances import TEMPLATE_MANAGER
11
+ from fabricatio.capabilities.review import Review, ReviewResult
12
+ from fabricatio.config import configs
13
+ from fabricatio.models.generic import Display, ProposedAble, WithBriefing
14
+ from fabricatio.models.kwargs_types import ReviewKwargs
15
+ from fabricatio.models.task import Task
16
+
17
+
18
+ class Correct(Review):
19
+ """Correct capability for reviewing, validating, and improving objects.
20
+
21
+ This class enhances the Review capability with specialized functionality for
22
+ correcting and improving objects based on review feedback. It can process
23
+ various inputs including tasks, strings, and generic objects that implement
24
+ the required interfaces, applying corrections based on templated review processes.
25
+ """
26
+
27
+ async def correct_obj[M: ProposedAble](
28
+ self, obj: M, **kwargs: Unpack[ReviewKwargs[ReviewResult[str]]]
29
+ ) -> Optional[M]:
30
+ """Review and correct an object based on defined criteria and templates.
31
+
32
+ This method first conducts a review of the given object, then uses the review results
33
+ to generate a corrected version of the object using appropriate templates.
34
+
35
+ Args:
36
+ obj (M): The object to be reviewed and corrected. Must implement ProposedAble.
37
+ **kwargs: Review configuration parameters including criteria and review options.
38
+
39
+ Returns:
40
+ Optional[M]: A corrected version of the input object, or None if correction fails.
41
+
42
+ Raises:
43
+ TypeError: If the provided object doesn't implement Display or WithBriefing interfaces.
44
+ """
45
+ if not isinstance(obj, (Display, WithBriefing)):
46
+ raise TypeError(f"Expected Display or WithBriefing, got {type(obj)}")
47
+ review_res = await self.review_obj(obj, **kwargs)
48
+ await review_res.supervisor_check()
49
+ if "default" in kwargs:
50
+ kwargs["default"] = None
51
+ return await self.propose(
52
+ obj.__class__,
53
+ TEMPLATE_MANAGER.render_template(
54
+ configs.templates.correct_template,
55
+ {
56
+ "content": obj.display() if isinstance(obj, Display) else obj.briefing,
57
+ "review": review_res.display(),
58
+ },
59
+ ),
60
+ **kwargs,
61
+ )
62
+
63
+ async def correct_string(self, input_text: str, **kwargs: Unpack[ReviewKwargs[ReviewResult[str]]]) -> Optional[str]:
64
+ """Review and correct a string based on defined criteria and templates.
65
+
66
+ This method applies the review process to the input text and generates
67
+ a corrected version based on the review results.
68
+
69
+ Args:
70
+ input_text (str): The text content to be reviewed and corrected.
71
+ **kwargs: Review configuration parameters including criteria and review options.
72
+
73
+ Returns:
74
+ Optional[str]: The corrected text content, or None if correction fails.
75
+ """
76
+ review_res = await self.review_string(input_text, **kwargs)
77
+ await review_res.supervisor_check()
78
+
79
+ if "default" in kwargs:
80
+ kwargs["default"] = None
81
+ return await self.ageneric_string(
82
+ TEMPLATE_MANAGER.render_template(
83
+ configs.templates.correct_template, {"content": input_text, "review": review_res.display()}
84
+ ),
85
+ **kwargs,
86
+ )
87
+
88
+ async def correct_task[T](
89
+ self, task: Task[T], **kwargs: Unpack[ReviewKwargs[ReviewResult[str]]]
90
+ ) -> Optional[Task[T]]:
91
+ """Review and correct a task object based on defined criteria.
92
+
93
+ This is a specialized version of correct_obj specifically for Task objects,
94
+ applying the same review and correction process to task definitions.
95
+
96
+ Args:
97
+ task (Task[T]): The task to be reviewed and corrected.
98
+ **kwargs: Review configuration parameters including criteria and review options.
99
+
100
+ Returns:
101
+ Optional[Task[T]]: The corrected task, or None if correction fails.
102
+ """
103
+ return await self.correct_obj(task, **kwargs)
@@ -8,9 +8,9 @@ from functools import lru_cache
8
8
  from operator import itemgetter
9
9
  from os import PathLike
10
10
  from pathlib import Path
11
- from typing import Any, Callable, Dict, List, Optional, Self, Union, Unpack, overload
11
+ from typing import Any, Callable, Dict, List, Optional, Self, Union, Unpack, cast, overload
12
12
 
13
- from fabricatio._rust_instances import template_manager
13
+ from fabricatio._rust_instances import TEMPLATE_MANAGER
14
14
  from fabricatio.config import configs
15
15
  from fabricatio.journal import logger
16
16
  from fabricatio.models.kwargs_types import (
@@ -111,9 +111,9 @@ class RAG(EmbeddingUsage):
111
111
  create (bool): Whether to create the collection if it does not exist.
112
112
  **kwargs (Unpack[CollectionSimpleConfigKwargs]): Additional keyword arguments for collection configuration.
113
113
  """
114
- if create and collection_name and not self._client.has_collection(collection_name):
114
+ if create and collection_name and self.client.has_collection(collection_name):
115
115
  kwargs["dimension"] = kwargs.get("dimension") or self.milvus_dimensions or configs.rag.milvus_dimensions
116
- self._client.create_collection(collection_name, auto_id=True, **kwargs)
116
+ self.client.create_collection(collection_name, auto_id=True, **kwargs)
117
117
  logger.info(f"Creating collection {collection_name}")
118
118
 
119
119
  self.target_collection = collection_name
@@ -152,15 +152,17 @@ class RAG(EmbeddingUsage):
152
152
  Self: The current instance, allowing for method chaining.
153
153
  """
154
154
  if isinstance(data, MilvusData):
155
- data = data.prepare_insertion()
156
- if isinstance(data, list):
157
- data = [d.prepare_insertion() if isinstance(d, MilvusData) else d for d in data]
155
+ prepared_data = data.prepare_insertion()
156
+ elif isinstance(data, list):
157
+ prepared_data = [d.prepare_insertion() if isinstance(d, MilvusData) else d for d in data]
158
+ else:
159
+ raise TypeError(f"Expected MilvusData or list of MilvusData, got {type(data)}")
158
160
  c_name = collection_name or self.safe_target_collection
159
- self._client.insert(c_name, data)
161
+ self.client.insert(c_name, prepared_data)
160
162
 
161
163
  if flush:
162
164
  logger.debug(f"Flushing collection {c_name}")
163
- self._client.flush(c_name)
165
+ self.client.flush(c_name)
164
166
  return self
165
167
 
166
168
  async def consume_file(
@@ -196,14 +198,14 @@ class RAG(EmbeddingUsage):
196
198
  self.add_document(await self.pack(text), collection_name or self.safe_target_collection, flush=True)
197
199
  return self
198
200
 
199
- async def afetch_document(
201
+ async def afetch_document[V: (int, str, float, bytes)](
200
202
  self,
201
203
  vecs: List[List[float]],
202
204
  desired_fields: List[str] | str,
203
205
  collection_name: Optional[str] = None,
204
206
  similarity_threshold: float = 0.37,
205
207
  result_per_query: int = 10,
206
- ) -> List[Dict[str, Any]] | List[Any]:
208
+ ) -> List[Dict[str, Any]] | List[V]:
207
209
  """Fetch data from the collection.
208
210
 
209
211
  Args:
@@ -217,7 +219,7 @@ class RAG(EmbeddingUsage):
217
219
  List[Dict[str, Any]] | List[Any]: The retrieved data.
218
220
  """
219
221
  # Step 1: Search for vectors
220
- search_results = self._client.search(
222
+ search_results = self.client.search(
221
223
  collection_name or self.safe_target_collection,
222
224
  vecs,
223
225
  search_params={"radius": similarity_threshold},
@@ -237,7 +239,7 @@ class RAG(EmbeddingUsage):
237
239
 
238
240
  if isinstance(desired_fields, list):
239
241
  return resp
240
- return [r.get(desired_fields) for r in resp]
242
+ return [r.get(desired_fields) for r in resp] # extract the single field as list
241
243
 
242
244
  async def aretrieve(
243
245
  self,
@@ -257,12 +259,13 @@ class RAG(EmbeddingUsage):
257
259
  """
258
260
  if isinstance(query, str):
259
261
  query = [query]
260
- return (
262
+ return cast(
263
+ List[str],
261
264
  await self.afetch_document(
262
265
  vecs=(await self.vectorize(query)),
263
266
  desired_fields="text",
264
267
  **kwargs,
265
- )
268
+ ),
266
269
  )[:final_limit]
267
270
 
268
271
  async def aask_retrieved(
@@ -303,7 +306,7 @@ class RAG(EmbeddingUsage):
303
306
  similarity_threshold=similarity_threshold,
304
307
  )
305
308
 
306
- rendered = template_manager.render_template(configs.templates.retrieved_display_template, {"docs": docs[::-1]})
309
+ rendered = TEMPLATE_MANAGER.render_template(configs.templates.retrieved_display_template, {"docs": docs[::-1]})
307
310
 
308
311
  logger.debug(f"Retrieved Documents: \n{rendered}")
309
312
  return await self.aask(
@@ -323,7 +326,7 @@ class RAG(EmbeddingUsage):
323
326
  List[str]: A list of refined questions.
324
327
  """
325
328
  return await self.aliststr(
326
- template_manager.render_template(
329
+ TEMPLATE_MANAGER.render_template(
327
330
  configs.templates.refined_query_template,
328
331
  {"question": [question] if isinstance(question, str) else question},
329
332
  ),
@@ -4,7 +4,7 @@ from itertools import permutations
4
4
  from random import sample
5
5
  from typing import Dict, List, Optional, Set, Tuple, Union, Unpack, overload
6
6
 
7
- from fabricatio._rust_instances import template_manager
7
+ from fabricatio._rust_instances import TEMPLATE_MANAGER
8
8
  from fabricatio.config import configs
9
9
  from fabricatio.journal import logger
10
10
  from fabricatio.models.generic import WithBriefing
@@ -53,7 +53,7 @@ class GiveRating(WithBriefing, LLMUsage):
53
53
  logger.info(f"Rating for {to_rate}")
54
54
  return await self.aask_validate(
55
55
  question=(
56
- template_manager.render_template(
56
+ TEMPLATE_MANAGER.render_template(
57
57
  configs.templates.rate_fine_grind_template,
58
58
  {
59
59
  "to_rate": to_rate,
@@ -65,7 +65,7 @@ class GiveRating(WithBriefing, LLMUsage):
65
65
  )
66
66
  if isinstance(to_rate, str)
67
67
  else [
68
- template_manager.render_template(
68
+ TEMPLATE_MANAGER.render_template(
69
69
  configs.templates.rate_fine_grind_template,
70
70
  {
71
71
  "to_rate": item,
@@ -150,7 +150,7 @@ class GiveRating(WithBriefing, LLMUsage):
150
150
 
151
151
  return await self.aask_validate(
152
152
  question=(
153
- template_manager.render_template(
153
+ TEMPLATE_MANAGER.render_template(
154
154
  configs.templates.draft_rating_manual_template,
155
155
  {
156
156
  "topic": topic,
@@ -180,7 +180,7 @@ class GiveRating(WithBriefing, LLMUsage):
180
180
  """
181
181
  return await self.aask_validate(
182
182
  question=(
183
- template_manager.render_template(
183
+ TEMPLATE_MANAGER.render_template(
184
184
  configs.templates.draft_rating_criteria_template,
185
185
  {
186
186
  "topic": topic,
@@ -230,7 +230,7 @@ class GiveRating(WithBriefing, LLMUsage):
230
230
  reasons = flatten(
231
231
  await self.aask_validate(
232
232
  question=[
233
- template_manager.render_template(
233
+ TEMPLATE_MANAGER.render_template(
234
234
  configs.templates.extract_reasons_from_examples_template,
235
235
  {
236
236
  "topic": topic,
@@ -250,7 +250,7 @@ class GiveRating(WithBriefing, LLMUsage):
250
250
  # extract certain mount of criteria from reasons according to their importance and frequency
251
251
  return await self.aask_validate(
252
252
  question=(
253
- template_manager.render_template(
253
+ TEMPLATE_MANAGER.render_template(
254
254
  configs.templates.extract_criteria_from_reasons_template,
255
255
  {
256
256
  "topic": topic,
@@ -290,7 +290,7 @@ class GiveRating(WithBriefing, LLMUsage):
290
290
  # get the importance multiplier indicating how important is second criterion compared to the first one
291
291
  relative_weights = await self.aask_validate(
292
292
  question=[
293
- template_manager.render_template(
293
+ TEMPLATE_MANAGER.render_template(
294
294
  configs.templates.draft_rating_weights_klee_template,
295
295
  {
296
296
  "topic": topic,