fabricatio 0.2.6.dev8__tar.gz → 0.2.7__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 (137) hide show
  1. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/.gitignore +1 -0
  2. fabricatio-0.2.7/Makefile +27 -0
  3. fabricatio-0.2.7/PKG-INFO +181 -0
  4. fabricatio-0.2.7/README.md +138 -0
  5. fabricatio-0.2.7/examples/extract_and_inject/article_rag.py +33 -0
  6. fabricatio-0.2.7/examples/extract_and_inject/ask.py +59 -0
  7. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/extract_and_inject/extract_and_inject.py +14 -7
  8. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/extract_article/extract.py +1 -1
  9. fabricatio-0.2.7/examples/write_article/write_article.py +46 -0
  10. fabricatio-0.2.7/examples/write_outline/.gitignore +2 -0
  11. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/pyproject.toml +11 -2
  12. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/_rust.pyi +11 -2
  13. fabricatio-0.2.7/python/fabricatio/actions/article.py +230 -0
  14. fabricatio-0.2.7/python/fabricatio/actions/article_rag.py +35 -0
  15. fabricatio-0.2.7/python/fabricatio/actions/output.py +34 -0
  16. fabricatio-0.2.7/python/fabricatio/actions/rag.py +73 -0
  17. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/capabilities/correct.py +36 -4
  18. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/capabilities/rag.py +41 -5
  19. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/capabilities/rating.py +15 -6
  20. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/capabilities/review.py +7 -4
  21. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/capabilities/task.py +3 -3
  22. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/config.py +3 -0
  23. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/decorators.py +32 -0
  24. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/action.py +9 -7
  25. fabricatio-0.2.7/python/fabricatio/models/extra/article_base.py +378 -0
  26. fabricatio-0.2.7/python/fabricatio/models/extra/article_essence.py +226 -0
  27. fabricatio-0.2.7/python/fabricatio/models/extra/article_main.py +196 -0
  28. fabricatio-0.2.7/python/fabricatio/models/extra/article_outline.py +32 -0
  29. fabricatio-0.2.7/python/fabricatio/models/extra/article_proposal.py +35 -0
  30. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/generic.py +164 -14
  31. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/kwargs_types.py +22 -3
  32. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/tool.py +6 -2
  33. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/usages.py +48 -37
  34. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/utils.py +6 -4
  35. fabricatio-0.2.7/src/templates.rs +111 -0
  36. fabricatio-0.2.7/templates/built-in/as_prompt.hbs +3 -0
  37. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/create_json_obj.hbs +1 -1
  38. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/refined_query.hbs +15 -4
  39. fabricatio-0.2.7/templates.tar.gz +0 -0
  40. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/uv.lock +136 -3
  41. fabricatio-0.2.6.dev8/Makefile +0 -27
  42. fabricatio-0.2.6.dev8/PKG-INFO +0 -432
  43. fabricatio-0.2.6.dev8/README.md +0 -393
  44. fabricatio-0.2.6.dev8/python/fabricatio/actions/article.py +0 -128
  45. fabricatio-0.2.6.dev8/python/fabricatio/actions/output.py +0 -19
  46. fabricatio-0.2.6.dev8/python/fabricatio/actions/rag.py +0 -26
  47. fabricatio-0.2.6.dev8/python/fabricatio/models/extra.py +0 -655
  48. fabricatio-0.2.6.dev8/src/templates.rs +0 -104
  49. fabricatio-0.2.6.dev8/templates.tar.gz +0 -0
  50. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/.github/workflows/build-package.yaml +0 -0
  51. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/.github/workflows/ruff.yaml +0 -0
  52. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/.github/workflows/tests.yaml +0 -0
  53. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/.python-version +0 -0
  54. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/Cargo.lock +0 -0
  55. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/Cargo.toml +0 -0
  56. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/LICENSE +0 -0
  57. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/correct/correct.py +0 -0
  58. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/correct/correct_loop.py +0 -0
  59. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/extract_and_inject/.gitignore +0 -0
  60. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/llm_usages/llm_usage.py +0 -0
  61. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/make_a_rating/rating.py +0 -0
  62. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/make_diary/commits.json +0 -0
  63. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/make_diary/diary.py +0 -0
  64. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/minor/hello_fabricatio.py +0 -0
  65. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/minor/write_a_poem.py +0 -0
  66. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/propose_task/propose.py +0 -0
  67. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/reviewer/review.py +0 -0
  68. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/search_bibtex/.gitignore +0 -0
  69. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/search_bibtex/search.py +0 -0
  70. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/simple_chat/chat.py +0 -0
  71. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/simple_rag/simple_rag.py +0 -0
  72. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/task_handle/handle_task.py +0 -0
  73. {fabricatio-0.2.6.dev8/examples/write_outline → fabricatio-0.2.7/examples/write_article}/.gitignore +0 -0
  74. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/write_outline/write_outline.py +0 -0
  75. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/examples/write_outline/write_outline_corrected.py +0 -0
  76. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/__init__.py +0 -0
  77. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/_rust_instances.py +0 -0
  78. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/capabilities/propose.py +0 -0
  79. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/core.py +0 -0
  80. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/fs/__init__.py +0 -0
  81. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/fs/curd.py +0 -0
  82. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/fs/readers.py +0 -0
  83. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/journal.py +0 -0
  84. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/events.py +0 -0
  85. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/role.py +0 -0
  86. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/models/task.py +0 -0
  87. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/parser.py +0 -0
  88. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/py.typed +0 -0
  89. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/toolboxes/__init__.py +0 -0
  90. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  91. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/toolboxes/fs.py +0 -0
  92. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/workflows/articles.py +0 -0
  93. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/python/fabricatio/workflows/rag.py +0 -0
  94. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/src/bib_tools.rs +0 -0
  95. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/src/hash.rs +0 -0
  96. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/src/hbs_helpers.rs +0 -0
  97. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/src/lib.rs +0 -0
  98. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  99. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/claude-xml.hbs +0 -0
  100. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/clean-up-code.hbs +0 -0
  101. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/co_validation.hbs +0 -0
  102. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/correct.hbs +0 -0
  103. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  104. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/dependencies.hbs +0 -0
  105. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/document-the-code.hbs +0 -0
  106. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/draft_rating_criteria.hbs +0 -0
  107. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/draft_rating_manual.hbs +0 -0
  108. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  109. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  110. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  111. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  112. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  113. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/fix-bugs.hbs +0 -0
  114. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/generic_string.hbs +0 -0
  115. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/improve-performance.hbs +0 -0
  116. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/liststr.hbs +0 -0
  117. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/make_choice.hbs +0 -0
  118. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/make_judgment.hbs +0 -0
  119. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/pathstr.hbs +0 -0
  120. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/rate_fine_grind.hbs +0 -0
  121. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/refactor.hbs +0 -0
  122. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/retrieved_display.hbs +0 -0
  123. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  124. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/review_string.hbs +0 -0
  125. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/task_briefing.hbs +0 -0
  126. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/web-ctf-solver.hbs +0 -0
  127. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/write-git-commit.hbs +0 -0
  128. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/write-github-pull-request.hbs +0 -0
  129. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/templates/built-in/write-github-readme.hbs +0 -0
  130. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/tests/test_config.py +0 -0
  131. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/tests/test_models/test_action.py +0 -0
  132. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/tests/test_models/test_advanced.py +0 -0
  133. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/tests/test_models/test_generic.py +0 -0
  134. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/tests/test_models/test_role.py +0 -0
  135. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/tests/test_models/test_task.py +0 -0
  136. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/tests/test_models/test_tool.py +0 -0
  137. {fabricatio-0.2.6.dev8 → fabricatio-0.2.7}/tests/test_models/test_usages.py +0 -0
@@ -165,3 +165,4 @@ cython_debug/
165
165
 
166
166
  extra/scripts/*
167
167
  output/
168
+ .vscode/
@@ -0,0 +1,27 @@
1
+ DIST:=dist
2
+ DATA:=extra
3
+ PY:=3.12
4
+
5
+
6
+ all:bdist
7
+
8
+ tools:
9
+ cargo build --all --bins -Z unstable-options --artifact-dir $(DATA)/scripts --release
10
+ mkdir -p $(DATA)/scripts
11
+ rm $(DATA)/scripts/*.pdb || true
12
+ rm $(DATA)/scripts/*.dwarf || true
13
+
14
+ dev: tools
15
+ uvx -p $(PY) --project . maturin develop --uv -r
16
+
17
+ bdist:clean tools
18
+ uvx -p $(PY) --project . maturin sdist -o $(DIST)
19
+ uvx -p $(PY) --project . maturin build -r -o $(DIST)
20
+
21
+ clean:
22
+ rm -rf $(DIST) $(DATA)
23
+
24
+ publish:tools
25
+ uvx -p $(PY) --project . maturin publish --skip-existing
26
+ uvx -p $(PY) --project . maturin upload --skip-existing $(DIST)/*
27
+ .PHONY: tools dev bdist clean publish
@@ -0,0 +1,181 @@
1
+ Metadata-Version: 2.4
2
+ Name: fabricatio
3
+ Version: 0.2.7
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: json-repair>=0.39.1
15
+ Requires-Dist: litellm>=1.60.0
16
+ Requires-Dist: loguru>=0.7.3
17
+ Requires-Dist: magika>=0.5.1
18
+ Requires-Dist: more-itertools>=10.6.0
19
+ Requires-Dist: orjson>=3.10.15
20
+ Requires-Dist: pydantic>=2.10.6
21
+ Requires-Dist: pydantic-settings>=2.7.1
22
+ Requires-Dist: pymitter>=1.0.0
23
+ Requires-Dist: questionary>=2.1.0
24
+ Requires-Dist: regex>=2024.11.6
25
+ Requires-Dist: rich>=13.9.4
26
+ Requires-Dist: pymilvus>=2.5.4 ; extra == 'rag'
27
+ Requires-Dist: fabricatio[calc,plot,rag] ; extra == 'full'
28
+ Requires-Dist: sympy>=1.13.3 ; extra == 'calc'
29
+ Requires-Dist: matplotlib>=3.10.1 ; extra == 'plot'
30
+ Provides-Extra: rag
31
+ Provides-Extra: full
32
+ Provides-Extra: calc
33
+ Provides-Extra: plot
34
+ License-File: LICENSE
35
+ Summary: A LLM multi-agent framework.
36
+ Keywords: ai,agents,multi-agent,llm,pyo3
37
+ Author-email: Whth <zettainspector@foxmail.com>
38
+ Requires-Python: >=3.12, <3.13
39
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
40
+ Project-URL: Homepage, https://github.com/Whth/fabricatio
41
+ Project-URL: Repository, https://github.com/Whth/fabricatio
42
+ Project-URL: Issues, https://github.com/Whth/fabricatio/issues
43
+
44
+ # Fabricatio
45
+
46
+ ![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)
47
+ ![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)
48
+ ![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
49
+
50
+ ## Overview
51
+
52
+ Fabricatio is a streamlined Python library for building LLM applications using an event-based agent structure. It leverages Rust for performance-critical tasks, Handlebars for templating, and PyO3 for Python bindings.
53
+
54
+ ## Features
55
+
56
+ - **Event-Driven Architecture**: Robust task management through an EventEmitter pattern.
57
+ - **LLM Integration & Templating**: Seamlessly interact with large language models and dynamic content generation.
58
+ - **Async & Extensible**: Fully asynchronous execution with easy extension via custom actions and workflows.
59
+
60
+ ## Installation
61
+
62
+ ### Using UV (Recommended)
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
+ ```bash
79
+ # Build distribution packages
80
+ make bdist
81
+ ```
82
+
83
+ ## Usage
84
+
85
+ ### Basic Example
86
+
87
+ ```python
88
+ import asyncio
89
+ from fabricatio import Action, Role, Task, logger, WorkFlow
90
+ from typing import Any
91
+
92
+ class Hello(Action):
93
+ name: str = "hello"
94
+ output_key: str = "task_output"
95
+
96
+ async def _execute(self, task_input: Task[str], **_) -> Any:
97
+ ret = "Hello fabricatio!"
98
+ logger.info("executing talk action")
99
+ return ret
100
+
101
+ async def main() -> None:
102
+ role = Role(
103
+ name="talker",
104
+ description="talker role",
105
+ registry={Task.pending_label: WorkFlow(name="talk", steps=(Hello,))}
106
+ )
107
+
108
+ task = Task(name="say hello", goals="say hello", description="say hello to the world")
109
+ result = await task.delegate()
110
+ logger.success(f"Result: {result}")
111
+
112
+ if __name__ == "__main__":
113
+ asyncio.run(main())
114
+ ```
115
+
116
+ ### Examples
117
+
118
+ For various usage scenarios, refer to the following examples:
119
+ - Simple Chat
120
+ - Retrieval-Augmented Generation (RAG)
121
+ - Article Extraction
122
+ - Propose Task
123
+ - Code Review
124
+ - Write Outline
125
+
126
+ _(For full example details, please check our detailed documentation, see [Examples](./examples))_
127
+
128
+ ## Configuration
129
+
130
+ The configuration for Fabricatio is managed via environment variables or TOML files. For example:
131
+
132
+ ```toml
133
+ [llm]
134
+ api_endpoint = "https://api.openai.com"
135
+ api_key = "your_openai_api_key"
136
+ timeout = 300
137
+ max_retries = 3
138
+ model = "gpt-3.5-turbo"
139
+ temperature = 1.0
140
+ stop_sign = ["\n\n\n", "User:"]
141
+ top_p = 0.35
142
+ generation_count = 1
143
+ stream = false
144
+ max_tokens = 8192
145
+ ```
146
+
147
+ ## Development Setup
148
+
149
+ 1. **Clone the Repository**:
150
+ ```bash
151
+ git clone https://github.com/Whth/fabricatio.git
152
+ cd fabricatio
153
+ ```
154
+ 2. **Install Dependencies**:
155
+ ```bash
156
+ uv --with-editable . maturin develop --uv -r
157
+ ```
158
+ 3. **Run Tests**:
159
+ ```bash
160
+ make test
161
+ ```
162
+
163
+ ## Contributing
164
+
165
+ Contributions are welcome! Follow these steps:
166
+ 1. Fork the repository.
167
+ 2. Create your feature branch (`git checkout -b feature/new-feature`).
168
+ 3. Commit your changes (`git commit -am 'Add new feature'`).
169
+ 4. Push to the branch (`git push origin feature/new-feature`).
170
+ 5. Create a new Pull Request.
171
+
172
+ ## License
173
+
174
+ Fabricatio is licensed under the MIT License. See [LICENSE](LICENSE) for details.
175
+
176
+ ## Acknowledgments
177
+
178
+ Special thanks to the contributors and maintainers of:
179
+ - [PyO3](https://github.com/PyO3/pyo3)
180
+ - [Maturin](https://github.com/PyO3/maturin)
181
+ - [Handlebars.rs](https://github.com/sunng87/handlebars-rust)
@@ -0,0 +1,138 @@
1
+ # Fabricatio
2
+
3
+ ![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)
4
+ ![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)
5
+ ![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
6
+
7
+ ## Overview
8
+
9
+ Fabricatio is a streamlined Python library for building LLM applications using an event-based agent structure. It leverages Rust for performance-critical tasks, Handlebars for templating, and PyO3 for Python bindings.
10
+
11
+ ## Features
12
+
13
+ - **Event-Driven Architecture**: Robust task management through an EventEmitter pattern.
14
+ - **LLM Integration & Templating**: Seamlessly interact with large language models and dynamic content generation.
15
+ - **Async & Extensible**: Fully asynchronous execution with easy extension via custom actions and workflows.
16
+
17
+ ## Installation
18
+
19
+ ### Using UV (Recommended)
20
+
21
+ ```bash
22
+ # Install uv if not already installed
23
+ pip install uv
24
+
25
+ # Clone the repository
26
+ git clone https://github.com/Whth/fabricatio.git
27
+ cd fabricatio
28
+
29
+ # Install the package in development mode with uv
30
+ uv --with-editable . maturin develop --uv -r
31
+ ```
32
+
33
+ ### Building Distribution
34
+
35
+ ```bash
36
+ # Build distribution packages
37
+ make bdist
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ### Basic Example
43
+
44
+ ```python
45
+ import asyncio
46
+ from fabricatio import Action, Role, Task, logger, WorkFlow
47
+ from typing import Any
48
+
49
+ class Hello(Action):
50
+ name: str = "hello"
51
+ output_key: str = "task_output"
52
+
53
+ async def _execute(self, task_input: Task[str], **_) -> Any:
54
+ ret = "Hello fabricatio!"
55
+ logger.info("executing talk action")
56
+ return ret
57
+
58
+ async def main() -> None:
59
+ role = Role(
60
+ name="talker",
61
+ description="talker role",
62
+ registry={Task.pending_label: WorkFlow(name="talk", steps=(Hello,))}
63
+ )
64
+
65
+ task = Task(name="say hello", goals="say hello", description="say hello to the world")
66
+ result = await task.delegate()
67
+ logger.success(f"Result: {result}")
68
+
69
+ if __name__ == "__main__":
70
+ asyncio.run(main())
71
+ ```
72
+
73
+ ### Examples
74
+
75
+ For various usage scenarios, refer to the following examples:
76
+ - Simple Chat
77
+ - Retrieval-Augmented Generation (RAG)
78
+ - Article Extraction
79
+ - Propose Task
80
+ - Code Review
81
+ - Write Outline
82
+
83
+ _(For full example details, please check our detailed documentation, see [Examples](./examples))_
84
+
85
+ ## Configuration
86
+
87
+ The configuration for Fabricatio is managed via environment variables or TOML files. For example:
88
+
89
+ ```toml
90
+ [llm]
91
+ api_endpoint = "https://api.openai.com"
92
+ api_key = "your_openai_api_key"
93
+ timeout = 300
94
+ max_retries = 3
95
+ model = "gpt-3.5-turbo"
96
+ temperature = 1.0
97
+ stop_sign = ["\n\n\n", "User:"]
98
+ top_p = 0.35
99
+ generation_count = 1
100
+ stream = false
101
+ max_tokens = 8192
102
+ ```
103
+
104
+ ## Development Setup
105
+
106
+ 1. **Clone the Repository**:
107
+ ```bash
108
+ git clone https://github.com/Whth/fabricatio.git
109
+ cd fabricatio
110
+ ```
111
+ 2. **Install Dependencies**:
112
+ ```bash
113
+ uv --with-editable . maturin develop --uv -r
114
+ ```
115
+ 3. **Run Tests**:
116
+ ```bash
117
+ make test
118
+ ```
119
+
120
+ ## Contributing
121
+
122
+ Contributions are welcome! Follow these steps:
123
+ 1. Fork the repository.
124
+ 2. Create your feature branch (`git checkout -b feature/new-feature`).
125
+ 3. Commit your changes (`git commit -am 'Add new feature'`).
126
+ 4. Push to the branch (`git push origin feature/new-feature`).
127
+ 5. Create a new Pull Request.
128
+
129
+ ## License
130
+
131
+ Fabricatio is licensed under the MIT License. See [LICENSE](LICENSE) for details.
132
+
133
+ ## Acknowledgments
134
+
135
+ Special thanks to the contributors and maintainers of:
136
+ - [PyO3](https://github.com/PyO3/pyo3)
137
+ - [Maturin](https://github.com/PyO3/maturin)
138
+ - [Handlebars.rs](https://github.com/sunng87/handlebars-rust)
@@ -0,0 +1,33 @@
1
+ """Example of proposing a task to a role."""
2
+
3
+ import asyncio
4
+
5
+ from fabricatio import Event, Role, Task, WorkFlow, logger
6
+ from fabricatio.actions.rag import RAGTalk
7
+
8
+
9
+ async def main() -> None:
10
+ """Main function."""
11
+ role = Role(
12
+ name="Researcher",
13
+ description="Extract article essence",
14
+ llm_model="openai/deepseek-r1-distill-llama-70b",
15
+ llm_rpm=50,
16
+ llm_tpm=100000,
17
+ registry={
18
+ Event.quick_instantiate(e := "answer"): WorkFlow(
19
+ name="answer",
20
+ steps=(RAGTalk,),
21
+ ).update_init_context(collection_name="article_essence"),
22
+ },
23
+ )
24
+
25
+ task: Task[int] = await role.propose_task(
26
+ "Answer to all user questions properly and patiently",
27
+ )
28
+
29
+ logger.info(f"Complete {await task.delegate(e)} times qa.")
30
+
31
+
32
+ if __name__ == "__main__":
33
+ asyncio.run(main())
@@ -0,0 +1,59 @@
1
+ """Simple chat example."""
2
+
3
+ import asyncio
4
+
5
+ from fabricatio import RAG, Action, Role, Task, WorkFlow, logger
6
+ from fabricatio.models.events import Event
7
+ from fabricatio.models.utils import ok
8
+ from questionary import text
9
+
10
+
11
+ class Talk(Action, RAG):
12
+ """Action that says hello to the world."""
13
+
14
+ output_key: str = "task_output"
15
+
16
+ async def _execute(self, task_input: Task[str], **_) -> int:
17
+ counter = 0
18
+
19
+ self.init_client()
20
+
21
+ try:
22
+ while True:
23
+ user_say = await text("User: ").ask_async()
24
+ if user_say is None:
25
+ break
26
+ gpt_say = await self.aask_refined(
27
+ user_say,
28
+ "article_essence_max",
29
+ extra_system_message=f"You have to answer to user obeying task assigned to you:\n{task_input.briefing}\nYou should explicitly say write a label if you draw a conclusion from the references, the label shall contain names.",
30
+ result_per_query=16,
31
+ final_limit=40,
32
+ similarity_threshold=0.31,
33
+ )
34
+ print(f"GPT: {gpt_say}") # noqa: T201
35
+ counter += 1
36
+ except KeyboardInterrupt:
37
+ logger.info(f"executed talk action {counter} times")
38
+ return counter
39
+
40
+
41
+ async def main() -> None:
42
+ """Main function."""
43
+ role = Role(
44
+ name="talker",
45
+ description="talker role but with rag",
46
+ registry={Event.instantiate_from("talk").push_wildcard().push("pending"): WorkFlow(name="talk", steps=(Talk,))},
47
+ )
48
+
49
+ task = ok(
50
+ await role.propose_task(
51
+ "you have to act as a helpful assistant, answer to all user questions properly and patiently"
52
+ ),
53
+ "Failed to propose task",
54
+ )
55
+ _ = await task.delegate("talk")
56
+
57
+
58
+ if __name__ == "__main__":
59
+ asyncio.run(main())
@@ -8,7 +8,9 @@ from fabricatio import Action, Event, Role, Task, WorkFlow, logger
8
8
  from fabricatio.actions.article import ExtractArticleEssence
9
9
  from fabricatio.actions.rag import InjectToDB
10
10
  from fabricatio.fs.curd import dump_text, gather_files
11
- from fabricatio.models.extra import ArticleEssence
11
+ from fabricatio.models.extra.article_essence import ArticleEssence
12
+ from fabricatio.models.utils import ok
13
+ from pydantic import HttpUrl
12
14
 
13
15
 
14
16
  class SaveToFS(Action):
@@ -31,20 +33,25 @@ async def main() -> None:
31
33
  role = Role(
32
34
  name="Researcher",
33
35
  description="Extract article essence",
34
- llm_model="openai/deepseek-r1-distill-llama-70b",
35
- llm_rpm=50,
36
- llm_tpm=100000,
36
+ llm_api_endpoint=HttpUrl("https://dashscope.aliyuncs.com/compatible-mode/v1"),
37
+ llm_model="openai/qwq-plus",
38
+ llm_stream=True,
39
+ llm_rpm=500,
40
+ llm_tpm=5000000,
37
41
  registry={
38
42
  Event.quick_instantiate("article"): WorkFlow(
39
43
  name="extract",
40
44
  steps=(ExtractArticleEssence(output_key="to_inject"), SaveToFS, InjectToDB(output_key="task_output")),
41
- extra_init_context={"collection_name": "article_essence", "output_dir": Path("output")},
45
+ ).update_init_context(
46
+ override_inject=True, collection_name="article_essence_max", output_dir=Path("output")
42
47
  )
43
48
  },
44
49
  )
45
50
 
46
- task: Task[str] = await role.propose_task(
47
- "Extract the essence of the article from the files in './bpdf_out'",
51
+ task: Task[str] = ok(
52
+ await role.propose_task(
53
+ "Extract the essence of the article from the files in './bpdf_out'",
54
+ )
48
55
  )
49
56
 
50
57
  col_name = await task.override_dependencies(gather_files("bpdf_out", "md")).delegate("article")
@@ -7,7 +7,7 @@ from fabricatio import Event, Role, Task, WorkFlow, logger
7
7
  from fabricatio.actions.article import ExtractArticleEssence
8
8
 
9
9
  if TYPE_CHECKING:
10
- from fabricatio.models.extra import ArticleEssence
10
+ from fabricatio.models.extra.article_essence import ArticleEssence
11
11
 
12
12
 
13
13
  async def main() -> None:
@@ -0,0 +1,46 @@
1
+ """Example of using the library."""
2
+
3
+ import asyncio
4
+ from pathlib import Path
5
+
6
+ from fabricatio import Event, Role, WorkFlow, logger
7
+ from fabricatio.actions.article import (
8
+ GenerateArticle,
9
+ GenerateArticleProposal,
10
+ GenerateOutline,
11
+ )
12
+ from fabricatio.actions.output import DumpFinalizedOutput
13
+ from fabricatio.models.task import Task
14
+
15
+
16
+ async def main() -> None:
17
+ """Main function."""
18
+ Role(
19
+ name="Undergraduate Researcher",
20
+ description="Write an outline for an article in typst format.",
21
+ llm_top_p=0.8,
22
+ llm_temperature=1.15,
23
+ llm_max_tokens=8192,
24
+ llm_model="openai/qwen-max",
25
+ llm_stream=True,
26
+ registry={
27
+ Event.quick_instantiate(ns := "article"): WorkFlow(
28
+ name="Generate Article Outline",
29
+ description="Generate an outline for an article. dump the outline to the given path. in typst format.",
30
+ steps=(
31
+ GenerateArticleProposal(llm_temperature=1.18),
32
+ GenerateOutline(llm_temperature=1.21, llm_top_p=0.3),
33
+ GenerateArticle(output_key="to_dump", llm_temperature=1.2, llm_top_p=0.45),
34
+ DumpFinalizedOutput(output_key="task_output"),
35
+ ),
36
+ ).update_init_context(article_briefing=Path("./article_briefing.txt").read_text(), dump_path="out.typ")
37
+ },
38
+ )
39
+
40
+ proposed_task = Task(name="write an article")
41
+ path = await proposed_task.delegate(ns)
42
+ logger.success(f"The outline is saved in:\n{path}")
43
+
44
+
45
+ if __name__ == "__main__":
46
+ asyncio.run(main())
@@ -0,0 +1,2 @@
1
+ article_briefing.txt
2
+ out.typ
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.6-dev8"
3
+ version = "0.2.7"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -81,7 +81,13 @@ rag = [
81
81
  ]
82
82
 
83
83
  full = [
84
- "fabricatio[rag]",
84
+ "fabricatio[calc,plot,rag]",
85
+ ]
86
+ calc = [
87
+ "sympy>=1.13.3",
88
+ ]
89
+ plot = [
90
+ "matplotlib>=3.10.1",
85
91
  ]
86
92
 
87
93
  [tool.ruff]
@@ -140,6 +146,9 @@ testpaths = [
140
146
  asyncio_mode = "auto"
141
147
  asyncio_default_fixture_loop_scope = "function"
142
148
 
149
+ [tool.uv.sources]
150
+ fabricatio = { workspace = true }
151
+
143
152
  [[tool.uv.index]]
144
153
  url = "https://mirrors.bfsu.edu.cn/pypi/web/simple"
145
154
  default = true
@@ -11,7 +11,7 @@ class TemplateManager:
11
11
  """
12
12
 
13
13
  def __init__(
14
- self, template_dirs: List[Path], suffix: Optional[str] = None, active_loading: Optional[bool] = None
14
+ self, template_dirs: List[Path], suffix: Optional[str] = None, active_loading: Optional[bool] = None
15
15
  ) -> None:
16
16
  """Initialize the template manager.
17
17
 
@@ -55,6 +55,16 @@ class TemplateManager:
55
55
  RuntimeError: If template rendering fails
56
56
  """
57
57
 
58
+ def render_template_raw(self, template: str, data: Dict[str, Any]) -> str:
59
+ """Render a template with context data.
60
+
61
+ Args:
62
+ template: The template string
63
+ data: Context dictionary to provide variables to the template
64
+
65
+ Returns:
66
+ Rendered template content as string
67
+ """
58
68
 
59
69
  def blake3_hash(content: bytes) -> str:
60
70
  """Calculate the BLAKE3 cryptographic hash of data.
@@ -66,7 +76,6 @@ def blake3_hash(content: bytes) -> str:
66
76
  Hex-encoded BLAKE3 hash string
67
77
  """
68
78
 
69
-
70
79
  class BibManager:
71
80
  """BibTeX bibliography manager for parsing and querying citation data."""
72
81