fabricatio 0.2.0.dev19__tar.gz → 0.2.0.dev20__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 (86) hide show
  1. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/.github/workflows/build-package.yaml +1 -1
  2. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/.github/workflows/tests.yaml +2 -2
  3. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/PKG-INFO +118 -9
  4. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/README.md +116 -8
  5. fabricatio-0.2.0.dev20/examples/llm_usages/llm_usage.py +60 -0
  6. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/examples/propose_task/propose.py +1 -1
  7. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/pyproject.toml +4 -1
  8. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/_rust.pyi +3 -3
  9. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/config.py +12 -0
  10. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/journal.py +7 -2
  11. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/action.py +7 -1
  12. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/generic.py +2 -1
  13. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/task.py +9 -3
  14. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/usages.py +28 -13
  15. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/dependencies.hbs +1 -0
  16. fabricatio-0.2.0.dev20/templates/built-in/task_briefing.hbs +8 -0
  17. fabricatio-0.2.0.dev20/templates.tar.gz +0 -0
  18. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/tests/test_config.py +22 -2
  19. fabricatio-0.2.0.dev20/tests/test_models/test_action.py +115 -0
  20. fabricatio-0.2.0.dev20/tests/test_models/test_role.py +93 -0
  21. fabricatio-0.2.0.dev20/tests/test_models/test_task.py +100 -0
  22. fabricatio-0.2.0.dev20/tests/test_models/test_tool.py +64 -0
  23. fabricatio-0.2.0.dev20/tests/test_models/test_usages.py +198 -0
  24. fabricatio-0.2.0.dev20/uv.lock +1868 -0
  25. fabricatio-0.2.0.dev19/examples/llm_usages/llm_usage.py +0 -41
  26. fabricatio-0.2.0.dev19/templates.tar.gz +0 -0
  27. fabricatio-0.2.0.dev19/tests/test_models/test_action.py +0 -53
  28. fabricatio-0.2.0.dev19/tests/test_models/test_role.py +0 -34
  29. fabricatio-0.2.0.dev19/tests/test_models/test_task.py +0 -32
  30. fabricatio-0.2.0.dev19/tests/test_models/test_tool.py +0 -34
  31. fabricatio-0.2.0.dev19/tests/test_models/test_usages.py +0 -20
  32. fabricatio-0.2.0.dev19/uv.lock +0 -1855
  33. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/.github/workflows/ruff.yaml +0 -0
  34. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/.gitignore +0 -0
  35. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/.python-version +0 -0
  36. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/Cargo.lock +0 -0
  37. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/Cargo.toml +0 -0
  38. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/LICENSE +0 -0
  39. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/Makefile +0 -0
  40. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/examples/minor/hello_fabricatio.py +0 -0
  41. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/examples/simple_chat/chat.py +0 -0
  42. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/__init__.py +0 -0
  43. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/_rust_instances.py +0 -0
  44. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/actions/__init__.py +0 -0
  45. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/actions/communication.py +0 -0
  46. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/actions/transmission.py +0 -0
  47. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/core.py +0 -0
  48. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/decorators.py +0 -0
  49. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/fs/__init__.py +0 -0
  50. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/fs/curd.py +0 -0
  51. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/fs/readers.py +0 -0
  52. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/advanced.py +0 -0
  53. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/events.py +0 -0
  54. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/kwargs_types.py +0 -0
  55. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/role.py +0 -0
  56. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/tool.py +0 -0
  57. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/models/utils.py +0 -0
  58. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/parser.py +0 -0
  59. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/py.typed +0 -0
  60. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/toolboxes/__init__.py +0 -0
  61. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  62. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/toolboxes/fs.py +0 -0
  63. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/python/fabricatio/toolboxes/task.py +0 -0
  64. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/src/hash.rs +0 -0
  65. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/src/lib.rs +0 -0
  66. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/src/templates.rs +0 -0
  67. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  68. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/claude-xml.hbs +0 -0
  69. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/clean-up-code.hbs +0 -0
  70. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  71. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/document-the-code.hbs +0 -0
  72. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  73. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  74. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/fix-bugs.hbs +0 -0
  75. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/improve-performance.hbs +0 -0
  76. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/make_choice.hbs +0 -0
  77. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/make_judgment.hbs +0 -0
  78. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/propose_task.hbs +0 -0
  79. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/refactor.hbs +0 -0
  80. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  81. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/web-ctf-solver.hbs +0 -0
  82. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/write-git-commit.hbs +0 -0
  83. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/write-github-pull-request.hbs +0 -0
  84. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/templates/built-in/write-github-readme.hbs +0 -0
  85. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/tests/test_models/test_advanced.py +0 -0
  86. {fabricatio-0.2.0.dev19 → fabricatio-0.2.0.dev20}/tests/test_models/test_generic.py +0 -0
@@ -49,7 +49,7 @@ jobs:
49
49
  rustup default nightly
50
50
  - name: Install deps
51
51
  run: |
52
- uv sync --no-install-project --all-extras
52
+ uv sync --no-install-project --all-extras --index https://pypi.org/simple
53
53
  - name: Build
54
54
  run: |
55
55
  make
@@ -22,8 +22,8 @@ jobs:
22
22
 
23
23
  - name: Install deps
24
24
  run: |
25
- uv sync
26
-
25
+ uv sync --no-install-project --all-extras --index https://pypi.org/simple
26
+ make dev
27
27
  - name: Build
28
28
  run: |
29
29
  pytest tests
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.0.dev19
3
+ Version: 0.2.0.dev20
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -10,6 +10,7 @@ Classifier: Framework :: Pydantic :: 2
10
10
  Classifier: Typing :: Typed
11
11
  Requires-Dist: appdirs>=1.4.4
12
12
  Requires-Dist: asyncio>=3.4.3
13
+ Requires-Dist: asyncstdlib>=3.13.0
13
14
  Requires-Dist: code2prompt
14
15
  Requires-Dist: gitpython>=3.1.44
15
16
  Requires-Dist: litellm>=1.60.0
@@ -47,26 +48,28 @@ Fabricatio is a powerful framework designed to facilitate the creation and manag
47
48
 
48
49
  - [Installation](#installation)
49
50
  - [Usage](#usage)
50
- - [Defining a Task](#defining-a-task)
51
- - [Creating an Action](#creating-an-action)
52
- - [Assigning a Role](#assigning-a-role)
53
- - [Logging](#logging)
51
+ - [Defining a Task](#defining-a-task)
52
+ - [Creating an Action](#creating-an-action)
53
+ - [Assigning a Role](#assigning-a-role)
54
+ - [Logging](#logging)
54
55
  - [Configuration](#configuration)
55
- - [LLM Configuration](#llm-configuration)
56
- - [Debug Configuration](#debug-configuration)
56
+ - [LLM Configuration](#llm-configuration)
57
+ - [Debug Configuration](#debug-configuration)
57
58
  - [Examples](#examples)
58
- - [Simple Task Example](#simple-task-example)
59
- - [Complex Workflow Example](#complex-workflow-example)
59
+ - [Simple Task Example](#simple-task-example)
60
+ - [Complex Workflow Example](#complex-workflow-example)
60
61
  - [Contributing](#contributing)
61
62
  - [License](#license)
62
63
 
63
64
  ## Installation
65
+
64
66
  To install Fabricatio, you can use pip:
65
67
 
66
68
  ```bash
67
69
  pip install fabricatio
68
70
  ```
69
71
 
72
+
70
73
  Alternatively, you can clone the repository and install it manually:
71
74
 
72
75
  ```bash
@@ -231,3 +234,109 @@ Contributions to Fabricatio are welcome! Please submit a pull request with your
231
234
 
232
235
  Fabricatio is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
233
236
 
237
+ ---
238
+
239
+ ### Additional Features and Modules
240
+
241
+ #### Advanced Models and Functionalities
242
+
243
+ The `advanced.py` module provides advanced models and functionalities for handling complex tasks and workflows.
244
+
245
+ ```python
246
+ from fabricatio.models.advanced import ProposeTask, HandleTask
247
+
248
+ class ProposeTaskExample(ProposeTask):
249
+ pass
250
+
251
+ class HandleTaskExample(HandleTask):
252
+ pass
253
+ ```
254
+
255
+
256
+ #### Toolboxes
257
+
258
+ Fabricatio includes various toolboxes for different types of operations. For example, the `arithmetic.py` toolbox provides arithmetic operations.
259
+
260
+ ```python
261
+ from fabricatio.toolboxes.arithmetic import add, subtract, multiply, divide
262
+
263
+ result = add(1, 2)
264
+ print(result) # Output: 3
265
+ ```
266
+
267
+
268
+ #### File System Operations
269
+
270
+ The `fs.py` toolbox offers tools for file system operations such as copying, moving, deleting files, and creating directories.
271
+
272
+ ```python
273
+ from fabricatio.toolboxes.fs import copy_file, move_file, delete_file, create_directory
274
+
275
+ copy_file("source.txt", "destination.txt")
276
+ move_file("old_location.txt", "new_location.txt")
277
+ delete_file("file_to_delete.txt")
278
+ create_directory("new_directory")
279
+ ```
280
+
281
+
282
+ #### Logging Setup
283
+
284
+ The logging setup in Fabricatio is handled by the `journal.py` module, which configures Loguru for logging.
285
+
286
+ ```python
287
+ from fabricatio.journal import logger
288
+
289
+ logger.debug("This is a debug message.")
290
+ logger.info("This is an info message.")
291
+ logger.success("This is a success message.")
292
+ logger.warning("This is a warning message.")
293
+ logger.error("This is an error message.")
294
+ logger.critical("This is a critical message.")
295
+ ```
296
+
297
+
298
+ #### Configuration Management
299
+
300
+ The configuration management in Fabricatio is handled by the `config.py` module, which uses Pydantic for defining and validating configurations.
301
+
302
+ ```python
303
+ from fabricatio.config import Settings, LLMConfig, DebugConfig
304
+
305
+ settings = Settings()
306
+ llm_config = LLMConfig(api_endpoint="https://api.example.com")
307
+ debug_config = DebugConfig(log_level="DEBUG", log_file="fabricatio.log")
308
+ ```
309
+
310
+
311
+ #### Testing
312
+
313
+ Fabricatio includes a suite of test cases to ensure the stability and correctness of the codebase. The tests are located in the `tests` directory and cover various modules and functionalities.
314
+
315
+ ```python
316
+ # Example of a test case for the config module
317
+ import pytest
318
+ from fabricatio.config import DebugConfig
319
+
320
+ def test_debug_config_initialization():
321
+ temp_log_file = "fabricatio.log"
322
+ debug_config = DebugConfig(log_level="DEBUG", log_file=temp_log_file)
323
+ assert debug_config.log_level == "DEBUG"
324
+ assert str(debug_config.log_file) == temp_log_file
325
+ ```
326
+
327
+
328
+ ---
329
+
330
+ ### Conclusion
331
+
332
+ Fabricatio is a versatile and powerful framework for managing tasks, actions, and workflows. It provides a robust set of tools and features to facilitate task automation and orchestration. Whether you're building a simple script or a complex application, Fabricatio has the capabilities to meet your needs.
333
+
334
+ For more detailed information and examples, please refer to the [official documentation](https://fabricatio.readthedocs.io).
335
+
336
+ ---
337
+
338
+ If you have any questions or need further assistance, feel free to reach out to the community or open an issue on the GitHub repository.
339
+
340
+ Happy coding!
341
+
342
+
@@ -8,26 +8,28 @@ Fabricatio is a powerful framework designed to facilitate the creation and manag
8
8
 
9
9
  - [Installation](#installation)
10
10
  - [Usage](#usage)
11
- - [Defining a Task](#defining-a-task)
12
- - [Creating an Action](#creating-an-action)
13
- - [Assigning a Role](#assigning-a-role)
14
- - [Logging](#logging)
11
+ - [Defining a Task](#defining-a-task)
12
+ - [Creating an Action](#creating-an-action)
13
+ - [Assigning a Role](#assigning-a-role)
14
+ - [Logging](#logging)
15
15
  - [Configuration](#configuration)
16
- - [LLM Configuration](#llm-configuration)
17
- - [Debug Configuration](#debug-configuration)
16
+ - [LLM Configuration](#llm-configuration)
17
+ - [Debug Configuration](#debug-configuration)
18
18
  - [Examples](#examples)
19
- - [Simple Task Example](#simple-task-example)
20
- - [Complex Workflow Example](#complex-workflow-example)
19
+ - [Simple Task Example](#simple-task-example)
20
+ - [Complex Workflow Example](#complex-workflow-example)
21
21
  - [Contributing](#contributing)
22
22
  - [License](#license)
23
23
 
24
24
  ## Installation
25
+
25
26
  To install Fabricatio, you can use pip:
26
27
 
27
28
  ```bash
28
29
  pip install fabricatio
29
30
  ```
30
31
 
32
+
31
33
  Alternatively, you can clone the repository and install it manually:
32
34
 
33
35
  ```bash
@@ -191,3 +193,109 @@ Contributions to Fabricatio are welcome! Please submit a pull request with your
191
193
  ## License
192
194
 
193
195
  Fabricatio is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
196
+
197
+ ---
198
+
199
+ ### Additional Features and Modules
200
+
201
+ #### Advanced Models and Functionalities
202
+
203
+ The `advanced.py` module provides advanced models and functionalities for handling complex tasks and workflows.
204
+
205
+ ```python
206
+ from fabricatio.models.advanced import ProposeTask, HandleTask
207
+
208
+ class ProposeTaskExample(ProposeTask):
209
+ pass
210
+
211
+ class HandleTaskExample(HandleTask):
212
+ pass
213
+ ```
214
+
215
+
216
+ #### Toolboxes
217
+
218
+ Fabricatio includes various toolboxes for different types of operations. For example, the `arithmetic.py` toolbox provides arithmetic operations.
219
+
220
+ ```python
221
+ from fabricatio.toolboxes.arithmetic import add, subtract, multiply, divide
222
+
223
+ result = add(1, 2)
224
+ print(result) # Output: 3
225
+ ```
226
+
227
+
228
+ #### File System Operations
229
+
230
+ The `fs.py` toolbox offers tools for file system operations such as copying, moving, deleting files, and creating directories.
231
+
232
+ ```python
233
+ from fabricatio.toolboxes.fs import copy_file, move_file, delete_file, create_directory
234
+
235
+ copy_file("source.txt", "destination.txt")
236
+ move_file("old_location.txt", "new_location.txt")
237
+ delete_file("file_to_delete.txt")
238
+ create_directory("new_directory")
239
+ ```
240
+
241
+
242
+ #### Logging Setup
243
+
244
+ The logging setup in Fabricatio is handled by the `journal.py` module, which configures Loguru for logging.
245
+
246
+ ```python
247
+ from fabricatio.journal import logger
248
+
249
+ logger.debug("This is a debug message.")
250
+ logger.info("This is an info message.")
251
+ logger.success("This is a success message.")
252
+ logger.warning("This is a warning message.")
253
+ logger.error("This is an error message.")
254
+ logger.critical("This is a critical message.")
255
+ ```
256
+
257
+
258
+ #### Configuration Management
259
+
260
+ The configuration management in Fabricatio is handled by the `config.py` module, which uses Pydantic for defining and validating configurations.
261
+
262
+ ```python
263
+ from fabricatio.config import Settings, LLMConfig, DebugConfig
264
+
265
+ settings = Settings()
266
+ llm_config = LLMConfig(api_endpoint="https://api.example.com")
267
+ debug_config = DebugConfig(log_level="DEBUG", log_file="fabricatio.log")
268
+ ```
269
+
270
+
271
+ #### Testing
272
+
273
+ Fabricatio includes a suite of test cases to ensure the stability and correctness of the codebase. The tests are located in the `tests` directory and cover various modules and functionalities.
274
+
275
+ ```python
276
+ # Example of a test case for the config module
277
+ import pytest
278
+ from fabricatio.config import DebugConfig
279
+
280
+ def test_debug_config_initialization():
281
+ temp_log_file = "fabricatio.log"
282
+ debug_config = DebugConfig(log_level="DEBUG", log_file=temp_log_file)
283
+ assert debug_config.log_level == "DEBUG"
284
+ assert str(debug_config.log_file) == temp_log_file
285
+ ```
286
+
287
+
288
+ ---
289
+
290
+ ### Conclusion
291
+
292
+ Fabricatio is a versatile and powerful framework for managing tasks, actions, and workflows. It provides a robust set of tools and features to facilitate task automation and orchestration. Whether you're building a simple script or a complex application, Fabricatio has the capabilities to meet your needs.
293
+
294
+ For more detailed information and examples, please refer to the [official documentation](https://fabricatio.readthedocs.io).
295
+
296
+ ---
297
+
298
+ If you have any questions or need further assistance, feel free to reach out to the community or open an issue on the GitHub repository.
299
+
300
+ Happy coding!
301
+
@@ -0,0 +1,60 @@
1
+ """Example of using the library."""
2
+
3
+ import asyncio
4
+
5
+ from fabricatio import Action, Role, Task, WorkFlow
6
+ from fabricatio.journal import logger
7
+ from fabricatio.models.events import Event
8
+ from fabricatio.parser import PythonCapture
9
+
10
+
11
+ class WriteCode(Action):
12
+ """Action that says hello to the world."""
13
+
14
+ name: str = "write code"
15
+ output_key: str = "task_output"
16
+
17
+ async def _execute(self, task_input: Task[str], **_) -> str:
18
+ return await self.aask_validate(
19
+ task_input.briefing,
20
+ validator=PythonCapture.capture,
21
+ )
22
+
23
+
24
+ class WriteDocumentation(Action):
25
+ """Action that says hello to the world."""
26
+
27
+ name: str = "write documentation"
28
+ description: str = "write documentation for the code in markdown format"
29
+ output_key: str = "task_output"
30
+
31
+ async def _execute(self, task_input: Task[str], **_) -> str:
32
+ return await self.aask(task_input.briefing, task_input.dependencies_prompt)
33
+
34
+
35
+ async def main() -> None:
36
+ """Main function."""
37
+ role = Role(
38
+ name="Coder",
39
+ description="A python coder who can write code and documentation",
40
+ registry={
41
+ Event.instantiate_from("coding.*").push("pending"): WorkFlow(name="write code", steps=(WriteCode,)),
42
+ Event.instantiate_from("doc.*").push("pending"): WorkFlow(
43
+ name="write documentation", steps=(WriteDocumentation,)
44
+ ),
45
+ },
46
+ )
47
+
48
+ prompt = "write a python cli app which can add a list of numbers writen in a file together,with detailed google style documentation."
49
+
50
+ proposed_task = await role.propose(prompt)
51
+ code = await proposed_task.move_to("coding").delegate()
52
+ logger.success(f"Code: \n{code}")
53
+
54
+ proposed_task = await role.propose(f"{code} \n\n write Readme.md file for the code.")
55
+ doc = await proposed_task.move_to("doc").delegate()
56
+ logger.success(f"Documentation: \n{doc}")
57
+
58
+
59
+ if __name__ == "__main__":
60
+ asyncio.run(main())
@@ -14,7 +14,7 @@ class Talk(Action):
14
14
  name: str = "talk"
15
15
  output_key: str = "task_output"
16
16
 
17
- async def _execute(self, task_input: Task[str], **_) -> Any:
17
+ async def _execute(self, **_) -> Any:
18
18
  ret = "Hello fabricatio!"
19
19
  logger.info("executing talk action")
20
20
  return ret
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.0-dev.19"
3
+ version = "0.2.0-dev.20"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -29,6 +29,7 @@ requires-python = ">=3.12"
29
29
  dependencies = [
30
30
  "appdirs>=1.4.4",
31
31
  "asyncio>=3.4.3",
32
+ "asyncstdlib>=3.13.0",
32
33
  "code2prompt",
33
34
  "gitpython>=3.1.44",
34
35
  "litellm>=1.60.0",
@@ -137,6 +138,8 @@ addopts = "-ra -q"
137
138
  testpaths = [
138
139
  "tests",
139
140
  ]
141
+ asyncio_mode = "auto"
142
+ asyncio_default_fixture_loop_scope = "function"
140
143
 
141
144
  [tool.uv.sources]
142
145
  code2prompt = { git = "https://github.com/mufeedvh/code2prompt", rev = "d157ee84827458bd6816142e213886487d28bd3d" }
@@ -1,5 +1,5 @@
1
1
  from pathlib import Path
2
- from typing import Dict, List, Optional
2
+ from typing import Any, Dict, List, Optional
3
3
 
4
4
  class TemplateManager:
5
5
  """TemplateManager class for managing handlebars templates."""
@@ -31,12 +31,12 @@ class TemplateManager:
31
31
  def discover_templates(self) -> None:
32
32
  """Discover templates in the specified directories."""
33
33
 
34
- def render_template(self, name: str, data: Dict[str, str]) -> str:
34
+ def render_template(self, name: str, data: Dict[str, Any]) -> str:
35
35
  """Render a template with the given name and data.
36
36
 
37
37
  Args:
38
38
  name (str): The name of the template to render.
39
- data (Dict[str, str]): The data to pass to the template.
39
+ data (Dict[str, Any]): The data to pass to the template.
40
40
 
41
41
  Returns:
42
42
  str: The rendered template.
@@ -115,6 +115,15 @@ class DebugConfig(BaseModel):
115
115
  log_file: FilePath = Field(default=rf"{ROAMING_DIR}\fabricatio.log")
116
116
  """The log file of the application."""
117
117
 
118
+ rotation: int = Field(default=1)
119
+ """The rotation of the log file. in weeks."""
120
+
121
+ retention: int = Field(default=2)
122
+ """The retention of the log file. in weeks."""
123
+
124
+ streaming_visible: bool = Field(default=False)
125
+ """Whether to print the llm output when streaming."""
126
+
118
127
 
119
128
  class TemplateConfig(BaseModel):
120
129
  """Template configuration class."""
@@ -145,6 +154,9 @@ class TemplateConfig(BaseModel):
145
154
  dependencies_template: str = Field(default="dependencies")
146
155
  """The name of the dependencies template which will be used to manage dependencies."""
147
156
 
157
+ task_briefing_template: str = Field(default="task_briefing")
158
+ """The name of the task briefing template which will be used to brief a task."""
159
+
148
160
 
149
161
  class MagikaConfig(BaseModel):
150
162
  """Magika configuration class."""
@@ -3,17 +3,22 @@
3
3
  import sys
4
4
 
5
5
  from loguru import logger
6
- from rich import traceback
6
+ from rich import pretty, traceback
7
7
 
8
8
  from fabricatio.config import configs
9
9
 
10
+ pretty.install()
10
11
  traceback.install()
11
12
  logger.remove()
12
13
  logger.add(
13
- configs.debug.log_file, level=configs.debug.log_level, rotation="1 weeks", retention="1 month", compression="zip"
14
+ configs.debug.log_file,
15
+ level=configs.debug.log_level,
16
+ rotation=f"{configs.debug.rotation} weeks",
17
+ retention=f"{configs.debug.retention} weeks",
14
18
  )
15
19
  logger.add(sys.stderr, level=configs.debug.log_level)
16
20
 
21
+
17
22
  if __name__ == "__main__":
18
23
  logger.debug("This is a trace message.")
19
24
  logger.info("This is an information message.")
@@ -111,7 +111,13 @@ class WorkFlow[A: Union[Type[Action], Action]](WithBriefing, ToolBoxUsage):
111
111
  await self._context.put(modified_ctx)
112
112
  current_action = step.name
113
113
  logger.info(f"Finished executing workflow: {self.name}")
114
- await task.finish((await self._context.get()).get(self.task_output_key, None))
114
+ final_ctx = await self._context.get()
115
+ if self.task_output_key not in final_ctx:
116
+ logger.warning(
117
+ f"Task output key: {self.task_output_key} not found in the context, None will be returned. You can check if `Action.output_key` is set the same as `WorkFlow.task_output_key`."
118
+ )
119
+
120
+ await task.finish(final_ctx.get(self.task_output_key, None))
115
121
  except RuntimeError as e:
116
122
  logger.error(f"Error during task: {current_action} execution: {e}") # Log the exception
117
123
  logger.error(traceback.format_exc()) # Add this line to log the traceback
@@ -109,7 +109,8 @@ class WithDependency(Base):
109
109
  return template_manager.render_template(
110
110
  configs.templates.dependencies_template,
111
111
  {
112
- (pth := Path(p)).as_posix(): {
112
+ (pth := Path(p)).name: {
113
+ "path": pth.as_posix(),
113
114
  "exists": pth.exists(),
114
115
  "description": (identity := magika.identify_path(pth)).output.description,
115
116
  "size": f"{pth.stat().st_size / (1024 * 1024) if pth.exists() and pth.is_file() else 0:.3f} MB",
@@ -7,6 +7,8 @@ from asyncio import Queue
7
7
  from enum import Enum
8
8
  from typing import Any, List, Optional, Self
9
9
 
10
+ from fabricatio._rust_instances import template_manager
11
+ from fabricatio.config import configs
10
12
  from fabricatio.core import env
11
13
  from fabricatio.journal import logger
12
14
  from fabricatio.models.events import Event, EventLike
@@ -214,7 +216,7 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
214
216
  Returns:
215
217
  Task: The running instance of the `Task` class.
216
218
  """
217
- logger.info(f"Starting task {self.name}")
219
+ logger.info(f"Starting task `{self.name}`")
218
220
  self._status = TaskStatus.Running
219
221
  await env.emit_async(self.running_label, self)
220
222
  return self
@@ -225,6 +227,7 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
225
227
  Returns:
226
228
  Task: The cancelled instance of the `Task` class.
227
229
  """
230
+ logger.info(f"Cancelling task `{self.name}`")
228
231
  self._status = TaskStatus.Cancelled
229
232
  await env.emit_async(self.cancelled_label, self)
230
233
  return self
@@ -235,7 +238,7 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
235
238
  Returns:
236
239
  Task: The failed instance of the `Task` class.
237
240
  """
238
- logger.error(f"Task {self.name} failed")
241
+ logger.info(f"Failing task `{self.name}`")
239
242
  self._status = TaskStatus.Failed
240
243
  await env.emit_async(self.failed_label, self)
241
244
  return self
@@ -267,4 +270,7 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
267
270
  Returns:
268
271
  str: The briefing of the task.
269
272
  """
270
- return f"{super().briefing}\n{self.goal}"
273
+ return template_manager.render_template(
274
+ configs.templates.task_briefing_template,
275
+ self.model_dump(include={"name", "description", "dependencies", "goal"}),
276
+ )
@@ -2,6 +2,7 @@
2
2
 
3
3
  from typing import Callable, Dict, Iterable, List, Optional, Self, Set, Union, Unpack
4
4
 
5
+ import asyncstdlib
5
6
  import litellm
6
7
  import orjson
7
8
  from fabricatio._rust_instances import template_manager
@@ -13,7 +14,13 @@ from fabricatio.models.task import Task
13
14
  from fabricatio.models.tool import Tool, ToolBox
14
15
  from fabricatio.models.utils import Messages
15
16
  from fabricatio.parser import JsonCapture
16
- from litellm.types.utils import Choices, ModelResponse, StreamingChoices
17
+ from litellm import stream_chunk_builder
18
+ from litellm.types.utils import (
19
+ Choices,
20
+ ModelResponse,
21
+ StreamingChoices,
22
+ )
23
+ from litellm.utils import CustomStreamWrapper
17
24
  from pydantic import Field, HttpUrl, NonNegativeFloat, NonNegativeInt, PositiveInt, SecretStr
18
25
 
19
26
 
@@ -58,7 +65,7 @@ class LLMUsage(Base):
58
65
  messages: List[Dict[str, str]],
59
66
  n: PositiveInt | None = None,
60
67
  **kwargs: Unpack[LLMKwargs],
61
- ) -> ModelResponse:
68
+ ) -> ModelResponse | CustomStreamWrapper:
62
69
  """Asynchronously queries the language model to generate a response based on the provided messages and parameters.
63
70
 
64
71
  Args:
@@ -105,13 +112,23 @@ class LLMUsage(Base):
105
112
  Returns:
106
113
  List[Choices | StreamingChoices]: A list of choices or streaming choices from the model response.
107
114
  """
108
- return (
109
- await self.aquery(
110
- messages=Messages().add_system_message(system_message).add_user_message(question),
111
- n=n,
112
- **kwargs,
113
- )
114
- ).choices
115
+ resp = await self.aquery(
116
+ messages=Messages().add_system_message(system_message).add_user_message(question),
117
+ n=n,
118
+ **kwargs,
119
+ )
120
+ if isinstance(resp, ModelResponse):
121
+ return resp.choices
122
+ if isinstance(resp, CustomStreamWrapper):
123
+ if configs.debug.streaming_visible:
124
+ chunks = []
125
+ async for chunk in resp:
126
+ chunks.append(chunk)
127
+ print(chunk.choices[0].delta.content or "", end="") # noqa: T201
128
+ return stream_chunk_builder(chunks).choices
129
+ return stream_chunk_builder(await asyncstdlib.list()).choices
130
+ logger.critical(err := f"Unexpected response type: {type(resp)}")
131
+ raise ValueError(err)
115
132
 
116
133
  async def aask(
117
134
  self,
@@ -137,10 +154,8 @@ class LLMUsage(Base):
137
154
  system_message=system_message,
138
155
  **kwargs,
139
156
  )
140
- )
141
- .pop()
142
- .message.content
143
- )
157
+ ).pop()
158
+ ).message.content
144
159
 
145
160
  async def aask_validate[T](
146
161
  self,
@@ -1,5 +1,6 @@
1
1
  {{#each this}}
2
2
  ### {{@key}}
3
+ - **Path:** {{path}}
3
4
  - **Exists:** {{exists}}
4
5
  - **Description:** {{description}}
5
6
  - **Size:** {{size}}
@@ -0,0 +1,8 @@
1
+ Task Briefing:
2
+ Name: {{name}}
3
+ Description: {{description}}
4
+ Dependencies:
5
+ {{#each dependencies}}
6
+ - `{{this}}`
7
+ {{/each}}
8
+ Goal: {{goal}}
Binary file