fabricatio 0.2.7.dev2__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.
- fabricatio-0.2.7.dev4/PKG-INFO +181 -0
- fabricatio-0.2.7.dev4/README.md +138 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/extract_and_inject.py +1 -1
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/extract_article/extract.py +1 -1
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/pyproject.toml +1 -1
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/actions/article.py +4 -1
- fabricatio-0.2.7.dev4/python/fabricatio/actions/article_rag.py +35 -0
- fabricatio-0.2.7.dev4/python/fabricatio/models/extra/article_base.py +192 -0
- fabricatio-0.2.7.dev4/python/fabricatio/models/extra/article_essence.py +226 -0
- fabricatio-0.2.7.dev4/python/fabricatio/models/extra/article_main.py +293 -0
- fabricatio-0.2.7.dev4/python/fabricatio/models/extra/article_outline.py +181 -0
- fabricatio-0.2.7.dev4/python/fabricatio/models/extra/article_proposal.py +35 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/generic.py +55 -2
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/utils.py +6 -4
- fabricatio-0.2.7.dev4/templates.tar.gz +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/uv.lock +1 -1
- fabricatio-0.2.7.dev2/PKG-INFO +0 -436
- fabricatio-0.2.7.dev2/README.md +0 -393
- fabricatio-0.2.7.dev2/python/fabricatio/models/extra.py +0 -811
- fabricatio-0.2.7.dev2/templates.tar.gz +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/.gitignore +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/.python-version +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/Cargo.lock +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/Cargo.toml +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/LICENSE +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/Makefile +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/correct/correct_loop.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/.gitignore +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/article_rag.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/ask.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/search_bibtex/.gitignore +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/search_bibtex/search.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/write_article/.gitignore +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/write_article/write_article.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/write_outline/.gitignore +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/write_outline/write_outline.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/write_outline/write_outline_corrected.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/_rust.pyi +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/_rust_instances.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/actions/output.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/actions/rag.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/correct.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/rag.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/rating.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/review.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/config.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/action.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/kwargs_types.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/models/usages.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/src/bib_tools.rs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/src/hash.rs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/src/hbs_helpers.rs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/src/lib.rs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/src/templates.rs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/as_prompt.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/co_validation.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/correct.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/refined_query.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/tests/test_config.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.7.dev2 → 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
|
+

|
47
|
+

|
48
|
+

|
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
|
+

|
4
|
+

|
5
|
+

|
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)
|
{fabricatio-0.2.7.dev2 → fabricatio-0.2.7.dev4}/examples/extract_and_inject/extract_and_inject.py
RENAMED
@@ -8,7 +8,7 @@ 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
12
|
from fabricatio.models.utils import ok
|
13
13
|
from pydantic import HttpUrl
|
14
14
|
|
@@ -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:
|
@@ -6,7 +6,10 @@ from typing import Any, Callable, List, Optional
|
|
6
6
|
from fabricatio.fs import safe_text_read
|
7
7
|
from fabricatio.journal import logger
|
8
8
|
from fabricatio.models.action import Action
|
9
|
-
from fabricatio.models.extra import
|
9
|
+
from fabricatio.models.extra.article_essence import ArticleEssence
|
10
|
+
from fabricatio.models.extra.article_main import Article
|
11
|
+
from fabricatio.models.extra.article_outline import ArticleOutline
|
12
|
+
from fabricatio.models.extra.article_proposal import ArticleProposal
|
10
13
|
from fabricatio.models.task import Task
|
11
14
|
from fabricatio.models.utils import ok
|
12
15
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"""A module for writing articles using RAG (Retrieval-Augmented Generation) capabilities."""
|
2
|
+
|
3
|
+
from typing import Optional
|
4
|
+
|
5
|
+
from fabricatio.capabilities.rag import RAG
|
6
|
+
from fabricatio.journal import logger
|
7
|
+
from fabricatio.models.action import Action
|
8
|
+
from fabricatio.models.extra.article_main import Article
|
9
|
+
from fabricatio.models.extra.article_outline import ArticleOutline
|
10
|
+
|
11
|
+
|
12
|
+
class GenerateArticleRAG(Action, RAG):
|
13
|
+
"""Write an article based on the provided outline."""
|
14
|
+
|
15
|
+
output_key: str = "article"
|
16
|
+
|
17
|
+
async def _execute(self, article_outline: ArticleOutline, **cxt) -> Optional[Article]:
|
18
|
+
"""Write an article based on the provided outline."""
|
19
|
+
logger.info(f"Writing an article based on the outline:\n{article_outline.title}")
|
20
|
+
refined_q = await self.arefined_query(article_outline.display())
|
21
|
+
return await self.propose(
|
22
|
+
Article,
|
23
|
+
article_outline.display(),
|
24
|
+
**self.prepend_sys_msg(f"{await self.aretrieve_compact(refined_q)}\n{self.briefing}"),
|
25
|
+
)
|
26
|
+
|
27
|
+
|
28
|
+
class WriteArticleFineGrind(Action, RAG):
|
29
|
+
"""Fine-grind an article based on the provided outline."""
|
30
|
+
|
31
|
+
output_key: str = "article"
|
32
|
+
|
33
|
+
async def _execute(self, article_outline: ArticleOutline, **cxt) -> Optional[Article]:
|
34
|
+
"""Fine-grind an article based on the provided outline."""
|
35
|
+
logger.info(f"Fine-grinding an article based on the outline:\n{article_outline.title}")
|
@@ -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())
|