fabricatio 0.2.1.dev1__cp312-cp312-win_amd64.whl → 0.2.1.dev3__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/_rust.cp312-win_amd64.pyd +0 -0
- fabricatio/config.py +10 -0
- fabricatio/models/action.py +2 -2
- fabricatio/models/advanced.py +171 -10
- fabricatio/models/kwargs_types.py +7 -2
- fabricatio/models/role.py +2 -3
- fabricatio/models/task.py +3 -0
- fabricatio-0.2.1.dev3.data/scripts/tdown.exe +0 -0
- {fabricatio-0.2.1.dev1.dist-info → fabricatio-0.2.1.dev3.dist-info}/METADATA +1 -1
- {fabricatio-0.2.1.dev1.dist-info → fabricatio-0.2.1.dev3.dist-info}/RECORD +12 -12
- fabricatio-0.2.1.dev1.data/scripts/tdown.exe +0 -0
- {fabricatio-0.2.1.dev1.dist-info → fabricatio-0.2.1.dev3.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.1.dev1.dist-info → fabricatio-0.2.1.dev3.dist-info}/licenses/LICENSE +0 -0
Binary file
|
fabricatio/config.py
CHANGED
@@ -157,6 +157,15 @@ class TemplateConfig(BaseModel):
|
|
157
157
|
task_briefing_template: str = Field(default="task_briefing")
|
158
158
|
"""The name of the task briefing template which will be used to brief a task."""
|
159
159
|
|
160
|
+
rate_fine_grind_template: str = Field(default="rate_fine_grind")
|
161
|
+
"""The name of the rate fine grind template which will be used to rate fine grind."""
|
162
|
+
|
163
|
+
draft_rating_manual_template: str = Field(default="draft_rating_manual")
|
164
|
+
"""The name of the draft rating manual template which will be used to draft rating manual."""
|
165
|
+
|
166
|
+
draft_rating_dimensions_template: str = Field(default="draft_rating_dimensions")
|
167
|
+
"""The name of the draft rating dimensions template which will be used to draft rating dimensions."""
|
168
|
+
|
160
169
|
|
161
170
|
class MagikaConfig(BaseModel):
|
162
171
|
"""Magika configuration class."""
|
@@ -208,6 +217,7 @@ class Settings(BaseSettings):
|
|
208
217
|
toml_file=["fabricatio.toml", rf"{ROAMING_DIR}\fabricatio.toml"],
|
209
218
|
env_file=[".env", ".envrc"],
|
210
219
|
use_attribute_docstrings=True,
|
220
|
+
extra="ignore",
|
211
221
|
)
|
212
222
|
|
213
223
|
llm: LLMConfig = Field(default_factory=LLMConfig)
|
fabricatio/models/action.py
CHANGED
@@ -6,14 +6,14 @@ from asyncio import Queue
|
|
6
6
|
from typing import Any, Dict, Self, Tuple, Type, Union, Unpack
|
7
7
|
|
8
8
|
from fabricatio.journal import logger
|
9
|
-
from fabricatio.models.advanced import HandleTask, ProposeTask
|
9
|
+
from fabricatio.models.advanced import GiveRating, HandleTask, ProposeTask
|
10
10
|
from fabricatio.models.generic import WithBriefing
|
11
11
|
from fabricatio.models.task import Task
|
12
12
|
from fabricatio.models.usages import ToolBoxUsage
|
13
13
|
from pydantic import Field, PrivateAttr
|
14
14
|
|
15
15
|
|
16
|
-
class Action(HandleTask, ProposeTask):
|
16
|
+
class Action(HandleTask, ProposeTask, GiveRating):
|
17
17
|
"""Class that represents an action to be executed in a workflow."""
|
18
18
|
|
19
19
|
personality: str = Field(default="")
|
fabricatio/models/advanced.py
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
"""A module for advanced models and functionalities."""
|
2
2
|
|
3
3
|
from types import CodeType
|
4
|
-
from typing import Any, Dict, List, Optional, Tuple, Unpack
|
4
|
+
from typing import Any, Dict, List, Optional, Set, Tuple, Unpack
|
5
5
|
|
6
6
|
import orjson
|
7
7
|
from fabricatio._rust_instances import template_manager
|
8
8
|
from fabricatio.config import configs
|
9
9
|
from fabricatio.models.generic import WithBriefing
|
10
|
-
from fabricatio.models.kwargs_types import
|
10
|
+
from fabricatio.models.kwargs_types import ChooseKwargs, ValidateKwargs
|
11
11
|
from fabricatio.models.task import Task
|
12
12
|
from fabricatio.models.tool import Tool, ToolExecutor
|
13
13
|
from fabricatio.models.usages import LLMUsage, ToolBoxUsage
|
14
14
|
from fabricatio.parser import JsonCapture, PythonCapture
|
15
15
|
from loguru import logger
|
16
|
-
from pydantic import
|
16
|
+
from pydantic import NonNegativeInt, ValidationError
|
17
17
|
|
18
18
|
|
19
19
|
class ProposeTask(WithBriefing, LLMUsage):
|
@@ -22,14 +22,12 @@ class ProposeTask(WithBriefing, LLMUsage):
|
|
22
22
|
async def propose[T](
|
23
23
|
self,
|
24
24
|
prompt: str,
|
25
|
-
|
26
|
-
**kwargs: Unpack[LLMKwargs],
|
25
|
+
**kwargs: Unpack[ValidateKwargs],
|
27
26
|
) -> Task[T]:
|
28
27
|
"""Asynchronously proposes a task based on a given prompt and parameters.
|
29
28
|
|
30
29
|
Parameters:
|
31
30
|
prompt: The prompt text for proposing a task, which is a string that must be provided.
|
32
|
-
max_validations: The maximum number of validations allowed, default is 2.
|
33
31
|
**kwargs: The keyword arguments for the LLM (Large Language Model) usage.
|
34
32
|
|
35
33
|
Returns:
|
@@ -55,7 +53,6 @@ class ProposeTask(WithBriefing, LLMUsage):
|
|
55
53
|
question=template_manager.render_template(configs.templates.propose_task_template, template_data),
|
56
54
|
validator=_validate_json,
|
57
55
|
system_message=f"# your personal briefing: \n{self.briefing}",
|
58
|
-
max_validations=max_validations,
|
59
56
|
**kwargs,
|
60
57
|
)
|
61
58
|
|
@@ -68,7 +65,7 @@ class HandleTask(WithBriefing, ToolBoxUsage):
|
|
68
65
|
task: Task,
|
69
66
|
tools: List[Tool],
|
70
67
|
data: Dict[str, Any],
|
71
|
-
**kwargs: Unpack[
|
68
|
+
**kwargs: Unpack[ValidateKwargs],
|
72
69
|
) -> Tuple[CodeType, List[str]]:
|
73
70
|
"""Asynchronously drafts the tool usage code for a task based on a given task object and tools."""
|
74
71
|
logger.info(f"Drafting tool usage code for task: {task.briefing}")
|
@@ -109,12 +106,14 @@ class HandleTask(WithBriefing, ToolBoxUsage):
|
|
109
106
|
self,
|
110
107
|
task: Task,
|
111
108
|
data: Dict[str, Any],
|
112
|
-
|
109
|
+
box_choose_kwargs: Optional[ChooseKwargs] = None,
|
110
|
+
tool_choose_kwargs: Optional[ChooseKwargs] = None,
|
111
|
+
**kwargs: Unpack[ValidateKwargs],
|
113
112
|
) -> Optional[Tuple]:
|
114
113
|
"""Asynchronously handles a task based on a given task object and parameters."""
|
115
114
|
logger.info(f"Handling task: \n{task.briefing}")
|
116
115
|
|
117
|
-
tools = await self.
|
116
|
+
tools = await self.gather_tools_fine_grind(task, box_choose_kwargs, tool_choose_kwargs)
|
118
117
|
logger.info(f"{self.name} have gathered {[t.name for t in tools]}")
|
119
118
|
|
120
119
|
if tools:
|
@@ -126,3 +125,165 @@ class HandleTask(WithBriefing, ToolBoxUsage):
|
|
126
125
|
return tuple(cxt.get(k) for k in to_extract)
|
127
126
|
|
128
127
|
return None
|
128
|
+
|
129
|
+
async def handle(self, task: Task, data: Dict[str, Any], **kwargs: Unpack[ValidateKwargs]) -> Optional[Tuple]:
|
130
|
+
"""Asynchronously handles a task based on a given task object and parameters."""
|
131
|
+
return await self.handle_fin_grind(task, data, **kwargs)
|
132
|
+
|
133
|
+
|
134
|
+
class GiveRating(WithBriefing, LLMUsage):
|
135
|
+
"""A class that provides functionality to rate tasks based on a rating manual and score range."""
|
136
|
+
|
137
|
+
async def rate_fine_grind(
|
138
|
+
self,
|
139
|
+
to_rate: str,
|
140
|
+
rating_manual: Dict[str, str],
|
141
|
+
score_range: Tuple[float, float],
|
142
|
+
**kwargs: Unpack[ValidateKwargs],
|
143
|
+
) -> Dict[str, float]:
|
144
|
+
"""Rates a given task based on a rating manual and score range.
|
145
|
+
|
146
|
+
Args:
|
147
|
+
to_rate: The task to be rated.
|
148
|
+
rating_manual: A dictionary containing the rating criteria.
|
149
|
+
score_range: A tuple representing the valid score range.
|
150
|
+
**kwargs: Additional keyword arguments for the LLM usage.
|
151
|
+
|
152
|
+
Returns:
|
153
|
+
A dictionary with the ratings for each dimension.
|
154
|
+
"""
|
155
|
+
|
156
|
+
def _validator(response: str) -> Dict[str, float] | None:
|
157
|
+
if (
|
158
|
+
(json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
|
159
|
+
and isinstance(json_data, dict)
|
160
|
+
and json_data.keys() == rating_manual.keys()
|
161
|
+
and all(isinstance(v, float) for v in json_data.values())
|
162
|
+
and all(score_range[0] <= v <= score_range[1] for v in json_data.values())
|
163
|
+
):
|
164
|
+
return json_data
|
165
|
+
return None
|
166
|
+
|
167
|
+
return await self.aask_validate(
|
168
|
+
question=(
|
169
|
+
template_manager.render_template(
|
170
|
+
configs.templates.rate_fine_grind_template,
|
171
|
+
{
|
172
|
+
"to_rate": to_rate,
|
173
|
+
"min_score": score_range[0],
|
174
|
+
"max_score": score_range[1],
|
175
|
+
"rating_manual": rating_manual,
|
176
|
+
},
|
177
|
+
)
|
178
|
+
),
|
179
|
+
validator=_validator,
|
180
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
181
|
+
**kwargs,
|
182
|
+
)
|
183
|
+
|
184
|
+
async def rate(
|
185
|
+
self,
|
186
|
+
to_rate: str,
|
187
|
+
topic: str,
|
188
|
+
dimensions: Set[str],
|
189
|
+
score_range: Tuple[float, float] = (0.0, 1.0),
|
190
|
+
**kwargs: Unpack[ValidateKwargs],
|
191
|
+
) -> Dict[str, float]:
|
192
|
+
"""Rates a task based on a topic and dimensions. this function will automatically draft a rating manual based on the topic and dimensions.
|
193
|
+
|
194
|
+
Args:
|
195
|
+
to_rate: The task to be rated.
|
196
|
+
topic: The topic related to the task.
|
197
|
+
dimensions: A set of dimensions for rating.
|
198
|
+
score_range: A tuple representing the valid score range
|
199
|
+
**kwargs: Additional keyword arguments for the LLM usage.
|
200
|
+
|
201
|
+
Returns:
|
202
|
+
A dictionary with the ratings for each dimension.
|
203
|
+
"""
|
204
|
+
manual = await self.draft_rating_manual(topic, dimensions, **kwargs)
|
205
|
+
return await self.rate_fine_grind(to_rate, manual, score_range, **kwargs)
|
206
|
+
|
207
|
+
async def draft_rating_manual(
|
208
|
+
self, topic: str, dimensions: Set[str], **kwargs: Unpack[ValidateKwargs]
|
209
|
+
) -> Dict[str, str]:
|
210
|
+
"""Drafts a rating manual based on a topic and dimensions.
|
211
|
+
|
212
|
+
Args:
|
213
|
+
topic: The topic for the rating manual.
|
214
|
+
dimensions: A set of dimensions for the rating manual.
|
215
|
+
**kwargs: Additional keyword arguments for the LLM usage.
|
216
|
+
|
217
|
+
Returns:
|
218
|
+
A dictionary representing the drafted rating manual.
|
219
|
+
"""
|
220
|
+
|
221
|
+
def _validator(response: str) -> Dict[str, str] | None:
|
222
|
+
if (
|
223
|
+
(json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
|
224
|
+
and isinstance(json_data, dict)
|
225
|
+
and json_data.keys() == dimensions
|
226
|
+
and all(isinstance(v, str) for v in json_data.values())
|
227
|
+
):
|
228
|
+
return json_data
|
229
|
+
return None
|
230
|
+
|
231
|
+
return await self.aask_validate(
|
232
|
+
question=(
|
233
|
+
template_manager.render_template(
|
234
|
+
configs.templates.draft_rating_manual_template,
|
235
|
+
{
|
236
|
+
"topic": topic,
|
237
|
+
"dimensions": dimensions,
|
238
|
+
},
|
239
|
+
)
|
240
|
+
),
|
241
|
+
validator=_validator,
|
242
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
243
|
+
**kwargs,
|
244
|
+
)
|
245
|
+
|
246
|
+
async def draft_rating_dimensions(
|
247
|
+
self,
|
248
|
+
topic: str,
|
249
|
+
dimensions_count: NonNegativeInt = 0,
|
250
|
+
examples: Optional[List[str]] = None,
|
251
|
+
**kwargs: Unpack[ValidateKwargs],
|
252
|
+
) -> Set[str]:
|
253
|
+
"""Drafts rating dimensions based on a topic.
|
254
|
+
|
255
|
+
Args:
|
256
|
+
topic: The topic for the rating dimensions.
|
257
|
+
dimensions_count: The number of dimensions to draft, 0 means no limit.
|
258
|
+
examples: A list of examples which is rated based on the rating dimensions.
|
259
|
+
**kwargs: Additional keyword arguments for the LLM usage.
|
260
|
+
|
261
|
+
Returns:
|
262
|
+
A set of rating dimensions.
|
263
|
+
"""
|
264
|
+
|
265
|
+
def _validator(response: str) -> Set[str] | None:
|
266
|
+
if (
|
267
|
+
(json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
|
268
|
+
and isinstance(json_data, list)
|
269
|
+
and all(isinstance(v, str) for v in json_data)
|
270
|
+
and (dimensions_count == 0 or len(json_data) == dimensions_count)
|
271
|
+
):
|
272
|
+
return set(json_data)
|
273
|
+
return None
|
274
|
+
|
275
|
+
return await self.aask_validate(
|
276
|
+
question=(
|
277
|
+
template_manager.render_template(
|
278
|
+
configs.templates.draft_rating_dimensions_template,
|
279
|
+
{
|
280
|
+
"topic": topic,
|
281
|
+
"examples": examples,
|
282
|
+
"dimensions_count": dimensions_count,
|
283
|
+
},
|
284
|
+
)
|
285
|
+
),
|
286
|
+
validator=_validator,
|
287
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
288
|
+
**kwargs,
|
289
|
+
)
|
@@ -18,9 +18,14 @@ class LLMKwargs(TypedDict):
|
|
18
18
|
max_retries: NotRequired[PositiveInt]
|
19
19
|
|
20
20
|
|
21
|
-
class
|
22
|
-
"""A type representing the keyword arguments for the
|
21
|
+
class ValidateKwargs(LLMKwargs):
|
22
|
+
"""A type representing the keyword arguments for the validate method."""
|
23
23
|
|
24
24
|
max_validations: NotRequired[PositiveInt]
|
25
|
+
|
26
|
+
|
27
|
+
class ChooseKwargs(ValidateKwargs):
|
28
|
+
"""A type representing the keyword arguments for the choose method."""
|
29
|
+
|
25
30
|
system_message: NotRequired[str]
|
26
31
|
k: NotRequired[NonNegativeInt]
|
fabricatio/models/role.py
CHANGED
@@ -5,14 +5,13 @@ from typing import Any, Self, Set
|
|
5
5
|
from fabricatio.core import env
|
6
6
|
from fabricatio.journal import logger
|
7
7
|
from fabricatio.models.action import WorkFlow
|
8
|
-
from fabricatio.models.advanced import ProposeTask
|
8
|
+
from fabricatio.models.advanced import GiveRating, HandleTask, ProposeTask
|
9
9
|
from fabricatio.models.events import Event
|
10
10
|
from fabricatio.models.tool import ToolBox
|
11
|
-
from fabricatio.models.usages import ToolBoxUsage
|
12
11
|
from pydantic import Field
|
13
12
|
|
14
13
|
|
15
|
-
class Role(ProposeTask,
|
14
|
+
class Role(ProposeTask, HandleTask, GiveRating):
|
16
15
|
"""Class that represents a role with a registry of events and workflows."""
|
17
16
|
|
18
17
|
registry: dict[Event | str, WorkFlow] = Field(...)
|
fabricatio/models/task.py
CHANGED
@@ -57,6 +57,9 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
|
57
57
|
namespace: List[str] = Field(default_factory=list)
|
58
58
|
"""The namespace of the task, a list of namespace segment, as string."""
|
59
59
|
|
60
|
+
dependencies: List[str] = Field(default_factory=list)
|
61
|
+
"""A list of file paths, These file are needed to read or write to meet a specific requirement of this task."""
|
62
|
+
|
60
63
|
_output: Queue = PrivateAttr(default_factory=lambda: Queue(maxsize=1))
|
61
64
|
"""The output queue of the task."""
|
62
65
|
|
Binary file
|
@@ -1,23 +1,23 @@
|
|
1
|
-
fabricatio-0.2.1.
|
2
|
-
fabricatio-0.2.1.
|
3
|
-
fabricatio-0.2.1.
|
1
|
+
fabricatio-0.2.1.dev3.dist-info/METADATA,sha256=OwlHmlzaQ2C89QQVzGZUKNkNHKb6rAjeAFRShKYSfkM,12351
|
2
|
+
fabricatio-0.2.1.dev3.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
|
3
|
+
fabricatio-0.2.1.dev3.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
|
4
4
|
fabricatio/actions/communication.py,sha256=NZxIIncKgJSDyBrqNebUtH_haqtxHa8ld2TZxT3CMdU,429
|
5
5
|
fabricatio/actions/transmission.py,sha256=xpvKqbXqgpi1BWy-vUUvmd8NZ1GhRNfsYUBp-l2jLyk,862
|
6
6
|
fabricatio/actions/__init__.py,sha256=eFmFVPQvtNgFynIXBVr3eP-vWQDWCPng60YY5LXvZgg,115
|
7
|
-
fabricatio/config.py,sha256=
|
7
|
+
fabricatio/config.py,sha256=qHPChDvzoclDLuaykHr8qlJq1zE3RjU6jObSNe11C1Y,10822
|
8
8
|
fabricatio/core.py,sha256=yQK2ZrbPYDJOaNDp0Bky3muTkB-ZaQ1ld_Qfflm2dY0,5938
|
9
9
|
fabricatio/decorators.py,sha256=uzsP4tFKQNjDHBkofsjjoJA0IUAaYOtt6YVedoyOqlo,6551
|
10
10
|
fabricatio/fs/curd.py,sha256=faMstgGUiQ4k2AW3OXfvvWWTldTtKXco7QINYaMjmyA,3981
|
11
11
|
fabricatio/fs/readers.py,sha256=Pz1-cdZYtmqr032dsroImlkFXAd0kCYY_9qVpD4UrG4,1045
|
12
12
|
fabricatio/fs/__init__.py,sha256=lWcKYg0v3mv2LnnSegOQaTtlVDODU0vtw_s6iKU5IqQ,122
|
13
13
|
fabricatio/journal.py,sha256=siqimKF0M_QaaOCMxtjr_BJVNyUIAQWILzE9Q4T6-7c,781
|
14
|
-
fabricatio/models/action.py,sha256=
|
15
|
-
fabricatio/models/advanced.py,sha256=
|
14
|
+
fabricatio/models/action.py,sha256=VenovcZyR_ibwEy5Jpr4EaNP1L0hRqAjW0IhQNLdpNE,5676
|
15
|
+
fabricatio/models/advanced.py,sha256=xVzHqoO1glNdCqflKZF5FGkK5GQmfIMZpT_07zQi9KM,11420
|
16
16
|
fabricatio/models/events.py,sha256=mrihNEFgQ5o7qFWja1z_qX8dnaTLwPBoJdVlzxQV5oM,2719
|
17
17
|
fabricatio/models/generic.py,sha256=WEjZ96rTyBjaBjkM6e8E4Pg_Naot4xWRvGJteqBiCCI,5133
|
18
|
-
fabricatio/models/kwargs_types.py,sha256=
|
19
|
-
fabricatio/models/role.py,sha256=
|
20
|
-
fabricatio/models/task.py,sha256=
|
18
|
+
fabricatio/models/kwargs_types.py,sha256=sVEkaeujQDNnQzTlisnjjVjrqS2g_wa4ROVbD86nHCE,1024
|
19
|
+
fabricatio/models/role.py,sha256=h_0NIKvPbmRam4jsZOCGOMaje4gy5jYjTMpM39oTaYI,1785
|
20
|
+
fabricatio/models/task.py,sha256=It4pUoaNIIC4Jw66KOG07Vp0bumCJZQo61KnR7HoGzM,9435
|
21
21
|
fabricatio/models/tool.py,sha256=WTFnpF6xZ1nJbmIOonLsGQcM-kkDCeZiAFqyil9xg2U,6988
|
22
22
|
fabricatio/models/usages.py,sha256=6qoh9w1xeC-olkQjiH1oZYgqxohp0GX4dwOmSrhMn0E,25756
|
23
23
|
fabricatio/models/utils.py,sha256=i_kpcQpct04mQFk1nbcVGV-pl1YThWu4Qk3wbewzKkc,2535
|
@@ -30,6 +30,6 @@ fabricatio/toolboxes/__init__.py,sha256=b13KmASO8q5fBLwew964fn9oH86ER5g-S1PgA4fZ
|
|
30
30
|
fabricatio/_rust.pyi,sha256=0wCqtwWkVxxoqprvk8T27T8QYKIAKHS7xgsmdMNjQKc,1756
|
31
31
|
fabricatio/_rust_instances.py,sha256=dl0-yZ4UvT5g20tQgnPJpmqtkjFGXNG_YK4eLfi_ugQ,279
|
32
32
|
fabricatio/__init__.py,sha256=opIrN8lGyT-h2If4Qez0bRuWBa3uIT9GsM9CZy7_XJ0,1100
|
33
|
-
fabricatio/_rust.cp312-win_amd64.pyd,sha256=
|
34
|
-
fabricatio-0.2.1.
|
35
|
-
fabricatio-0.2.1.
|
33
|
+
fabricatio/_rust.cp312-win_amd64.pyd,sha256=p9QIx4phvmlr_ae1700OGjD1tVJRvkRCe9mWy_T4Z4U,1261056
|
34
|
+
fabricatio-0.2.1.dev3.data/scripts/tdown.exe,sha256=-jC9BrzFlXOyBsw3O3T4XTMqirtLGPXPtOE1gE4uh3M,3397120
|
35
|
+
fabricatio-0.2.1.dev3.dist-info/RECORD,,
|
Binary file
|
File without changes
|
File without changes
|