fabricatio 0.2.6.dev2__cp312-cp312-win_amd64.whl → 0.2.7__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fabricatio/__init__.py +7 -24
- fabricatio/_rust.cp312-win_amd64.pyd +0 -0
- fabricatio/_rust.pyi +22 -0
- fabricatio/actions/article.py +168 -19
- fabricatio/actions/article_rag.py +35 -0
- fabricatio/actions/output.py +21 -6
- fabricatio/actions/rag.py +51 -3
- fabricatio/capabilities/correct.py +36 -4
- fabricatio/capabilities/rag.py +67 -16
- fabricatio/capabilities/rating.py +15 -6
- fabricatio/capabilities/review.py +7 -4
- fabricatio/capabilities/task.py +5 -5
- fabricatio/config.py +29 -21
- fabricatio/decorators.py +32 -0
- fabricatio/models/action.py +117 -43
- fabricatio/models/extra/article_base.py +378 -0
- fabricatio/models/extra/article_essence.py +226 -0
- fabricatio/models/extra/article_main.py +196 -0
- fabricatio/models/extra/article_outline.py +32 -0
- fabricatio/models/extra/article_proposal.py +35 -0
- fabricatio/models/generic.py +164 -14
- fabricatio/models/kwargs_types.py +40 -10
- fabricatio/models/role.py +30 -6
- fabricatio/models/tool.py +6 -2
- fabricatio/models/usages.py +94 -47
- fabricatio/models/utils.py +29 -2
- fabricatio/parser.py +2 -0
- fabricatio/workflows/articles.py +12 -1
- fabricatio-0.2.7.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.7.dist-info/METADATA +181 -0
- fabricatio-0.2.7.dist-info/RECORD +47 -0
- {fabricatio-0.2.6.dev2.dist-info → fabricatio-0.2.7.dist-info}/WHEEL +1 -1
- fabricatio/models/extra.py +0 -171
- fabricatio-0.2.6.dev2.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.6.dev2.dist-info/METADATA +0 -432
- fabricatio-0.2.6.dev2.dist-info/RECORD +0 -42
- {fabricatio-0.2.6.dev2.dist-info → fabricatio-0.2.7.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
fabricatio-0.2.7.dist-info/METADATA,sha256=pURYBzHBlC9kis-tB11uD9qVokoR9Kpj52synmR7sMs,5254
|
2
|
+
fabricatio-0.2.7.dist-info/WHEEL,sha256=jABKVkLC9kJr8mi_er5jOqpiQUjARSLXDUIIxDqsS50,96
|
3
|
+
fabricatio-0.2.7.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
|
4
|
+
fabricatio/actions/article.py,sha256=W8MePeBrROpByxX48CKe4IwjRpm49-bnqM4V1SYThZk,8356
|
5
|
+
fabricatio/actions/article_rag.py,sha256=PiOFxI6VTmLXm3BK-01g_KH1mTE9uOtnA-CwUjt16AU,1456
|
6
|
+
fabricatio/actions/output.py,sha256=K7xsBH8MjXRH6JOy3ZO94KCQzX2jNrwPPK_rRXVkS0E,1161
|
7
|
+
fabricatio/actions/rag.py,sha256=QBdzEM8MloM_ahx5pTBZAETm9_631lTe_0ih_he_Iuo,2759
|
8
|
+
fabricatio/capabilities/correct.py,sha256=EM58d6Kt_XVpJFk9bkIbgBDA9LYTt6t5I0LPVuf_Fq8,6530
|
9
|
+
fabricatio/capabilities/propose.py,sha256=y3kge5g6bb8HYuV8e9h4MdqOMTlsfAIZpqE_cagWPTY,1593
|
10
|
+
fabricatio/capabilities/rag.py,sha256=XVvfH6rcog-moj1WCgwtR-l0-NdbFR6-fMQFLG7_asY,17690
|
11
|
+
fabricatio/capabilities/rating.py,sha256=yEPqL5_DqVMj_AH9cMvKsHdMnSbvm8dN6PaKHLsJUPQ,14904
|
12
|
+
fabricatio/capabilities/review.py,sha256=uc4WV9Xu-4rXAXZ-k-32HXAgm4WMLbDRfiZdRP7Nepg,11384
|
13
|
+
fabricatio/capabilities/task.py,sha256=vtS0YOe639vN8iTrkP2WK0AJVCr5N_JAaJuvRGyY2Fg,4639
|
14
|
+
fabricatio/config.py,sha256=hUv5XMzOkEw8cQjsVHTpPPix52IKwmxjBsZM6Px3xZI,16915
|
15
|
+
fabricatio/core.py,sha256=VQ_JKgUGIy2gZ8xsTBZCdr_IP7wC5aPg0_bsOmjQ588,6458
|
16
|
+
fabricatio/decorators.py,sha256=C0Gi7wcXC-0sWITqsSv3JdBGcgVJOlRvOt0FfO0aUsA,7554
|
17
|
+
fabricatio/fs/curd.py,sha256=N6l2MncjrFfnXBRtteRouXp5Rjy8EAKC_i29_G-zz98,4618
|
18
|
+
fabricatio/fs/readers.py,sha256=EZKN_AZdrp8DggJECP53QHw3uHeSDf-AwCAA_V7fNKU,1202
|
19
|
+
fabricatio/fs/__init__.py,sha256=PCf0s_9KDjVfNw7AfPoJzGt3jMq4gJOfbcT4pb0D0ZY,588
|
20
|
+
fabricatio/journal.py,sha256=stnEP88aUBA_GmU9gfTF2EZI8FS2OyMLGaMSTgK4QgA,476
|
21
|
+
fabricatio/models/action.py,sha256=UlflniS__MMrUXglu_U3PDFAtKEjVsKEix17AT9oP3M,8769
|
22
|
+
fabricatio/models/events.py,sha256=QvlnS8FEELg6KNabcJMeh2GV_y0ZBzKOPphcteKYWYU,4183
|
23
|
+
fabricatio/models/extra/article_base.py,sha256=kX32SvjUitK7fQr97joKyWlTpjqjrvsrWQVVqjggwkA,15371
|
24
|
+
fabricatio/models/extra/article_essence.py,sha256=DUESuK4CGgkRvIMoJCv4l8MNp5MawRYoNOtLCrFRPXY,9229
|
25
|
+
fabricatio/models/extra/article_main.py,sha256=XekZcXztjWdFT39lZ_Ny0zVGu56wt1oieeLd7aLPJo8,7400
|
26
|
+
fabricatio/models/extra/article_outline.py,sha256=pIsO5bOSV-SUeWWdhkfkVpcr9RPOHgYmsceHsrXs67M,1145
|
27
|
+
fabricatio/models/extra/article_proposal.py,sha256=p0NPzqg9x6t65DZqdF52Z1P0JwP6kwo2_eP-NsXgifU,1720
|
28
|
+
fabricatio/models/generic.py,sha256=tVMitdYI6gK30eWAIFvfXSRWliTzcfMKvuhaKFcZ_xw,19004
|
29
|
+
fabricatio/models/kwargs_types.py,sha256=chJ-rHaeBVRUPuORHuGR3DdNxxTUrotz0eflPEh4l4w,5474
|
30
|
+
fabricatio/models/role.py,sha256=mmQbJ6GKr2Gx3wtjEz8d-vYoXs09ffcEkT_eCXaDd3E,2782
|
31
|
+
fabricatio/models/task.py,sha256=8NaR7ojQWyM740EDTqt9stwHKdrD6axCRpLKo0QzS-I,10492
|
32
|
+
fabricatio/models/tool.py,sha256=kD0eB7OxO9geZOxO6JIKvCBeG-KOpRAkfRZqK_WGfW4,7105
|
33
|
+
fabricatio/models/usages.py,sha256=BSqTENSva8Flga3bPBfwuc1nHo5Z_29oYzar99NbjLM,31566
|
34
|
+
fabricatio/models/utils.py,sha256=yjxPZ6N7QGpGwkI_Vb28Ud3EhkdlB-tyfGRHAZMcGxs,5872
|
35
|
+
fabricatio/parser.py,sha256=9Jzw-yV6uKbFvf6sPna-XHdziVGVBZWvPctgX_6ODL8,6251
|
36
|
+
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
37
|
+
fabricatio/toolboxes/arithmetic.py,sha256=WLqhY-Pikv11Y_0SGajwZx3WhsLNpHKf9drzAqOf_nY,1369
|
38
|
+
fabricatio/toolboxes/fs.py,sha256=l4L1CVxJmjw9Ld2XUpIlWfV0_Fu_2Og6d3E13I-S4aE,736
|
39
|
+
fabricatio/toolboxes/__init__.py,sha256=KBJi5OG_pExscdlM7Bnt_UF43j4I3Lv6G71kPVu4KQU,395
|
40
|
+
fabricatio/workflows/articles.py,sha256=G5HGRr-DHuYuEcfhFdFAuDvTTJ9aSU_UQ2yYXEjTMtM,1047
|
41
|
+
fabricatio/workflows/rag.py,sha256=-YYp2tlE9Vtfgpg6ROpu6QVO8j8yVSPa6yDzlN3qVxs,520
|
42
|
+
fabricatio/_rust.pyi,sha256=dGTGV7viu3YAGl1cRKIWrdHPc1hlwk3_hbaDaswxdVo,3831
|
43
|
+
fabricatio/_rust_instances.py,sha256=2GwF8aVfYNemRI2feBzH1CZfBGno-XJJE5imJokGEYw,314
|
44
|
+
fabricatio/__init__.py,sha256=SzBYsRhZeL77jLtfJEjmoHOSwHwUGyvMATX6xfndLDM,1135
|
45
|
+
fabricatio/_rust.cp312-win_amd64.pyd,sha256=KSrEUEqHJLRXmr2uwDgmVVxBu_oGHsN68uvH2hm4vDs,1835008
|
46
|
+
fabricatio-0.2.7.data/scripts/tdown.exe,sha256=6GgVuiuWQ_iaKcoswVvE8bS1pYvemvGfmKo0CZV2WmE,3399680
|
47
|
+
fabricatio-0.2.7.dist-info/RECORD,,
|
fabricatio/models/extra.py
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
"""Extra models for built-in actions."""
|
2
|
-
|
3
|
-
from typing import List
|
4
|
-
|
5
|
-
from fabricatio.models.generic import Base, Display, FinalizedDumpAble, PrepareVectorization, ProposedAble
|
6
|
-
from pydantic import Field
|
7
|
-
|
8
|
-
|
9
|
-
class Equation(Base):
|
10
|
-
"""Structured representation of mathematical equations (including their physical or conceptual meanings)."""
|
11
|
-
|
12
|
-
description: str
|
13
|
-
"""A concise explanation of the equation's meaning, purpose, and relevance in the context of the research."""
|
14
|
-
|
15
|
-
latex_code: str
|
16
|
-
"""The LaTeX code used to represent the equation in a publication-ready format."""
|
17
|
-
|
18
|
-
|
19
|
-
class Figure(Base):
|
20
|
-
"""Structured representation of figures (including their academic significance and explanatory captions)."""
|
21
|
-
|
22
|
-
description: str
|
23
|
-
"""A detailed explanation of the figure's content and its role in conveying key insights."""
|
24
|
-
|
25
|
-
figure_caption: str
|
26
|
-
"""The caption accompanying the figure, summarizing its main points and academic value."""
|
27
|
-
|
28
|
-
figure_path: str
|
29
|
-
"""The file path to the figure"""
|
30
|
-
|
31
|
-
|
32
|
-
class Highlightings(Base):
|
33
|
-
"""Structured representation of highlighted elements in an academic paper (including equations, algorithms, figures, and tables)."""
|
34
|
-
|
35
|
-
# Academic Achievements Showcase
|
36
|
-
highlighted_equations: List[Equation] = Field(default_factory=list)
|
37
|
-
"""Core mathematical equations that represent breakthroughs in the field, accompanied by explanations of their physical or conceptual significance,Should always be in LaTeX format wrapped in $ or $$ signs."""
|
38
|
-
|
39
|
-
highlighted_algorithms: List[str] = Field(default_factory=list)
|
40
|
-
"""Pseudocode for key algorithms, annotated to highlight innovative components."""
|
41
|
-
|
42
|
-
highlighted_figures: List[Figure] = Field(default_factory=list)
|
43
|
-
"""Critical diagrams or illustrations, each accompanied by a caption explaining their academic importance."""
|
44
|
-
|
45
|
-
highlighted_tables: List[str] = Field(default_factory=list)
|
46
|
-
"""Important data tables, annotated to indicate statistical significance or other notable findings."""
|
47
|
-
|
48
|
-
|
49
|
-
class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
50
|
-
"""Structured representation of the core elements of an academic paper(providing a comprehensive digital profile of the paper's essential information)."""
|
51
|
-
|
52
|
-
# Basic Metadata
|
53
|
-
title: str = Field(...)
|
54
|
-
"""The full title of the paper, including any subtitles if applicable."""
|
55
|
-
|
56
|
-
authors: List[str]
|
57
|
-
"""A list of the paper's authors, typically in the order of contribution."""
|
58
|
-
|
59
|
-
keywords: List[str]
|
60
|
-
"""A list of keywords that summarize the paper's focus and facilitate indexing."""
|
61
|
-
|
62
|
-
publication_year: int
|
63
|
-
"""The year in which the paper was published."""
|
64
|
-
|
65
|
-
# Core Content Elements
|
66
|
-
highlightings: Highlightings = Field(default_factory=Highlightings)
|
67
|
-
"""A collection of highlighted elements in the paper, including equations, algorithms, figures, and tables."""
|
68
|
-
|
69
|
-
domain: List[str]
|
70
|
-
"""The research domains or fields addressed by the paper (e.g., ['Natural Language Processing', 'Computer Vision'])."""
|
71
|
-
|
72
|
-
abstract: str = Field(...)
|
73
|
-
"""A structured abstract that outlines the research problem, methodology, and conclusions in three distinct sections."""
|
74
|
-
|
75
|
-
core_contributions: List[str]
|
76
|
-
"""Key academic contributions that distinguish the paper from prior work in the field."""
|
77
|
-
|
78
|
-
technical_novelty: List[str]
|
79
|
-
"""Specific technical innovations introduced by the research, listed as individual points."""
|
80
|
-
|
81
|
-
# Academic Discussion Dimensions
|
82
|
-
research_problems: List[str]
|
83
|
-
"""A clearly defined research question or problem addressed by the study."""
|
84
|
-
|
85
|
-
limitations: List[str]
|
86
|
-
"""An analysis of the methodological or experimental limitations of the research."""
|
87
|
-
|
88
|
-
future_work: List[str]
|
89
|
-
"""Suggestions for potential directions or topics for follow-up studies."""
|
90
|
-
|
91
|
-
impact_analysis: List[str]
|
92
|
-
"""An assessment of the paper's potential influence on the development of the field."""
|
93
|
-
|
94
|
-
def _prepare_vectorization_inner(self) -> str:
|
95
|
-
return self.model_dump_json()
|
96
|
-
|
97
|
-
|
98
|
-
class ArticleProposal(ProposedAble, Display):
|
99
|
-
"""Structured representation of the proposal for an academic paper."""
|
100
|
-
|
101
|
-
title: str = Field(...)
|
102
|
-
"""The proposed title of the paper."""
|
103
|
-
|
104
|
-
focused_problem: List[str] = Field(default_factory=list)
|
105
|
-
"""The specific research problem or question that the paper aims to address."""
|
106
|
-
research_aim: List[str] = Field(default_factory=list)
|
107
|
-
"""The main objective or goal of the research, outlining what the study aims to achieve."""
|
108
|
-
research_methods: List[str] = Field(default_factory=list)
|
109
|
-
"""The methods used in the research, including the approach, techniques, and tools employed."""
|
110
|
-
|
111
|
-
|
112
|
-
class ArticleSubsectionOutline(Base):
|
113
|
-
"""Structured representation of the subsections of an academic paper."""
|
114
|
-
|
115
|
-
title: str = Field(...)
|
116
|
-
"""The title of the subsection."""
|
117
|
-
|
118
|
-
description: str = Field(...)
|
119
|
-
"""A brief description of the subsection's content should be, how it fits into the overall structure of the paper, and its significance in the context of the research."""
|
120
|
-
|
121
|
-
|
122
|
-
class ArticleSectionOutline(Base):
|
123
|
-
"""Structured representation of the sections of an academic paper."""
|
124
|
-
|
125
|
-
title: str = Field(...)
|
126
|
-
"""The title of the section."""
|
127
|
-
description: str = Field(...)
|
128
|
-
"""A brief description of the section's content should be, how it fits into the overall structure of the paper, and its significance in the context of the research."""
|
129
|
-
subsections: List[ArticleSubsectionOutline] = Field(default_factory=list)
|
130
|
-
"""The subsections of the section, outlining their content and significance."""
|
131
|
-
|
132
|
-
|
133
|
-
class ArticleChapterOutline(Base):
|
134
|
-
"""Structured representation of the chapters of an academic paper."""
|
135
|
-
|
136
|
-
title: str = Field(...)
|
137
|
-
"""The title of the chapter."""
|
138
|
-
description: str = Field(...)
|
139
|
-
"""A brief description of the chapter's content should be, how it fits into the overall structure of the paper, and its significance in the context of the research."""
|
140
|
-
sections: List[ArticleSectionOutline] = Field(default_factory=list)
|
141
|
-
"""The sections of the chapter, outlining their content and significance."""
|
142
|
-
|
143
|
-
|
144
|
-
class ArticleOutline(ProposedAble, Display, FinalizedDumpAble):
|
145
|
-
"""Structured representation of the outline for an academic paper."""
|
146
|
-
|
147
|
-
title: str = Field(...)
|
148
|
-
"""The proposed title of the paper."""
|
149
|
-
|
150
|
-
prospect: str = Field(...)
|
151
|
-
"""A brief description of the research problem or question that the paper aims to address manipulating methods or techniques"""
|
152
|
-
|
153
|
-
chapters: List[ArticleChapterOutline] = Field(default_factory=list)
|
154
|
-
"""The chapters of the paper, outlining their content and significance."""
|
155
|
-
|
156
|
-
def finalized_dump(self) -> str:
|
157
|
-
"""Finalized dump of the article outline.
|
158
|
-
|
159
|
-
Returns:
|
160
|
-
str: The finalized dump of the article outline.
|
161
|
-
"""
|
162
|
-
lines: List[str] = []
|
163
|
-
|
164
|
-
for chapter in self.chapters:
|
165
|
-
lines.append(f"= {chapter.title}")
|
166
|
-
for section in chapter.sections:
|
167
|
-
lines.append(f"== {section.title}")
|
168
|
-
for subsection in section.subsections:
|
169
|
-
lines.append(f"=== {subsection.title}")
|
170
|
-
|
171
|
-
return "\n\n".join(lines)
|
Binary file
|
@@ -1,432 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: fabricatio
|
3
|
-
Version: 0.2.6.dev2
|
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[rag] ; extra == 'full'
|
28
|
-
Provides-Extra: rag
|
29
|
-
Provides-Extra: full
|
30
|
-
License-File: LICENSE
|
31
|
-
Summary: A LLM multi-agent framework.
|
32
|
-
Keywords: ai,agents,multi-agent,llm,pyo3
|
33
|
-
Author-email: Whth <zettainspector@foxmail.com>
|
34
|
-
Requires-Python: >=3.12, <3.13
|
35
|
-
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
36
|
-
Project-URL: Homepage, https://github.com/Whth/fabricatio
|
37
|
-
Project-URL: Repository, https://github.com/Whth/fabricatio
|
38
|
-
Project-URL: Issues, https://github.com/Whth/fabricatio/issues
|
39
|
-
|
40
|
-
# Fabricatio
|
41
|
-
|
42
|
-

|
43
|
-

|
44
|
-

|
45
|
-
|
46
|
-
## Overview
|
47
|
-
|
48
|
-
Fabricatio is a Python library designed for building LLM (Large Language Model) applications using an event-based agent structure. It integrates Rust for performance-critical tasks, utilizes Handlebars for templating, and employs PyO3 for Python bindings.
|
49
|
-
|
50
|
-
## Features
|
51
|
-
|
52
|
-
- **Event-Based Architecture**: Utilizes an EventEmitter pattern for robust task management.
|
53
|
-
- **LLM Integration**: Supports interactions with large language models for intelligent task processing.
|
54
|
-
- **Templating Engine**: Uses Handlebars for dynamic content generation.
|
55
|
-
- **Toolboxes**: Provides predefined toolboxes for common operations like file manipulation and arithmetic.
|
56
|
-
- **Async Support**: Fully asynchronous for efficient execution.
|
57
|
-
- **Extensible**: Easy to extend with custom actions, workflows, and tools.
|
58
|
-
|
59
|
-
## Installation
|
60
|
-
|
61
|
-
### Using UV (Recommended)
|
62
|
-
|
63
|
-
To install Fabricatio using `uv` (a package manager for Python):
|
64
|
-
|
65
|
-
```bash
|
66
|
-
# Install uv if not already installed
|
67
|
-
pip install uv
|
68
|
-
|
69
|
-
# Clone the repository
|
70
|
-
git clone https://github.com/Whth/fabricatio.git
|
71
|
-
cd fabricatio
|
72
|
-
|
73
|
-
# Install the package in development mode with uv
|
74
|
-
uv --with-editable . maturin develop --uv -r
|
75
|
-
```
|
76
|
-
|
77
|
-
### Building Distribution
|
78
|
-
|
79
|
-
For production builds:
|
80
|
-
|
81
|
-
```bash
|
82
|
-
# Build distribution packages
|
83
|
-
make bdist
|
84
|
-
```
|
85
|
-
|
86
|
-
This will generate distribution files in the `dist` directory.
|
87
|
-
|
88
|
-
## Usage
|
89
|
-
|
90
|
-
### Basic Example
|
91
|
-
|
92
|
-
#### Simple Hello World Program
|
93
|
-
|
94
|
-
```python
|
95
|
-
import asyncio
|
96
|
-
from fabricatio import Action, Role, Task, logger, WorkFlow
|
97
|
-
from typing import Any
|
98
|
-
|
99
|
-
class Hello(Action):
|
100
|
-
name: str = "hello"
|
101
|
-
output_key: str = "task_output"
|
102
|
-
|
103
|
-
async def _execute(self, task_input: Task[str], **_) -> Any:
|
104
|
-
ret = "Hello fabricatio!"
|
105
|
-
logger.info("executing talk action")
|
106
|
-
return ret
|
107
|
-
|
108
|
-
async def main() -> None:
|
109
|
-
role = Role(
|
110
|
-
name="talker",
|
111
|
-
description="talker role",
|
112
|
-
registry={Task.pending_label: WorkFlow(name="talk", steps=(Hello,))}
|
113
|
-
)
|
114
|
-
|
115
|
-
task = Task(name="say hello", goals="say hello", description="say hello to the world")
|
116
|
-
result = await task.delegate()
|
117
|
-
logger.success(f"Result: {result}")
|
118
|
-
|
119
|
-
if __name__ == "__main__":
|
120
|
-
asyncio.run(main())
|
121
|
-
```
|
122
|
-
|
123
|
-
### Advanced Examples
|
124
|
-
|
125
|
-
#### Simple Chat
|
126
|
-
|
127
|
-
Demonstrates a basic chat application.
|
128
|
-
|
129
|
-
```python
|
130
|
-
"""Simple chat example."""
|
131
|
-
import asyncio
|
132
|
-
from fabricatio import Action, Role, Task, WorkFlow, logger
|
133
|
-
from fabricatio.models.events import Event
|
134
|
-
from questionary import text
|
135
|
-
|
136
|
-
class Talk(Action):
|
137
|
-
"""Action that says hello to the world."""
|
138
|
-
|
139
|
-
output_key: str = "task_output"
|
140
|
-
|
141
|
-
async def _execute(self, task_input: Task[str], **_) -> int:
|
142
|
-
counter = 0
|
143
|
-
try:
|
144
|
-
while True:
|
145
|
-
user_say = await text("User: ").ask_async()
|
146
|
-
gpt_say = await self.aask(
|
147
|
-
user_say,
|
148
|
-
system_message=f"You have to answer to user obeying task assigned to you:\n{task_input.briefing}",
|
149
|
-
)
|
150
|
-
print(f"GPT: {gpt_say}") # noqa: T201
|
151
|
-
counter += 1
|
152
|
-
except KeyboardInterrupt:
|
153
|
-
logger.info(f"executed talk action {counter} times")
|
154
|
-
return counter
|
155
|
-
|
156
|
-
async def main() -> None:
|
157
|
-
"""Main function."""
|
158
|
-
role = Role(
|
159
|
-
name="talker",
|
160
|
-
description="talker role",
|
161
|
-
registry={Event.instantiate_from("talk").push_wildcard().push("pending"): WorkFlow(name="talk", steps=(Talk,))},
|
162
|
-
)
|
163
|
-
|
164
|
-
task = await role.propose_task(
|
165
|
-
"you have to act as a helpful assistant, answer to all user questions properly and patiently"
|
166
|
-
)
|
167
|
-
_ = await task.delegate("talk")
|
168
|
-
|
169
|
-
if __name__ == "__main__":
|
170
|
-
asyncio.run(main())
|
171
|
-
```
|
172
|
-
|
173
|
-
#### Simple RAG
|
174
|
-
|
175
|
-
Demonstrates Retrieval-Augmented Generation (RAG).
|
176
|
-
|
177
|
-
```python
|
178
|
-
"""Simple chat example."""
|
179
|
-
import asyncio
|
180
|
-
from fabricatio import RAG, Action, Role, Task, WorkFlow, logger
|
181
|
-
from fabricatio.models.events import Event
|
182
|
-
from questionary import text
|
183
|
-
|
184
|
-
class Talk(Action, RAG):
|
185
|
-
"""Action that says hello to the world."""
|
186
|
-
|
187
|
-
output_key: str = "task_output"
|
188
|
-
|
189
|
-
async def _execute(self, task_input: Task[str], **_) -> int:
|
190
|
-
counter = 0
|
191
|
-
|
192
|
-
self.init_client().view("test_collection", create=True)
|
193
|
-
await self.consume_string(
|
194
|
-
[
|
195
|
-
"Company policy clearly stipulates that all employees must arrive at the headquarters building located at 88 Jianguo Road, Chaoyang District, Beijing before 9 AM daily.",
|
196
|
-
"According to the latest revised health and safety guidelines, employees must wear company-provided athletic gear when using the company gym facilities.",
|
197
|
-
"Section 3.2.1 of the employee handbook states that pets are not allowed in the office area under any circumstances.",
|
198
|
-
"To promote work efficiency, the company has quiet workspaces at 100 Century Avenue, Pudong New District, Shanghai, for employees who need high concentration for their work.",
|
199
|
-
"According to the company's remote work policy, employees can apply for a maximum of 5 days of working from home per month, but must submit the application one week in advance.",
|
200
|
-
"The company has strict regulations on overtime. Unless approved by direct supervisors, no form of work is allowed after 9 PM.",
|
201
|
-
"Regarding the new regulations for business travel reimbursement, all traveling personnel must submit detailed expense reports within five working days after returning.",
|
202
|
-
"Company address: 123 East Sports Road, Tianhe District, Guangzhou, Postal Code: 510620.",
|
203
|
-
"Annual team building activities will be held in the second quarter of each year, usually at a resort within a two-hour drive from the Guangzhou headquarters.",
|
204
|
-
"Employees who are late more than three times will receive a formal warning, which may affect their year-end performance evaluation.",
|
205
|
-
]
|
206
|
-
)
|
207
|
-
try:
|
208
|
-
while True:
|
209
|
-
user_say = await text("User: ").ask_async()
|
210
|
-
if user_say is None:
|
211
|
-
break
|
212
|
-
gpt_say = await self.aask_retrieved(
|
213
|
-
user_say,
|
214
|
-
user_say,
|
215
|
-
extra_system_message=f"You have to answer to user obeying task assigned to you:\n{task_input.briefing}",
|
216
|
-
)
|
217
|
-
print(f"GPT: {gpt_say}") # noqa: T201
|
218
|
-
counter += 1
|
219
|
-
except KeyboardInterrupt:
|
220
|
-
logger.info(f"executed talk action {counter} times")
|
221
|
-
return counter
|
222
|
-
|
223
|
-
async def main() -> None:
|
224
|
-
"""Main function."""
|
225
|
-
role = Role(
|
226
|
-
name="talker",
|
227
|
-
description="talker role but with rag",
|
228
|
-
registry={Event.instantiate_from("talk").push_wildcard().push("pending"): WorkFlow(name="talk", steps=(Talk,))},
|
229
|
-
)
|
230
|
-
|
231
|
-
task = await role.propose_task(
|
232
|
-
"you have to act as a helpful assistant, answer to all user questions properly and patiently"
|
233
|
-
)
|
234
|
-
_ = await task.delegate("talk")
|
235
|
-
|
236
|
-
if __name__ == "__main__":
|
237
|
-
asyncio.run(main())
|
238
|
-
```
|
239
|
-
|
240
|
-
#### Extract Article
|
241
|
-
|
242
|
-
Demonstrates extracting the essence of an article from a file.
|
243
|
-
|
244
|
-
```python
|
245
|
-
"""Example of proposing a task to a role."""
|
246
|
-
import asyncio
|
247
|
-
from typing import List
|
248
|
-
|
249
|
-
from fabricatio import ArticleEssence, Event, ExtractArticleEssence, Role, Task, WorkFlow, logger
|
250
|
-
|
251
|
-
async def main() -> None:
|
252
|
-
"""Main function."""
|
253
|
-
role = Role(
|
254
|
-
name="Researcher",
|
255
|
-
description="Extract article essence",
|
256
|
-
registry={
|
257
|
-
Event.quick_instantiate("article"): WorkFlow(
|
258
|
-
name="extract",
|
259
|
-
steps=(ExtractArticleEssence(output_key="task_output"),),
|
260
|
-
)
|
261
|
-
},
|
262
|
-
)
|
263
|
-
task: Task[List[ArticleEssence]] = await role.propose_task(
|
264
|
-
"Extract the essence of the article from the file at './7.md'"
|
265
|
-
)
|
266
|
-
ess = (await task.delegate("article")).pop()
|
267
|
-
logger.success(f"Essence:\n{ess.display()}")
|
268
|
-
|
269
|
-
if __name__ == "__main__":
|
270
|
-
asyncio.run(main())
|
271
|
-
```
|
272
|
-
|
273
|
-
#### Propose Task
|
274
|
-
|
275
|
-
Demonstrates proposing a task to a role.
|
276
|
-
|
277
|
-
```python
|
278
|
-
"""Example of proposing a task to a role."""
|
279
|
-
import asyncio
|
280
|
-
from typing import Any
|
281
|
-
|
282
|
-
from fabricatio import Action, Event, Role, Task, WorkFlow, logger
|
283
|
-
|
284
|
-
class Talk(Action):
|
285
|
-
"""Action that says hello to the world."""
|
286
|
-
|
287
|
-
output_key: str = "task_output"
|
288
|
-
|
289
|
-
async def _execute(self, **_) -> Any:
|
290
|
-
ret = "Hello fabricatio!"
|
291
|
-
logger.info("executing talk action")
|
292
|
-
return ret
|
293
|
-
|
294
|
-
async def main() -> None:
|
295
|
-
"""Main function."""
|
296
|
-
role = Role(
|
297
|
-
name="talker",
|
298
|
-
description="talker role",
|
299
|
-
registry={Event.quick_instantiate("talk"): WorkFlow(name="talk", steps=(Talk,))},
|
300
|
-
)
|
301
|
-
logger.info(f"Task example:\n{Task.formated_json_schema()}")
|
302
|
-
logger.info(f"proposed task: {await role.propose_task('write a rust clap cli that can download a html page')}")
|
303
|
-
|
304
|
-
if __name__ == "__main__":
|
305
|
-
asyncio.run(main())
|
306
|
-
```
|
307
|
-
|
308
|
-
#### Review
|
309
|
-
|
310
|
-
Demonstrates reviewing code.
|
311
|
-
|
312
|
-
```python
|
313
|
-
"""Example of review usage."""
|
314
|
-
import asyncio
|
315
|
-
|
316
|
-
from fabricatio import Role, logger
|
317
|
-
|
318
|
-
async def main() -> None:
|
319
|
-
"""Main function."""
|
320
|
-
role = Role(
|
321
|
-
name="Reviewer",
|
322
|
-
description="A role that reviews the code.",
|
323
|
-
)
|
324
|
-
|
325
|
-
code = await role.aask(
|
326
|
-
"write a cli app using rust with clap which can generate a basic manifest of a standard rust project, output code only,no extra explanation"
|
327
|
-
)
|
328
|
-
|
329
|
-
logger.success(f"Code: \n{code}")
|
330
|
-
res = await role.review_string(code, "If the cli app is of good design")
|
331
|
-
logger.success(f"Review: \n{res.display()}")
|
332
|
-
await res.supervisor_check()
|
333
|
-
logger.success(f"Review: \n{res.display()}")
|
334
|
-
|
335
|
-
if __name__ == "__main__":
|
336
|
-
asyncio.run(main())
|
337
|
-
```
|
338
|
-
|
339
|
-
#### Write Outline
|
340
|
-
|
341
|
-
Demonstrates writing an outline for an article in Typst format.
|
342
|
-
|
343
|
-
```python
|
344
|
-
"""Example of using the library."""
|
345
|
-
import asyncio
|
346
|
-
|
347
|
-
from fabricatio import Event, Role, WriteOutlineWorkFlow, logger
|
348
|
-
|
349
|
-
async def main() -> None:
|
350
|
-
"""Main function."""
|
351
|
-
role = Role(
|
352
|
-
name="Undergraduate Researcher",
|
353
|
-
description="Write an outline for an article in typst format.",
|
354
|
-
registry={Event.quick_instantiate(ns := "article"): WriteOutlineWorkFlow},
|
355
|
-
)
|
356
|
-
|
357
|
-
proposed_task = await role.propose_task(
|
358
|
-
"You need to read the `./article_briefing.txt` file and write an outline for the article in typst format. The outline should be saved in the `./out.typ` file.",
|
359
|
-
)
|
360
|
-
path = await proposed_task.delegate(ns)
|
361
|
-
logger.success(f"The outline is saved in:\n{path}")
|
362
|
-
|
363
|
-
if __name__ == "__main__":
|
364
|
-
asyncio.run(main())
|
365
|
-
```
|
366
|
-
|
367
|
-
## Configuration
|
368
|
-
|
369
|
-
The configuration for Fabricatio is managed via environment variables or TOML files. The default configuration file (`config.toml`) can be overridden by specifying a custom path.
|
370
|
-
|
371
|
-
Example `config.toml`:
|
372
|
-
|
373
|
-
```toml
|
374
|
-
[llm]
|
375
|
-
api_endpoint = "https://api.openai.com"
|
376
|
-
api_key = "your_openai_api_key"
|
377
|
-
timeout = 300
|
378
|
-
max_retries = 3
|
379
|
-
model = "gpt-3.5-turbo"
|
380
|
-
temperature = 1.0
|
381
|
-
stop_sign = ["\n\n\n", "User:"]
|
382
|
-
top_p = 0.35
|
383
|
-
generation_count = 1
|
384
|
-
stream = false
|
385
|
-
max_tokens = 8192
|
386
|
-
```
|
387
|
-
|
388
|
-
## Development Setup
|
389
|
-
|
390
|
-
To set up a development environment for Fabricatio:
|
391
|
-
|
392
|
-
1. **Clone the Repository**:
|
393
|
-
```bash
|
394
|
-
git clone https://github.com/Whth/fabricatio.git
|
395
|
-
cd fabricatio
|
396
|
-
```
|
397
|
-
|
398
|
-
2. **Install Dependencies**:
|
399
|
-
```bash
|
400
|
-
uv --with-editable . maturin develop --uv -r
|
401
|
-
```
|
402
|
-
|
403
|
-
3. **Run Tests**:
|
404
|
-
```bash
|
405
|
-
make test
|
406
|
-
```
|
407
|
-
|
408
|
-
4. **Build Documentation**:
|
409
|
-
```bash
|
410
|
-
make docs
|
411
|
-
```
|
412
|
-
|
413
|
-
## Contributing
|
414
|
-
|
415
|
-
Contributions are welcome! Please follow these guidelines when contributing:
|
416
|
-
|
417
|
-
1. Fork the repository.
|
418
|
-
2. Create your feature branch (`git checkout -b feature/new-feature`).
|
419
|
-
3. Commit your changes (`git commit -am 'Add new feature'`).
|
420
|
-
4. Push to the branch (`git push origin feature/new-feature`).
|
421
|
-
5. Create a new Pull Request.
|
422
|
-
|
423
|
-
## License
|
424
|
-
|
425
|
-
Fabricatio is licensed under the MIT License. See [LICENSE](LICENSE) for more details.
|
426
|
-
|
427
|
-
## Acknowledgments
|
428
|
-
|
429
|
-
Special thanks to the contributors and maintainers of:
|
430
|
-
- [PyO3](https://github.com/PyO3/pyo3)
|
431
|
-
- [Maturin](https://github.com/PyO3/maturin)
|
432
|
-
- [Handlebars.rs](https://github.com/sunng87/handlebars-rust)
|