fabricatio 0.2.7.dev3__tar.gz → 0.2.7.dev4__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 (131) hide show
  1. fabricatio-0.2.7.dev4/PKG-INFO +181 -0
  2. fabricatio-0.2.7.dev4/README.md +138 -0
  3. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/pyproject.toml +1 -1
  4. fabricatio-0.2.7.dev4/python/fabricatio/models/extra/article_base.py +192 -0
  5. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/extra/article_main.py +31 -97
  6. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/extra/article_outline.py +27 -122
  7. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/extra/article_proposal.py +12 -14
  8. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/generic.py +20 -2
  9. fabricatio-0.2.7.dev4/templates.tar.gz +0 -0
  10. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/uv.lock +1 -1
  11. fabricatio-0.2.7.dev3/PKG-INFO +0 -436
  12. fabricatio-0.2.7.dev3/README.md +0 -393
  13. fabricatio-0.2.7.dev3/templates.tar.gz +0 -0
  14. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/.github/workflows/build-package.yaml +0 -0
  15. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/.github/workflows/ruff.yaml +0 -0
  16. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/.github/workflows/tests.yaml +0 -0
  17. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/.gitignore +0 -0
  18. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/.python-version +0 -0
  19. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/Cargo.lock +0 -0
  20. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/Cargo.toml +0 -0
  21. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/LICENSE +0 -0
  22. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/Makefile +0 -0
  23. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/correct/correct.py +0 -0
  24. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/correct/correct_loop.py +0 -0
  25. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/.gitignore +0 -0
  26. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/article_rag.py +0 -0
  27. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/ask.py +0 -0
  28. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/extract_and_inject.py +0 -0
  29. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/extract_article/extract.py +0 -0
  30. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/llm_usages/llm_usage.py +0 -0
  31. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/make_a_rating/rating.py +0 -0
  32. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/make_diary/commits.json +0 -0
  33. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/make_diary/diary.py +0 -0
  34. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/minor/hello_fabricatio.py +0 -0
  35. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/minor/write_a_poem.py +0 -0
  36. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/propose_task/propose.py +0 -0
  37. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/reviewer/review.py +0 -0
  38. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/search_bibtex/.gitignore +0 -0
  39. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/search_bibtex/search.py +0 -0
  40. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/simple_chat/chat.py +0 -0
  41. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/simple_rag/simple_rag.py +0 -0
  42. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/task_handle/handle_task.py +0 -0
  43. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/write_article/.gitignore +0 -0
  44. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/write_article/write_article.py +0 -0
  45. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/write_outline/.gitignore +0 -0
  46. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/write_outline/write_outline.py +0 -0
  47. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/examples/write_outline/write_outline_corrected.py +0 -0
  48. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/__init__.py +0 -0
  49. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/_rust.pyi +0 -0
  50. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/_rust_instances.py +0 -0
  51. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/actions/article.py +0 -0
  52. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/actions/article_rag.py +0 -0
  53. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/actions/output.py +0 -0
  54. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/actions/rag.py +0 -0
  55. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/correct.py +0 -0
  56. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/propose.py +0 -0
  57. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/rag.py +0 -0
  58. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/rating.py +0 -0
  59. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/review.py +0 -0
  60. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/task.py +0 -0
  61. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/config.py +0 -0
  62. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/core.py +0 -0
  63. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/decorators.py +0 -0
  64. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/fs/__init__.py +0 -0
  65. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/fs/curd.py +0 -0
  66. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/fs/readers.py +0 -0
  67. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/journal.py +0 -0
  68. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/action.py +0 -0
  69. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/events.py +0 -0
  70. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/extra/article_essence.py +0 -0
  71. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/kwargs_types.py +0 -0
  72. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/role.py +0 -0
  73. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/task.py +0 -0
  74. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/tool.py +0 -0
  75. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/usages.py +0 -0
  76. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/models/utils.py +0 -0
  77. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/parser.py +0 -0
  78. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/py.typed +0 -0
  79. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/toolboxes/__init__.py +0 -0
  80. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  81. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/toolboxes/fs.py +0 -0
  82. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/workflows/articles.py +0 -0
  83. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/python/fabricatio/workflows/rag.py +0 -0
  84. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/src/bib_tools.rs +0 -0
  85. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/src/hash.rs +0 -0
  86. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/src/hbs_helpers.rs +0 -0
  87. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/src/lib.rs +0 -0
  88. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/src/templates.rs +0 -0
  89. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/as_prompt.hbs +0 -0
  90. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  91. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/claude-xml.hbs +0 -0
  92. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/clean-up-code.hbs +0 -0
  93. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/co_validation.hbs +0 -0
  94. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/correct.hbs +0 -0
  95. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/create_json_obj.hbs +0 -0
  96. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  97. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/dependencies.hbs +0 -0
  98. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/document-the-code.hbs +0 -0
  99. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/draft_rating_criteria.hbs +0 -0
  100. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/draft_rating_manual.hbs +0 -0
  101. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  102. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  103. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  104. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  105. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  106. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/fix-bugs.hbs +0 -0
  107. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/generic_string.hbs +0 -0
  108. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/improve-performance.hbs +0 -0
  109. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/liststr.hbs +0 -0
  110. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/make_choice.hbs +0 -0
  111. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/make_judgment.hbs +0 -0
  112. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/pathstr.hbs +0 -0
  113. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/rate_fine_grind.hbs +0 -0
  114. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/refactor.hbs +0 -0
  115. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/refined_query.hbs +0 -0
  116. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/retrieved_display.hbs +0 -0
  117. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  118. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/review_string.hbs +0 -0
  119. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/task_briefing.hbs +0 -0
  120. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/web-ctf-solver.hbs +0 -0
  121. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/write-git-commit.hbs +0 -0
  122. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/write-github-pull-request.hbs +0 -0
  123. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/templates/built-in/write-github-readme.hbs +0 -0
  124. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/tests/test_config.py +0 -0
  125. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/tests/test_models/test_action.py +0 -0
  126. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/tests/test_models/test_advanced.py +0 -0
  127. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/tests/test_models/test_generic.py +0 -0
  128. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/tests/test_models/test_role.py +0 -0
  129. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/tests/test_models/test_task.py +0 -0
  130. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/tests/test_models/test_tool.py +0 -0
  131. {fabricatio-0.2.7.dev3 → fabricatio-0.2.7.dev4}/tests/test_models/test_usages.py +0 -0
@@ -0,0 +1,181 @@
1
+ Metadata-Version: 2.4
2
+ Name: fabricatio
3
+ Version: 0.2.7.dev4
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)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.7-dev3"
3
+ version = "0.2.7-dev4"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -0,0 +1,192 @@
1
+ """A foundation for hierarchical document components with dependency tracking."""
2
+
3
+ from abc import abstractmethod
4
+ from enum import StrEnum
5
+ from typing import TYPE_CHECKING, List, Optional, Self, Union, final, overload
6
+
7
+ from fabricatio.models.generic import Base, CensoredAble, Display, PersistentAble
8
+ from pydantic import Field
9
+
10
+ if TYPE_CHECKING:
11
+ from fabricatio.models.extra.article_main import Article
12
+ from fabricatio.models.extra.article_outline import ArticleOutline
13
+
14
+
15
+ class ReferringType(StrEnum):
16
+ """Enumeration of different types of references that can be made in an article."""
17
+
18
+ CHAPTER: str = "chapter"
19
+ SECTION: str = "section"
20
+ SUBSECTION: str = "subsection"
21
+
22
+
23
+ class ArticleRef(CensoredAble):
24
+ """Reference to a specific chapter, section or subsection within the article. You SHALL not refer to an article component that is external and not present within our own article.
25
+
26
+ Examples:
27
+ - Referring to a chapter titled `Introduction`:
28
+ Using Python
29
+ ```python
30
+ ArticleRef(referred_chapter_title="Introduction")
31
+ ```
32
+ Using JSON
33
+ ```json
34
+ {referred_chapter_title="Introduction"}
35
+ ```
36
+ - Referring to a section titled `Background` under the `Introduction` chapter:
37
+ Using Python
38
+ ```python
39
+ ArticleRef(referred_chapter_title="Introduction", referred_section_title="Background")
40
+ ```
41
+ Using JSON
42
+ ```json
43
+ {referred_chapter_title="Introduction", referred_section_title="Background"}
44
+ ```
45
+ - Referring to a subsection titled `Related Work` under the `Background` section of the `Introduction` chapter:
46
+ Using Python
47
+ ```python
48
+ ArticleRef(referred_chapter_title="Introduction", referred_section_title="Background", referred_subsection_title="Related Work")
49
+ ```
50
+ Using JSON
51
+ ```json
52
+ {referred_chapter_title="Introduction", referred_section_title="Background", referred_subsection_title="Related Work"}
53
+ ```
54
+ """
55
+
56
+ referred_subsection_title: Optional[str] = None
57
+ """`title` Field of the referenced subsection."""
58
+
59
+ referred_section_title: Optional[str] = None
60
+ """`title` Field of the referenced section."""
61
+
62
+ referred_chapter_title: str
63
+ """`title` Field of the referenced chapter"""
64
+
65
+ def __hash__(self) -> int:
66
+ """Overrides the default hash function to ensure consistent hashing across instances."""
67
+ return hash((self.referred_chapter_title, self.referred_section_title, self.referred_subsection_title))
68
+
69
+ @overload
70
+ def deref(self, article: "Article") -> Optional["ArticleMainBase"]:
71
+ """Dereference the reference to the actual section or subsection within the provided article."""
72
+
73
+ @overload
74
+ def deref(self, article: "ArticleOutline") -> Optional["ArticleOutlineBase"]:
75
+ """Dereference the reference to the actual section or subsection within the provided article."""
76
+
77
+ def deref(
78
+ self, article: Union["ArticleOutline", "Article"]
79
+ ) -> Union["ArticleOutlineBase", "ArticleMainBase", None]:
80
+ """Dereference the reference to the actual section or subsection within the provided article.
81
+
82
+ Args:
83
+ article (ArticleOutline | Article): The article to dereference the reference from.
84
+
85
+ Returns:
86
+ ArticleMainBase | ArticleOutline | None: The dereferenced section or subsection, or None if not found.
87
+ """
88
+ chap = next((chap for chap in article.chapters if chap.title == self.referred_chapter_title), None)
89
+ if self.referred_section_title is None or chap is None:
90
+ return chap
91
+ sec = next((sec for sec in chap.sections if sec.title == self.referred_section_title), None)
92
+ if self.referred_subsection_title is None or sec is None:
93
+ return sec
94
+ return next((subsec for subsec in sec.subsections if subsec.title == self.referred_subsection_title), None)
95
+
96
+ @property
97
+ def referring_type(self) -> ReferringType:
98
+ """Determine the type of reference based on the presence of specific attributes."""
99
+ if self.referred_subsection_title is not None:
100
+ return ReferringType.SUBSECTION
101
+ if self.referred_section_title is not None:
102
+ return ReferringType.SECTION
103
+ return ReferringType.CHAPTER
104
+
105
+
106
+ class SubSectionBase(Base):
107
+ """Base class for article sections and subsections."""
108
+
109
+
110
+ class SectionBase[T: SubSectionBase](Base):
111
+ """Base class for article sections and subsections."""
112
+
113
+ subsections: List[T] = Field(min_length=1)
114
+ """List of subsections, each containing a specific research component. Must contains at least 1 subsection, But do remember you should always add more subsection as required."""
115
+
116
+
117
+ class ChapterBase[T: SectionBase](Base):
118
+ """Base class for article chapters."""
119
+
120
+ sections: List[T] = Field(min_length=1)
121
+ """List of sections, each containing a specific research component. Must contains at least 1 section, But do remember you should always add more section as required."""
122
+
123
+
124
+ class ArticleBase[T: ChapterBase](Base):
125
+ """Base class for article outlines."""
126
+
127
+ chapters: List[T] = Field(min_length=5)
128
+ """List of chapters, each containing a specific research component. Must contains at least 5 chapters, But do remember you should always add more chapter as required."""
129
+
130
+
131
+ class ArticleOutlineBase(Base):
132
+ """Base class for article outlines."""
133
+
134
+ title: str
135
+ """Title of the research component in academic style."""
136
+ description: str
137
+ """Description of the research component in academic style."""
138
+
139
+ support_to: List[ArticleRef]
140
+ """Required: List of all essential ArticleRef objects identifying components this section provides evidence for.
141
+ Format: Each reference must point to a specific chapter, section, or subsection.
142
+ Note: References form a directed acyclic graph in the document structure."""
143
+ depend_on: List[ArticleRef]
144
+ """Required: List of all essential ArticleRef objects identifying components this section builds upon.
145
+ Format: Each reference must point to a previously defined chapter, section, or subsection.
146
+ Note: Circular dependencies are not permitted."""
147
+
148
+ writing_aim: List[str]
149
+ """Required: List of specific rhetorical objectives (3-5 items).
150
+ Format: Each item must be an actionable phrase starting with a verb.
151
+ Example: ['Establish metric validity', 'Compare with baseline approaches',
152
+ 'Justify threshold selection']"""
153
+
154
+
155
+ class ArticleMainBase(CensoredAble, Display, ArticleOutlineBase, PersistentAble):
156
+ """Foundation for hierarchical document components with dependency tracking."""
157
+
158
+ @abstractmethod
159
+ def to_typst_code(self) -> str:
160
+ """Converts the component into a Typst code snippet for rendering."""
161
+
162
+ def _update_pre_check(self, other: Self) -> Self:
163
+ if not isinstance(other, self.__class__):
164
+ raise TypeError(f"Cannot update from a non-{self.__class__} instance.")
165
+ if self.title != other.title:
166
+ raise ValueError("Cannot update from a different title.")
167
+ return self
168
+
169
+ @abstractmethod
170
+ def resolve_update_error(self, other: Self) -> str:
171
+ """Resolve update errors in the article outline.
172
+
173
+ Returns:
174
+ str: Error message indicating update errors in the article outline.
175
+ """
176
+
177
+ @abstractmethod
178
+ def _update_from_inner(self, other: Self) -> Self:
179
+ """Updates the current instance with the attributes of another instance."""
180
+
181
+ @final
182
+ def update_from(self, other: Self) -> Self:
183
+ """Updates the current instance with the attributes of another instance."""
184
+ return self._update_pre_check(other)._update_from_inner(other)
185
+
186
+ def __eq__(self, other: "ArticleMainBase") -> bool:
187
+ """Compares two ArticleBase objects based on their model_dump_json representation."""
188
+ return self.model_dump_json() == other.model_dump_json()
189
+
190
+ def __hash__(self) -> int:
191
+ """Calculates a hash value for the ArticleBase object based on its model_dump_json representation."""
192
+ return hash(self.model_dump_json())