fabricatio 0.2.4.dev0__tar.gz → 0.2.4.dev2__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 (100) hide show
  1. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/PKG-INFO +1 -1
  2. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/extract_article/extract.py +7 -4
  3. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/llm_usages/llm_usage.py +3 -10
  4. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/make_a_rating/rating.py +3 -9
  5. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/make_diary/diary.py +1 -7
  6. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/minor/hello_fabricatio.py +0 -1
  7. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/propose_task/propose.py +0 -1
  8. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/simple_chat/chat.py +0 -1
  9. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/simple_rag/simple_rag.py +0 -1
  10. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/task_handle/handle_task.py +3 -15
  11. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/pyproject.toml +1 -1
  12. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/__init__.py +6 -2
  13. fabricatio-0.2.4.dev2/python/fabricatio/actions/article.py +49 -0
  14. fabricatio-0.2.4.dev2/python/fabricatio/actions/rag.py +25 -0
  15. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/capabilities/rating.py +12 -36
  16. fabricatio-0.2.4.dev2/python/fabricatio/fs/__init__.py +17 -0
  17. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/action.py +19 -4
  18. fabricatio-0.2.4.dev0/python/fabricatio/actions/article.py → fabricatio-0.2.4.dev2/python/fabricatio/models/extra.py +27 -58
  19. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/generic.py +36 -0
  20. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/usages.py +15 -23
  21. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/parser.py +6 -10
  22. fabricatio-0.2.4.dev2/python/fabricatio/workflows/articles.py +11 -0
  23. fabricatio-0.2.4.dev2/templates.tar.gz +0 -0
  24. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/tests/test_models/test_action.py +2 -2
  25. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/tests/test_models/test_task.py +2 -2
  26. fabricatio-0.2.4.dev2/uv.lock +1509 -0
  27. fabricatio-0.2.4.dev0/python/fabricatio/actions/__init__.py +0 -5
  28. fabricatio-0.2.4.dev0/python/fabricatio/fs/__init__.py +0 -5
  29. fabricatio-0.2.4.dev0/templates.tar.gz +0 -0
  30. fabricatio-0.2.4.dev0/uv.lock +0 -1509
  31. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/.github/workflows/build-package.yaml +0 -0
  32. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/.github/workflows/ruff.yaml +0 -0
  33. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/.github/workflows/tests.yaml +0 -0
  34. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/.gitignore +0 -0
  35. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/.python-version +0 -0
  36. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/Cargo.lock +0 -0
  37. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/Cargo.toml +0 -0
  38. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/LICENSE +0 -0
  39. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/Makefile +0 -0
  40. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/README.md +0 -0
  41. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/examples/make_diary/commits.json +0 -0
  42. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/_rust.pyi +0 -0
  43. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/_rust_instances.py +0 -0
  44. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/capabilities/propose.py +0 -0
  45. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/capabilities/rag.py +0 -0
  46. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/capabilities/task.py +0 -0
  47. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/config.py +0 -0
  48. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/core.py +0 -0
  49. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/decorators.py +0 -0
  50. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/fs/curd.py +0 -0
  51. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/fs/readers.py +0 -0
  52. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/journal.py +0 -0
  53. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/events.py +0 -0
  54. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/kwargs_types.py +0 -0
  55. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/role.py +0 -0
  56. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/task.py +0 -0
  57. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/tool.py +0 -0
  58. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/models/utils.py +0 -0
  59. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/py.typed +0 -0
  60. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/toolboxes/__init__.py +0 -0
  61. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  62. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/toolboxes/fs.py +0 -0
  63. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/python/fabricatio/toolboxes/task.py +0 -0
  64. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/src/hash.rs +0 -0
  65. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/src/lib.rs +0 -0
  66. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/src/templates.rs +0 -0
  67. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  68. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/claude-xml.hbs +0 -0
  69. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/clean-up-code.hbs +0 -0
  70. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/create_json_obj.hbs +0 -0
  71. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  72. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/dependencies.hbs +0 -0
  73. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/document-the-code.hbs +0 -0
  74. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/draft_rating_criteria.hbs +0 -0
  75. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/draft_rating_manual.hbs +0 -0
  76. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  77. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  78. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  79. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  80. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  81. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/fix-bugs.hbs +0 -0
  82. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/improve-performance.hbs +0 -0
  83. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/liststr.hbs +0 -0
  84. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/make_choice.hbs +0 -0
  85. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/make_judgment.hbs +0 -0
  86. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/rate_fine_grind.hbs +0 -0
  87. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/refactor.hbs +0 -0
  88. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/retrieved_display.hbs +0 -0
  89. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  90. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/task_briefing.hbs +0 -0
  91. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/web-ctf-solver.hbs +0 -0
  92. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/write-git-commit.hbs +0 -0
  93. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/write-github-pull-request.hbs +0 -0
  94. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/templates/built-in/write-github-readme.hbs +0 -0
  95. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/tests/test_config.py +0 -0
  96. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/tests/test_models/test_advanced.py +0 -0
  97. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/tests/test_models/test_generic.py +0 -0
  98. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/tests/test_models/test_role.py +0 -0
  99. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/tests/test_models/test_tool.py +0 -0
  100. {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev2}/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.4.dev0
3
+ Version: 0.2.4.dev2
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,8 +1,9 @@
1
1
  """Example of proposing a task to a role."""
2
2
 
3
3
  import asyncio
4
+ from typing import List
4
5
 
5
- from fabricatio import Event, ExtractArticleEssence, Role, WorkFlow, logger
6
+ from fabricatio import ArticleEssence, Event, ExtractArticleEssence, Role, Task, WorkFlow, logger
6
7
 
7
8
 
8
9
  async def main() -> None:
@@ -17,9 +18,11 @@ async def main() -> None:
17
18
  )
18
19
  },
19
20
  )
20
- task = await role.propose_task("Extract the essence of the article from the file at './7.md'")
21
- ess = await task.delegate("article")
22
- logger.success(f"Essence:\n{ess}")
21
+ task: Task[List[ArticleEssence]] = await role.propose_task(
22
+ "Extract the essence of the article from the file at './7.md'"
23
+ )
24
+ ess = (await task.delegate("article")).pop()
25
+ logger.success(f"Essence:\n{ess.display()}")
23
26
 
24
27
 
25
28
  if __name__ == "__main__":
@@ -11,7 +11,6 @@ from fabricatio.parser import PythonCapture
11
11
  class WriteCode(Action):
12
12
  """Action that says hello to the world."""
13
13
 
14
- name: str = "write code"
15
14
  output_key: str = "task_output"
16
15
 
17
16
  async def _execute(self, task_input: Task[str], **_) -> str:
@@ -22,10 +21,8 @@ class WriteCode(Action):
22
21
 
23
22
 
24
23
  class WriteDocumentation(Action):
25
- """Action that says hello to the world."""
24
+ """write documentation for the code in markdown format."""
26
25
 
27
- name: str = "write documentation"
28
- description: str = "write documentation for the code in markdown format"
29
26
  output_key: str = "task_output"
30
27
 
31
28
  async def _execute(self, task_input: Task[str], **_) -> str:
@@ -38,12 +35,8 @@ async def main() -> None:
38
35
  name="Coder",
39
36
  description="A python coder who can write code and documentation",
40
37
  registry={
41
- Event.instantiate_from("coding").push_wildcard().push("pending"): WorkFlow(
42
- name="write code", steps=(WriteCode,)
43
- ),
44
- Event.instantiate_from("doc").push_wildcard().push("pending"): WorkFlow(
45
- name="write documentation", steps=(WriteDocumentation,)
46
- ),
38
+ Event.quick_instantiate("coding"): WorkFlow(name="write code", steps=(WriteCode,)),
39
+ Event.quick_instantiate("doc"): WorkFlow(name="write documentation", steps=(WriteDocumentation,)),
47
40
  },
48
41
  )
49
42
 
@@ -12,7 +12,6 @@ from fabricatio.models.task import Task
12
12
  class Rate(Action):
13
13
  """Rate the task."""
14
14
 
15
- name: str = "rate"
16
15
  output_key: str = "task_output"
17
16
 
18
17
  async def _execute(self, to_rate: List[str], rate_topic: str, criteria: Set[str], **_) -> List[Dict[str, float]]:
@@ -28,8 +27,6 @@ class Rate(Action):
28
27
  class WhatToRate(Action):
29
28
  """Figure out what to rate."""
30
29
 
31
- name: str = "figure out what to rate"
32
-
33
30
  output_key: str = "to_rate"
34
31
 
35
32
  async def _execute(self, task_input: Task, rate_topic: str, **cxt: Unpack) -> List[str]:
@@ -55,7 +52,6 @@ class WhatToRate(Action):
55
52
  class MakeCriteria(Action):
56
53
  """Make criteria for rating."""
57
54
 
58
- name: str = "make criteria"
59
55
  output_key: str = "criteria"
60
56
 
61
57
  async def _execute(self, rate_topic: str, to_rate: List[str], **cxt: Unpack) -> Set[str]:
@@ -67,8 +63,6 @@ class MakeCriteria(Action):
67
63
  class MakeCompositeScore(Action):
68
64
  """Make a composite score."""
69
65
 
70
- name: str = "make composite score"
71
-
72
66
  output_key: str = "task_output"
73
67
 
74
68
  async def _execute(self, rate_topic: str, to_rate: List[str], **cxt: Unpack) -> List[float]:
@@ -84,7 +78,7 @@ async def main() -> None:
84
78
  name="TaskRater",
85
79
  description="A role that can rate tasks.",
86
80
  registry={
87
- Event.instantiate_from("rate_food").push_wildcard().push("pending"): WorkFlow(
81
+ Event.quick_instantiate("rate_food"): WorkFlow(
88
82
  name="Rate food",
89
83
  steps=(WhatToRate, Rate),
90
84
  extra_init_context={
@@ -92,14 +86,14 @@ async def main() -> None:
92
86
  "criteria": {"taste", "price", "quality", "safety", "healthiness"},
93
87
  },
94
88
  ),
95
- Event.instantiate_from("make_criteria_for_food").push_wildcard().push("pending"): WorkFlow(
89
+ Event.quick_instantiate("make_criteria_for_food"): WorkFlow(
96
90
  name="Make criteria for food",
97
91
  steps=(WhatToRate, MakeCriteria, Rate),
98
92
  extra_init_context={
99
93
  "rate_topic": "if the food is 'good'",
100
94
  },
101
95
  ),
102
- Event.instantiate_from("make_composite_score").push_wildcard().push("pending"): WorkFlow(
96
+ Event.quick_instantiate("make_composite_score"): WorkFlow(
103
97
  name="Make composite score",
104
98
  steps=(WhatToRate, MakeCompositeScore),
105
99
  extra_init_context={
@@ -13,8 +13,6 @@ from pydantic import Field
13
13
  class WriteDiary(Action):
14
14
  """Write a diary according to the given commit messages in json format."""
15
15
 
16
- name: str = "write diary"
17
- description: str = "write a diary according to the given commit messages in json format"
18
16
  output_key: str = "dump_text"
19
17
 
20
18
  async def _execute(self, task_input: Task[str], **_) -> str:
@@ -50,8 +48,6 @@ class WriteDiary(Action):
50
48
  class DumpText(Action):
51
49
  """Dump the text to a file."""
52
50
 
53
- name: str = "dump text"
54
- description: str = "dump text to a file"
55
51
  toolboxes: Set[ToolBox] = Field(default_factory=lambda: {fs_toolbox})
56
52
  output_key: str = "task_output"
57
53
 
@@ -77,9 +73,7 @@ async def main() -> None:
77
73
  name="Coder",
78
74
  description="A python coder who can ",
79
75
  registry={
80
- Event.instantiate_from("doc").push_wildcard().push("pending"): WorkFlow(
81
- name="write documentation", steps=(WriteDiary, DumpText)
82
- ),
76
+ Event.quick_instantiate("doc"): WorkFlow(name="write documentation", steps=(WriteDiary, DumpText)),
83
77
  },
84
78
  )
85
79
 
@@ -11,7 +11,6 @@ task = Task(name="say hello", goals=["say hello"], description="say hello to the
11
11
  class Hello(Action):
12
12
  """Action that says hello."""
13
13
 
14
- name: str = "hello"
15
14
  output_key: str = "task_output"
16
15
 
17
16
  async def _execute(self, task_input: Task[str], **_) -> Any:
@@ -9,7 +9,6 @@ from fabricatio import Action, Event, Role, Task, WorkFlow, logger
9
9
  class Talk(Action):
10
10
  """Action that says hello to the world."""
11
11
 
12
- name: str = "talk"
13
12
  output_key: str = "task_output"
14
13
 
15
14
  async def _execute(self, **_) -> Any:
@@ -10,7 +10,6 @@ from questionary import text
10
10
  class Talk(Action):
11
11
  """Action that says hello to the world."""
12
12
 
13
- name: str = "talk"
14
13
  output_key: str = "task_output"
15
14
 
16
15
  async def _execute(self, task_input: Task[str], **_) -> int:
@@ -10,7 +10,6 @@ from questionary import text
10
10
  class Talk(Action, RAG):
11
11
  """Action that says hello to the world."""
12
12
 
13
- name: str = "talk"
14
13
  output_key: str = "task_output"
15
14
 
16
15
  async def _execute(self, task_input: Task[str], **_) -> int:
@@ -10,7 +10,6 @@ from pydantic import Field
10
10
  class WriteCode(Action):
11
11
  """Action that says hello to the world."""
12
12
 
13
- name: str = "write code"
14
13
  output_key: str = "dump_text"
15
14
 
16
15
  async def _execute(self, task_input: Task[str], **_) -> str:
@@ -24,8 +23,6 @@ class WriteCode(Action):
24
23
  class DumpText(Action):
25
24
  """Dump the text to a file."""
26
25
 
27
- name: str = "dump text"
28
- description: str = "dump text to a file"
29
26
  toolboxes: Set[ToolBox] = Field(default_factory=lambda: {fs_toolbox})
30
27
  output_key: str = "task_output"
31
28
 
@@ -48,8 +45,6 @@ class DumpText(Action):
48
45
  class WriteDocumentation(Action):
49
46
  """Action that says hello to the world."""
50
47
 
51
- name: str = "write documentation"
52
- description: str = "write documentation for the code in markdown format"
53
48
  output_key: str = "dump_text"
54
49
 
55
50
  async def _execute(self, task_input: Task[str], **_) -> str:
@@ -59,8 +54,6 @@ class WriteDocumentation(Action):
59
54
  class TestCancel(Action):
60
55
  """Action that says hello to the world."""
61
56
 
62
- name: str = "cancel"
63
- description: str = "cancel the task"
64
57
  output_key: str = "counter"
65
58
 
66
59
  async def _execute(self, counter: int, **_) -> int:
@@ -73,7 +66,6 @@ class TestCancel(Action):
73
66
  class WriteToOutput(Action):
74
67
  """Action that says hello to the world."""
75
68
 
76
- name: str = "write to output"
77
69
  output_key: str = "task_output"
78
70
 
79
71
  async def _execute(self, **_) -> str:
@@ -86,13 +78,9 @@ async def main() -> None:
86
78
  name="Coder",
87
79
  description="A python coder who can ",
88
80
  registry={
89
- Event.instantiate_from("coding").push_wildcard().push("pending"): WorkFlow(
90
- name="write code", steps=(WriteCode, DumpText)
91
- ),
92
- Event.instantiate_from("doc").push_wildcard().push("pending"): WorkFlow(
93
- name="write documentation", steps=(WriteDocumentation, DumpText)
94
- ),
95
- Event.instantiate_from("cancel_test").push_wildcard().push("pending"): WorkFlow(
81
+ Event.quick_instantiate("coding"): WorkFlow(name="write code", steps=(WriteCode, DumpText)),
82
+ Event.quick_instantiate("doc"): WorkFlow(name="write documentation", steps=(WriteDocumentation, DumpText)),
83
+ Event.quick_instantiate("cancel_test"): WorkFlow(
96
84
  name="cancel_test",
97
85
  steps=(TestCancel, TestCancel, TestCancel, TestCancel, TestCancel, TestCancel, WriteToOutput),
98
86
  extra_init_context={"counter": 0},
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.4-dev0"
3
+ version = "0.2.4-dev2"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -3,12 +3,13 @@
3
3
  from importlib.util import find_spec
4
4
 
5
5
  from fabricatio._rust_instances import template_manager
6
- from fabricatio.actions import ExtractArticleEssence
6
+ from fabricatio.actions.article import ExtractArticleEssence
7
7
  from fabricatio.core import env
8
8
  from fabricatio.fs import magika
9
9
  from fabricatio.journal import logger
10
10
  from fabricatio.models.action import Action, WorkFlow
11
11
  from fabricatio.models.events import Event
12
+ from fabricatio.models.extra import ArticleEssence
12
13
  from fabricatio.models.role import Role
13
14
  from fabricatio.models.task import Task
14
15
  from fabricatio.models.tool import ToolBox
@@ -18,6 +19,7 @@ from fabricatio.toolboxes import arithmetic_toolbox, basic_toolboxes, fs_toolbox
18
19
 
19
20
  __all__ = [
20
21
  "Action",
22
+ "ArticleEssence",
21
23
  "Capture",
22
24
  "CodeBlockCapture",
23
25
  "Event",
@@ -42,6 +44,8 @@ __all__ = [
42
44
 
43
45
 
44
46
  if find_spec("pymilvus"):
47
+ from fabricatio.actions.rag import InjectToDB
45
48
  from fabricatio.capabilities.rag import RAG
49
+ from fabricatio.workflows.articles import StoreArticle
46
50
 
47
- __all__ += ["RAG"]
51
+ __all__ += ["RAG", "InjectToDB", "StoreArticle"]
@@ -0,0 +1,49 @@
1
+ """Actions for transmitting tasks to targets."""
2
+
3
+ from os import PathLike
4
+ from pathlib import Path
5
+ from typing import Callable, List
6
+
7
+ from fabricatio.journal import logger
8
+ from fabricatio.models.action import Action
9
+ from fabricatio.models.extra import ArticleEssence
10
+ from fabricatio.models.task import Task
11
+
12
+
13
+ class ExtractArticleEssence(Action):
14
+ """Extract the essence of article(s) in text format from the paths specified in the task dependencies.
15
+
16
+ Notes:
17
+ This action is designed to extract vital information from articles with Markdown format, which is pure text, and
18
+ which is converted from pdf files using `magic-pdf` from the `MinerU` project, see https://github.com/opendatalab/MinerU
19
+ """
20
+
21
+ name: str = "extract article essence"
22
+ """The name of the action."""
23
+ description: str = "Extract the essence of article(s) from the paths specified in the task dependencies."
24
+ """The description of the action."""
25
+
26
+ output_key: str = "article_essence"
27
+ """The key of the output data."""
28
+
29
+ async def _execute[P: PathLike | str](
30
+ self,
31
+ task_input: Task,
32
+ reader: Callable[[P], str] = lambda p: Path(p).read_text(encoding="utf-8"),
33
+ **_,
34
+ ) -> List[ArticleEssence]:
35
+ if not await self.ajudge(
36
+ f"= Task\n{task_input.briefing}\n\n\n= Role\n{self.briefing}",
37
+ affirm_case="The task does not violate the role, and could be approved since the file dependencies are specified.",
38
+ deny_case="The task does violate the role, and could not be approved.",
39
+ ):
40
+ logger.info(err := "Task not approved.")
41
+ raise RuntimeError(err)
42
+
43
+ # trim the references
44
+ contents = ["References".join(c.split("References")[:-1]) for c in map(reader, task_input.dependencies)]
45
+ return await self.propose(
46
+ ArticleEssence,
47
+ contents,
48
+ system_message=f"# your personal briefing: \n{self.briefing}",
49
+ )
@@ -0,0 +1,25 @@
1
+ """Inject data into the database."""
2
+
3
+ from typing import List, Optional, Unpack
4
+
5
+ from fabricatio.capabilities.rag import RAG
6
+ from fabricatio.models.action import Action
7
+ from fabricatio.models.generic import PrepareVectorization
8
+
9
+
10
+ class InjectToDB(Action, RAG):
11
+ """Inject data into the database."""
12
+
13
+ output_key: str = "collection_name"
14
+
15
+ async def _execute[T: PrepareVectorization](
16
+ self, to_inject: T | List[T], collection_name: Optional[str] = "my_collection", **cxt: Unpack
17
+ ) -> str:
18
+ if not isinstance(to_inject, list):
19
+ to_inject = [to_inject]
20
+
21
+ await self.view(collection_name, create=True).consume_string(
22
+ [t.prepare_vectorization(self.embedding_max_sequence_length) for t in to_inject],
23
+ )
24
+
25
+ return collection_name
@@ -131,8 +131,7 @@ class GiveRating(WithBriefing, LLMUsage):
131
131
 
132
132
  def _validator(response: str) -> Dict[str, str] | None:
133
133
  if (
134
- (json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
135
- and isinstance(json_data, dict)
134
+ (json_data := JsonCapture.validate_with(response, target_type=dict, elements_type=str)) is not None
136
135
  and json_data.keys() == criteria
137
136
  and all(isinstance(v, str) for v in json_data.values())
138
137
  ):
@@ -173,11 +172,10 @@ class GiveRating(WithBriefing, LLMUsage):
173
172
 
174
173
  def _validator(response: str) -> Set[str] | None:
175
174
  if (
176
- (json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
177
- and isinstance(json_data, list)
178
- and all(isinstance(v, str) for v in json_data)
179
- and (criteria_count == 0 or len(json_data) == criteria_count)
180
- ):
175
+ json_data := JsonCapture.validate_with(
176
+ response, target_type=list, elements_type=str, length=criteria_count
177
+ )
178
+ ) is not None:
181
179
  return set(json_data)
182
180
  return None
183
181
 
@@ -219,27 +217,6 @@ class GiveRating(WithBriefing, LLMUsage):
219
217
  Returns:
220
218
  Set[str]: A set of drafted rating criteria.
221
219
  """
222
-
223
- def _reasons_validator(response: str) -> List[str] | None:
224
- if (
225
- (json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
226
- and isinstance(json_data, list)
227
- and all(isinstance(v, str) for v in json_data)
228
- and len(json_data) == reasons_count
229
- ):
230
- return json_data
231
- return None
232
-
233
- def _criteria_validator(response: str) -> Set[str] | None:
234
- if (
235
- (json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
236
- and isinstance(json_data, list)
237
- and all(isinstance(v, str) for v in json_data)
238
- and len(json_data) == criteria_count
239
- ):
240
- return set(json_data)
241
- return None
242
-
243
220
  kwargs = GenerateKwargs(system_message=f"# your personal briefing: \n{self.briefing}", **kwargs)
244
221
  # extract reasons from the comparison of ordered pairs of extracted from examples
245
222
  reasons = flatten(
@@ -256,7 +233,9 @@ class GiveRating(WithBriefing, LLMUsage):
256
233
  )
257
234
  for pair in (permutations(examples, 2))
258
235
  ],
259
- validator=_reasons_validator,
236
+ validator=lambda resp: JsonCapture.validate_with(
237
+ resp, target_type=list, elements_type=str, length=reasons_count
238
+ ),
260
239
  **kwargs,
261
240
  )
262
241
  )
@@ -272,7 +251,9 @@ class GiveRating(WithBriefing, LLMUsage):
272
251
  },
273
252
  )
274
253
  ),
275
- validator=_criteria_validator,
254
+ validator=lambda resp: set(out)
255
+ if (out := JsonCapture.validate_with(resp, target_type=list, elements_type=str, length=criteria_count))
256
+ else None,
276
257
  **kwargs,
277
258
  )
278
259
 
@@ -295,11 +276,6 @@ class GiveRating(WithBriefing, LLMUsage):
295
276
  if len(criteria) < 2: # noqa: PLR2004
296
277
  raise ValueError("At least two criteria are required to draft rating weights")
297
278
 
298
- def _validator(resp: str) -> float | None:
299
- if (cap := JsonCapture.convert_with(resp, orjson.loads)) is not None and isinstance(cap, float):
300
- return cap
301
- return None
302
-
303
279
  criteria = list(criteria) # freeze the order
304
280
  windows = windowed(criteria, 2)
305
281
 
@@ -316,7 +292,7 @@ class GiveRating(WithBriefing, LLMUsage):
316
292
  )
317
293
  for pair in windows
318
294
  ],
319
- validator=_validator,
295
+ validator=lambda resp: JsonCapture.validate_with(resp, target_type=float),
320
296
  **GenerateKwargs(system_message=f"# your personal briefing: \n{self.briefing}", **kwargs),
321
297
  )
322
298
  weights = [1]
@@ -0,0 +1,17 @@
1
+ """FileSystem manipulation module for Fabricatio."""
2
+
3
+ from fabricatio.fs.curd import copy_file, create_directory, delete_directory, delete_file, dump_text, move_file, tree
4
+ from fabricatio.fs.readers import magika, safe_json_read, safe_text_read
5
+
6
+ __all__ = [
7
+ "copy_file",
8
+ "create_directory",
9
+ "delete_directory",
10
+ "delete_file",
11
+ "dump_text",
12
+ "magika",
13
+ "move_file",
14
+ "safe_json_read",
15
+ "safe_text_read",
16
+ "tree",
17
+ ]
@@ -3,7 +3,7 @@
3
3
  import traceback
4
4
  from abc import abstractmethod
5
5
  from asyncio import Queue, create_task
6
- from typing import Any, Dict, Self, Tuple, Type, Union, Unpack
6
+ from typing import Any, Dict, Self, Tuple, Type, Union, Unpack, final
7
7
 
8
8
  from fabricatio.capabilities.rating import GiveRating
9
9
  from fabricatio.capabilities.task import HandleTask, ProposeTask
@@ -17,11 +17,26 @@ from pydantic import Field, PrivateAttr
17
17
  class Action(HandleTask, ProposeTask, GiveRating):
18
18
  """Class that represents an action to be executed in a workflow."""
19
19
 
20
+ name: str = Field(default="")
21
+ """The name of the action."""
22
+ description: str = Field(default="")
23
+ """The description of the action."""
20
24
  personality: str = Field(default="")
21
25
  """The personality of whom the action belongs to."""
22
26
  output_key: str = Field(default="")
23
27
  """The key of the output data."""
24
28
 
29
+ @final
30
+ def model_post_init(self, __context: Any) -> None:
31
+ """Initialize the action by setting the name if not provided.
32
+
33
+ Args:
34
+ __context: The context to be used for initialization.
35
+ """
36
+ self.name = self.name or self.__class__.__name__
37
+
38
+ self.description = self.description or self.__class__.__doc__ or ""
39
+
25
40
  @abstractmethod
26
41
  async def _execute(self, **cxt: Unpack) -> Any:
27
42
  """Execute the action with the provided arguments.
@@ -34,6 +49,7 @@ class Action(HandleTask, ProposeTask, GiveRating):
34
49
  """
35
50
  pass
36
51
 
52
+ @final
37
53
  async def act(self, cxt: Dict[str, Any]) -> Dict[str, Any]:
38
54
  """Perform the action by executing it and setting the output data.
39
55
 
@@ -92,9 +108,8 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
92
108
  Returns:
93
109
  Self: The instance of the workflow with the injected personality.
94
110
  """
95
- for a in self._instances:
96
- if not a.personality:
97
- a.personality = personality
111
+ for a in filter(lambda action: not action.personality, self._instances):
112
+ a.personality = personality
98
113
  return self
99
114
 
100
115
  async def serve(self, task: Task) -> None:
@@ -1,16 +1,9 @@
1
- """Actions for transmitting tasks to targets."""
1
+ """Extra models for built-in actions."""
2
2
 
3
- from os import PathLike
4
- from pathlib import Path
5
- from typing import Callable, List
3
+ from typing import List
6
4
 
7
- from pydantic import BaseModel, Field
8
- from pydantic.config import ConfigDict
9
-
10
- from fabricatio.journal import logger
11
- from fabricatio.models.action import Action
12
- from fabricatio.models.generic import ProposedAble
13
- from fabricatio.models.task import Task
5
+ from fabricatio.models.generic import Display, PrepareVectorization, ProposedAble
6
+ from pydantic import BaseModel, ConfigDict, Field
14
7
 
15
8
 
16
9
  class Equation(BaseModel):
@@ -36,8 +29,28 @@ class Figure(BaseModel):
36
29
  figure_caption: str = Field(...)
37
30
  """The caption accompanying the figure, summarizing its main points and academic value."""
38
31
 
32
+ figure_path: str = Field(...)
33
+ """The file path to the figure"""
34
+
35
+
36
+ class Highlightings(BaseModel):
37
+ """Structured representation of highlighted elements in an academic paper (including equations, algorithms, figures, and tables)."""
38
+
39
+ # Academic Achievements Showcase
40
+ highlighted_equations: List[Equation] = Field(default_factory=list)
41
+ """Core mathematical equations that represent breakthroughs in the field, accompanied by explanations of their physical or conceptual significance."""
42
+
43
+ highlighted_algorithms: List[str] = Field(default_factory=list)
44
+ """Pseudocode for key algorithms, annotated to highlight innovative components."""
45
+
46
+ highlighted_figures: List[Figure] = Field(default_factory=list)
47
+ """Critical diagrams or illustrations, each accompanied by a caption explaining their academic importance."""
48
+
49
+ highlighted_tables: List[str] = Field(default_factory=list)
50
+ """Important data tables, annotated to indicate statistical significance or other notable findings."""
39
51
 
40
- class ArticleEssence(ProposedAble):
52
+
53
+ class ArticleEssence(ProposedAble, Display, PrepareVectorization):
41
54
  """Structured representation of the core elements of an academic paper(providing a comprehensive digital profile of the paper's essential information)."""
42
55
 
43
56
  # Basic Metadata
@@ -66,19 +79,6 @@ class ArticleEssence(ProposedAble):
66
79
  technical_novelty: List[str] = Field(default_factory=list)
67
80
  """Specific technical innovations introduced by the research, listed as individual points."""
68
81
 
69
- # Academic Achievements Showcase
70
- highlighted_equations: List[Equation] = Field(default_factory=list)
71
- """Core mathematical equations that represent breakthroughs in the field, accompanied by explanations of their physical or conceptual significance."""
72
-
73
- highlighted_algorithms: List[str] = Field(default_factory=list)
74
- """Pseudocode for key algorithms, annotated to highlight innovative components."""
75
-
76
- highlighted_figures: List[Figure] = Field(default_factory=list)
77
- """Critical diagrams or illustrations, each accompanied by a caption explaining their academic importance."""
78
-
79
- highlighted_tables: List[str] = Field(default_factory=list)
80
- """Important data tables, annotated to indicate statistical significance or other notable findings."""
81
-
82
82
  # Academic Discussion Dimensions
83
83
  research_problem: str = Field("")
84
84
  """A clearly defined research question or problem addressed by the study."""
@@ -92,36 +92,5 @@ class ArticleEssence(ProposedAble):
92
92
  impact_analysis: str = Field("")
93
93
  """An assessment of the paper's potential influence on the development of the field."""
94
94
 
95
-
96
- class ExtractArticleEssence(Action):
97
- """Extract the essence of article(s)."""
98
-
99
- name: str = "extract article essence"
100
- """The name of the action."""
101
- description: str = "Extract the essence of an article. output as json"
102
- """The description of the action."""
103
-
104
- output_key: str = "article_essence"
105
- """The key of the output data."""
106
-
107
- async def _execute[P: PathLike | str](
108
- self,
109
- task_input: Task,
110
- reader: Callable[[P], str] = lambda p: Path(p).read_text(encoding="utf-8"),
111
- **_,
112
- ) -> List[ArticleEssence]:
113
- if not await self.ajudge(
114
- f"= Task\n{task_input.briefing}\n\n\n= Role\n{self.briefing}",
115
- affirm_case="The task does not violate the role, and could be approved since the file dependencies are specified.",
116
- deny_case="The task does violate the role, and could not be approved.",
117
- ):
118
- logger.info(err := "Task not approved.")
119
- raise RuntimeError(err)
120
-
121
- # trim the references
122
- contents = ["References".join(c.split("References")[:-1]) for c in map(reader, task_input.dependencies)]
123
- return await self.propose(
124
- ArticleEssence,
125
- contents,
126
- system_message=f"# your personal briefing: \n{self.briefing}",
127
- )
95
+ def _prepare_vectorization_inner(self) -> str:
96
+ return self.model_dump_json()