fabricatio 0.2.0.dev20__cp312-cp312-win_amd64.whl → 0.2.1.dev0__cp312-cp312-win_amd64.whl

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.
@@ -1,10 +1,11 @@
1
1
  """File system tool box."""
2
2
 
3
- from fabricatio.fs.curd import copy_file, create_directory, delete_directory, delete_file, move_file, tree
3
+ from fabricatio.fs.curd import copy_file, create_directory, delete_directory, delete_file, dump_text, move_file, tree
4
4
  from fabricatio.models.tool import ToolBox
5
5
 
6
6
  fs_toolbox = (
7
- ToolBox(name="FsToolBox", description="A toolbox for file system operations.")
7
+ ToolBox(name="FsToolBox", description="A toolbox for basic file system operations.")
8
+ .add_tool(dump_text)
8
9
  .add_tool(copy_file)
9
10
  .add_tool(move_file)
10
11
  .add_tool(delete_file)
@@ -0,0 +1,419 @@
1
+ Metadata-Version: 2.4
2
+ Name: fabricatio
3
+ Version: 0.2.1.dev0
4
+ Classifier: License :: OSI Approved :: MIT License
5
+ Classifier: Programming Language :: Rust
6
+ Classifier: Programming Language :: Python :: 3.12
7
+ Classifier: Programming Language :: Python :: Implementation :: CPython
8
+ Classifier: Framework :: AsyncIO
9
+ Classifier: Framework :: Pydantic :: 2
10
+ Classifier: Typing :: Typed
11
+ Requires-Dist: appdirs>=1.4.4
12
+ Requires-Dist: asyncio>=3.4.3
13
+ Requires-Dist: asyncstdlib>=3.13.0
14
+ Requires-Dist: gitpython>=3.1.44
15
+ Requires-Dist: litellm>=1.60.0
16
+ Requires-Dist: loguru>=0.7.3
17
+ Requires-Dist: magika>=0.5.1
18
+ Requires-Dist: orjson>=3.10.15
19
+ Requires-Dist: pydantic>=2.10.6
20
+ Requires-Dist: pydantic-settings>=2.7.1
21
+ Requires-Dist: pymitter>=1.0.0
22
+ Requires-Dist: questionary>=2.1.0
23
+ Requires-Dist: regex>=2024.11.6
24
+ Requires-Dist: rich>=13.9.4
25
+ Requires-Dist: faiss-cpu>=1.10.0 ; extra == 'rag'
26
+ Requires-Dist: pymilvus>=2.5.4 ; extra == 'rag'
27
+ Requires-Dist: fabricatio[rag] ; extra == 'full'
28
+ Provides-Extra: rag
29
+ Provides-Extra: full
30
+ License-File: LICENSE
31
+ Summary: A LLM multi-agent framework.
32
+ Keywords: ai,agents,multi-agent,llm,pyo3
33
+ Author-email: Whth <zettainspector@foxmail.com>
34
+ Requires-Python: >=3.12, <3.13
35
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
36
+ Project-URL: Homepage, https://github.com/Whth/fabricatio
37
+ Project-URL: Repository, https://github.com/Whth/fabricatio
38
+ Project-URL: Issues, https://github.com/Whth/fabricatio/issues
39
+
40
+
41
+ # Fabricatio
42
+
43
+ ![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)
44
+ ![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)
45
+ ![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
46
+
47
+ Fabricatio is a Python library designed for building LLM (Large Language Model) applications using an event-based agent structure. It integrates Rust for performance-critical tasks, utilizes Handlebars for templating, and employs PyO3 for Python bindings.
48
+
49
+ ## Features
50
+
51
+ - **Event-Based Architecture**: Utilizes an EventEmitter pattern for robust task management.
52
+ - **LLM Integration**: Supports interactions with large language models for intelligent task processing.
53
+ - **Templating Engine**: Uses Handlebars for dynamic content generation.
54
+ - **Toolboxes**: Provides predefined toolboxes for common operations like file manipulation and arithmetic.
55
+ - **Async Support**: Fully asynchronous for efficient execution.
56
+ - **Extensible**: Easy to extend with custom actions, workflows, and tools.
57
+
58
+ ## Installation
59
+
60
+ ### Using UV (Recommended)
61
+
62
+ To install Fabricatio using `uv` (a package manager for Python):
63
+
64
+ ```bash
65
+ # Install uv if not already installed
66
+ pip install uv
67
+
68
+ # Clone the repository
69
+ git clone https://github.com/Whth/fabricatio.git
70
+ cd fabricatio
71
+
72
+ # Install the package in development mode with uv
73
+ uv --with-editable . maturin develop --uv -r
74
+ ```
75
+
76
+ ### Building Distribution
77
+
78
+ For production builds:
79
+
80
+ ```bash
81
+ # Build distribution packages
82
+ make bdist
83
+ ```
84
+
85
+ This will generate distribution files in the `dist` directory.
86
+
87
+ ## Usage
88
+
89
+ ### Basic Example
90
+
91
+ Below are some basic examples demonstrating how to use Fabricatio for different purposes.
92
+
93
+ #### Simple Hello World Program
94
+
95
+ ```python
96
+ import asyncio
97
+ from fabricatio import Action, Role, Task, logger
98
+
99
+
100
+ class Hello(Action):
101
+ """Action that says hello."""
102
+
103
+ name: str = "hello"
104
+ output_key: str = "task_output"
105
+
106
+ async def _execute(self, task_input: Task[str], **_) -> Any:
107
+ ret = "Hello fabricatio!"
108
+ logger.info("executing talk action")
109
+ return ret
110
+
111
+
112
+ async def main() -> None:
113
+ """Main function."""
114
+ role = Role(
115
+ name="talker",
116
+ description="talker role",
117
+ registry={Task.pending_label: WorkFlow(name="talk", steps=(Hello,))}
118
+ )
119
+
120
+ task = Task(name="say hello", goal="say hello", description="say hello to the world")
121
+ result = await task.delegate()
122
+ logger.success(f"Result: {result}")
123
+
124
+
125
+ if __name__ == "__main__":
126
+ asyncio.run(main())
127
+ ```
128
+
129
+ #### Writing and Dumping Code
130
+
131
+ ```python
132
+ import asyncio
133
+ from fabricatio import Action, Event, PythonCapture, Role, Task, ToolBox, WorkFlow, fs_toolbox, logger
134
+
135
+
136
+ class WriteCode(Action):
137
+ """Action that writes code based on a prompt."""
138
+
139
+ name: str = "write code"
140
+ output_key: str = "source_code"
141
+
142
+ async def _execute(self, task_input: Task[str], **_) -> str:
143
+ return await self.aask_validate(
144
+ task_input.briefing,
145
+ validator=PythonCapture.capture,
146
+ )
147
+
148
+
149
+ class DumpCode(Action):
150
+ """Action that dumps code to the file system."""
151
+
152
+ name: str = "dump code"
153
+ description: str = "Dump code to file system"
154
+ toolboxes: set[ToolBox] = {fs_toolbox}
155
+ output_key: str = "task_output"
156
+
157
+ async def _execute(self, task_input: Task, source_code: str, **_) -> Any:
158
+ path = await self.handle_fin_grind(task_input, {"source_code": source_code})
159
+ return path[0] if path else None
160
+
161
+
162
+ async def main() -> None:
163
+ """Main function."""
164
+ role = Role(
165
+ name="Coder",
166
+ description="A python coder who can write and document code",
167
+ registry={
168
+ Event.instantiate_from("coding.*").push("pending"): WorkFlow(
169
+ name="write code", steps=(WriteCode, DumpCode)
170
+ ),
171
+ },
172
+ )
173
+
174
+ prompt = "write a Python CLI app which prints 'hello world' n times with detailed Google-style docstring. Write the source code to `cli.py`."
175
+
176
+ proposed_task = await role.propose(prompt)
177
+ path = await proposed_task.move_to("coding").delegate()
178
+ logger.success(f"Code Path: {path}")
179
+
180
+
181
+ if __name__ == "__main__":
182
+ asyncio.run(main())
183
+ ```
184
+
185
+ #### Proposing Tasks
186
+
187
+ ```python
188
+ import asyncio
189
+ from typing import Any
190
+
191
+ from fabricatio import Action, Role, Task, WorkFlow, logger
192
+
193
+
194
+ class WriteDocumentation(Action):
195
+ """Action that generates documentation for the code in markdown format."""
196
+
197
+ name: str = "write documentation"
198
+ description: str = "Write detailed documentation for the provided code."
199
+ output_key: str = "task_output"
200
+
201
+ async def _execute(self, task_input: Task[str], **_) -> str:
202
+ return await self.aask(task_input.briefing)
203
+
204
+
205
+ async def main() -> None:
206
+ """Main function."""
207
+ role = Role(
208
+ name="Documenter",
209
+ description="Role responsible for writing documentation.",
210
+ registry={
211
+ "doc.*": WorkFlow(name="write documentation", steps=(WriteDocumentation,))
212
+ }
213
+ )
214
+
215
+ prompt = "write a Rust clap CLI that downloads an HTML page"
216
+ proposed_task = await role.propose(prompt)
217
+ documentation = await proposed_task.move_to("doc").delegate()
218
+ logger.success(f"Documentation:\n{documentation}")
219
+
220
+
221
+ if __name__ == "__main__":
222
+ asyncio.run(main())
223
+ ```
224
+
225
+ #### Complex Workflow Handling
226
+
227
+ ```python
228
+ import asyncio
229
+ from fabricatio import Action, Event, Role, Task, WorkFlow, logger
230
+
231
+
232
+ class WriteCode(Action):
233
+ """Action that writes code based on a prompt."""
234
+
235
+ name: str = "write code"
236
+ output_key: str = "source_code"
237
+
238
+ async def _execute(self, task_input: Task[str], **_) -> str:
239
+ return await self.aask_validate(
240
+ task_input.briefing,
241
+ validator=PythonCapture.capture,
242
+ )
243
+
244
+
245
+ class WriteDocumentation(Action):
246
+ """Action that generates documentation for the code in markdown format."""
247
+
248
+ name: str = "write documentation"
249
+ description: str = "Write detailed documentation for the provided code."
250
+ output_key: str = "task_output"
251
+
252
+ async def _execute(self, task_input: Task[str], **_) -> str:
253
+ return await self.aask(task_input.briefing)
254
+
255
+
256
+ async def main() -> None:
257
+ """Main function."""
258
+ role = Role(
259
+ name="Developer",
260
+ description="A developer who can write code and documentation.",
261
+ registry={
262
+ Event.instantiate_from("coding.*").push("pending"): WorkFlow(
263
+ name="write code", steps=(WriteCode,)
264
+ ),
265
+ Event.instantiate_from("doc.*").push("pending"): WorkFlow(
266
+ name="write documentation", steps=(WriteDocumentation,)
267
+ ),
268
+ }
269
+ )
270
+
271
+ # Propose a coding task
272
+ code_task_prompt = "write a Python CLI app which adds numbers from a file."
273
+ proposed_task = await role.propose(code_task_prompt)
274
+ code = await proposed_task.move_to("coding").delegate()
275
+ logger.success(f"Code:\n{code}")
276
+
277
+ # Propose a documentation task
278
+ doc_task_prompt = f"{code}\n\nwrite Readme.md file for the above code."
279
+ proposed_doc_task = await role.propose(doc_task_prompt)
280
+ documentation = await proposed_doc_task.move_to("doc").delegate()
281
+ logger.success(f"Documentation:\n{documentation}")
282
+
283
+
284
+ if __name__ == "__main__":
285
+ asyncio.run(main())
286
+ ```
287
+
288
+ ### Advanced Examples
289
+
290
+ #### Template Management and Rendering
291
+
292
+ ```python
293
+ from fabricatio._rust_instances import template_manager
294
+
295
+ template_name = "claude-xml.hbs"
296
+ data = {
297
+ "absolute_code_path": "/path/to/project",
298
+ "source_tree": "source tree content",
299
+ "files": [{"path": "file1.py", "code": "print('Hello')"}],
300
+ }
301
+
302
+ rendered_template = template_manager.render_template(template_name, data)
303
+ print(rendered_template)
304
+ ```
305
+
306
+ #### Handling Security Vulnerabilities
307
+
308
+ ```python
309
+ from fabricatio.models.usages import ToolBoxUsage
310
+ from fabricatio.models.task import Task
311
+
312
+ toolbox_usage = ToolBoxUsage()
313
+
314
+ async def handle_security_vulnerabilities():
315
+ task = Task(
316
+ name="Security Check",
317
+ goal=["Identify security vulnerabilities"],
318
+ description="Perform a thorough security review on the project.",
319
+ dependencies=["./src/main.py"]
320
+ )
321
+
322
+ vulnerabilities = await toolbox_usage.gather_tools_fine_grind(task)
323
+ for vulnerability in vulnerabilities:
324
+ print(f"Found vulnerability: {vulnerability.name}")
325
+ ```
326
+
327
+ #### Managing CTF Challenges
328
+
329
+ ```python
330
+ import asyncio
331
+
332
+ from fabricatio.models.usages import ToolBoxUsage
333
+ from fabricatio.models.task import Task
334
+
335
+ toolbox_usage = ToolBoxUsage()
336
+
337
+ async def solve_ctf_challenge(challenge_name: str, challenge_description: str, files: list[str]):
338
+ task = Task(
339
+ name=challenge_name,
340
+ goal=[f"Solve {challenge_name} challenge"],
341
+ description=challenge_description,
342
+ dependencies=files
343
+ )
344
+
345
+ solution = await toolbox_usage.gather_tools_fine_grind(task)
346
+ print(f"Challenge Solved: {solution}")
347
+
348
+ if __name__ == "__main__":
349
+ asyncio.run(solve_ctf_challenge("Binary Exploitation", "CTF Binary Exploitation Challenge", ["./challenges/binary_exploit"]))
350
+ ```
351
+
352
+ ### Configuration
353
+
354
+ The configuration for Fabricatio is managed via environment variables or TOML files. The default configuration file (`config.toml`) can be overridden by specifying a custom path.
355
+
356
+ Example `config.toml`:
357
+
358
+ ```toml
359
+ [llm]
360
+ api_endpoint = "https://api.openai.com"
361
+ api_key = "your_openai_api_key"
362
+ timeout = 300
363
+ max_retries = 3
364
+ model = "gpt-3.5-turbo"
365
+ temperature = 1.0
366
+ stop_sign = ["\n\n\n", "User:"]
367
+ top_p = 0.35
368
+ generation_count = 1
369
+ stream = false
370
+ max_tokens = 8192
371
+ ```
372
+
373
+ ### Development Setup
374
+
375
+ To set up a development environment for Fabricatio:
376
+
377
+ 1. **Clone the Repository**:
378
+ ```bash
379
+ git clone https://github.com/Whth/fabricatio.git
380
+ cd fabricatio
381
+ ```
382
+
383
+ 2. **Install Dependencies**:
384
+ ```bash
385
+ uv --with-editable . maturin develop --uv -r
386
+ ```
387
+
388
+ 3. **Run Tests**:
389
+ ```bash
390
+ make test
391
+ ```
392
+
393
+ 4. **Build Documentation**:
394
+ ```bash
395
+ make docs
396
+ ```
397
+
398
+ ### Contributing
399
+
400
+ Contributions are welcome! Please follow these guidelines when contributing:
401
+
402
+ 1. Fork the repository.
403
+ 2. Create your feature branch (`git checkout -b feature/new-feature`).
404
+ 3. Commit your changes (`git commit -am 'Add new feature'`).
405
+ 4. Push to the branch (`git push origin feature/new-feature`).
406
+ 5. Create a new Pull Request.
407
+
408
+ ### License
409
+
410
+ Fabricatio is licensed under the MIT License. See [LICENSE](LICENSE) for more details.
411
+
412
+ ### Acknowledgments
413
+
414
+ Special thanks to the contributors and maintainers of:
415
+ - [PyO3](https://github.com/PyO3/pyo3)
416
+ - [Maturin](https://github.com/PyO3/maturin)
417
+ - [Handlebars.rs](https://github.com/sunng87/handlebars-rust)
418
+
419
+
@@ -0,0 +1,35 @@
1
+ fabricatio-0.2.1.dev0.dist-info/METADATA,sha256=x6D37kGKzWuvkI5qEifdCCJLFhrHPoBBsmxatVxXB1w,12351
2
+ fabricatio-0.2.1.dev0.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
+ fabricatio-0.2.1.dev0.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
4
+ fabricatio/actions/communication.py,sha256=NZxIIncKgJSDyBrqNebUtH_haqtxHa8ld2TZxT3CMdU,429
5
+ fabricatio/actions/transmission.py,sha256=xpvKqbXqgpi1BWy-vUUvmd8NZ1GhRNfsYUBp-l2jLyk,862
6
+ fabricatio/actions/__init__.py,sha256=eFmFVPQvtNgFynIXBVr3eP-vWQDWCPng60YY5LXvZgg,115
7
+ fabricatio/config.py,sha256=TVge_fujKzvEZhOZYiYOMXdVn0YZ9SL5L1_mDzyeFUg,10260
8
+ fabricatio/core.py,sha256=yQK2ZrbPYDJOaNDp0Bky3muTkB-ZaQ1ld_Qfflm2dY0,5938
9
+ fabricatio/decorators.py,sha256=uzsP4tFKQNjDHBkofsjjoJA0IUAaYOtt6YVedoyOqlo,6551
10
+ fabricatio/fs/curd.py,sha256=faMstgGUiQ4k2AW3OXfvvWWTldTtKXco7QINYaMjmyA,3981
11
+ fabricatio/fs/readers.py,sha256=eDL9QhKEd6xfJBZaiwraObpGJWWpUd9NVYHoIvWgVqY,551
12
+ fabricatio/fs/__init__.py,sha256=lWcKYg0v3mv2LnnSegOQaTtlVDODU0vtw_s6iKU5IqQ,122
13
+ fabricatio/journal.py,sha256=siqimKF0M_QaaOCMxtjr_BJVNyUIAQWILzE9Q4T6-7c,781
14
+ fabricatio/models/action.py,sha256=1V3upL79e3ekyGXA4bSY70N60yeL0aWak7ZPBVsFE3A,5652
15
+ fabricatio/models/advanced.py,sha256=xAt0rgxzpw-gw-1LwRhvIbYKoNI8kzzcYPvcL7Q1z1U,5027
16
+ fabricatio/models/events.py,sha256=mrihNEFgQ5o7qFWja1z_qX8dnaTLwPBoJdVlzxQV5oM,2719
17
+ fabricatio/models/generic.py,sha256=HRslLNvP6v6wWag0tGda1FtAbjbjn096583u_IrixWs,4823
18
+ fabricatio/models/kwargs_types.py,sha256=lSZAxOnhFdQwRkm-NrbJVMSyBbfdeuVNx807LvJpEOo,901
19
+ fabricatio/models/role.py,sha256=RPdOcjmM6KNyH310Vx4524JQG94P5sXl_3doSrRpiKQ,1802
20
+ fabricatio/models/task.py,sha256=hogTBx74IAKfKDWghhWFR7i-LVQAn7L9PQM5tyOA5Rk,9257
21
+ fabricatio/models/tool.py,sha256=WTFnpF6xZ1nJbmIOonLsGQcM-kkDCeZiAFqyil9xg2U,6988
22
+ fabricatio/models/usages.py,sha256=JwVanhu5v87LUbnPjwFPriFI5O3HG4SppesYvYLAb50,23636
23
+ fabricatio/models/utils.py,sha256=i_kpcQpct04mQFk1nbcVGV-pl1YThWu4Qk3wbewzKkc,2535
24
+ fabricatio/parser.py,sha256=uLabsvF07wRKW1PoTGuGEENCx3P4mhmuO8JkmOEkKko,3522
25
+ fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
+ fabricatio/toolboxes/arithmetic.py,sha256=WLqhY-Pikv11Y_0SGajwZx3WhsLNpHKf9drzAqOf_nY,1369
27
+ fabricatio/toolboxes/fs.py,sha256=YkNgon5-bvCiPVEND9971W-6wj8btKNL6nGry2otn9I,498
28
+ fabricatio/toolboxes/task.py,sha256=kU4a501awIDV7GwNDuSlK3_Ym-5OhCp5sS-insTmUmQ,269
29
+ fabricatio/toolboxes/__init__.py,sha256=b13KmASO8q5fBLwew964fn9oH86ER5g-S1PgA4fZ_xs,482
30
+ fabricatio/_rust.pyi,sha256=0wCqtwWkVxxoqprvk8T27T8QYKIAKHS7xgsmdMNjQKc,1756
31
+ fabricatio/_rust_instances.py,sha256=dl0-yZ4UvT5g20tQgnPJpmqtkjFGXNG_YK4eLfi_ugQ,279
32
+ fabricatio/__init__.py,sha256=opIrN8lGyT-h2If4Qez0bRuWBa3uIT9GsM9CZy7_XJ0,1100
33
+ fabricatio/_rust.cp312-win_amd64.pyd,sha256=JrZsNCEZJqdoeo2x9MlTG-H7kdQo_3uTKek0P9DdG60,1260544
34
+ fabricatio-0.2.1.dev0.data/scripts/tdown.exe,sha256=n9vd_Mp4D-DcGm24C7exfhzphS2HIyS_lRb8lMPJzdk,3396608
35
+ fabricatio-0.2.1.dev0.dist-info/RECORD,,