fabricatio 0.2.1.dev1__cp312-cp312-win_amd64.whl → 0.2.1.dev2__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 +7 -0
- fabricatio/models/advanced.py +126 -10
- fabricatio/models/kwargs_types.py +7 -2
- fabricatio-0.2.1.dev2.data/scripts/tdown.exe +0 -0
- {fabricatio-0.2.1.dev1.dist-info → fabricatio-0.2.1.dev2.dist-info}/METADATA +1 -1
- {fabricatio-0.2.1.dev1.dist-info → fabricatio-0.2.1.dev2.dist-info}/RECORD +9 -9
- fabricatio-0.2.1.dev1.data/scripts/tdown.exe +0 -0
- {fabricatio-0.2.1.dev1.dist-info → fabricatio-0.2.1.dev2.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.1.dev1.dist-info → fabricatio-0.2.1.dev2.dist-info}/licenses/LICENSE +0 -0
Binary file
|
fabricatio/config.py
CHANGED
@@ -157,6 +157,12 @@ 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
|
+
|
160
166
|
|
161
167
|
class MagikaConfig(BaseModel):
|
162
168
|
"""Magika configuration class."""
|
@@ -208,6 +214,7 @@ class Settings(BaseSettings):
|
|
208
214
|
toml_file=["fabricatio.toml", rf"{ROAMING_DIR}\fabricatio.toml"],
|
209
215
|
env_file=[".env", ".envrc"],
|
210
216
|
use_attribute_docstrings=True,
|
217
|
+
extra="ignore",
|
211
218
|
)
|
212
219
|
|
213
220
|
llm: LLMConfig = Field(default_factory=LLMConfig)
|
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 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,120 @@ 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
|
+
)
|
@@ -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]
|
Binary file
|
@@ -1,10 +1,10 @@
|
|
1
|
-
fabricatio-0.2.1.
|
2
|
-
fabricatio-0.2.1.
|
3
|
-
fabricatio-0.2.1.
|
1
|
+
fabricatio-0.2.1.dev2.dist-info/METADATA,sha256=jNZzL0ClVEXeLkJFlLjaTo9sRHoG27EISI0JmMOqqaE,12351
|
2
|
+
fabricatio-0.2.1.dev2.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
|
3
|
+
fabricatio-0.2.1.dev2.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=hDYLpxn3ZrRjoSEGXGfC8s0URpebZyLHD45jU1UJOVo,10627
|
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
|
@@ -12,10 +12,10 @@ 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
14
|
fabricatio/models/action.py,sha256=1V3upL79e3ekyGXA4bSY70N60yeL0aWak7ZPBVsFE3A,5652
|
15
|
-
fabricatio/models/advanced.py,sha256=
|
15
|
+
fabricatio/models/advanced.py,sha256=YknnBR89nFosHjbD9moyXm8vWx4uD57zUgtvRfKALLc,9704
|
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=
|
18
|
+
fabricatio/models/kwargs_types.py,sha256=sVEkaeujQDNnQzTlisnjjVjrqS2g_wa4ROVbD86nHCE,1024
|
19
19
|
fabricatio/models/role.py,sha256=RPdOcjmM6KNyH310Vx4524JQG94P5sXl_3doSrRpiKQ,1802
|
20
20
|
fabricatio/models/task.py,sha256=hogTBx74IAKfKDWghhWFR7i-LVQAn7L9PQM5tyOA5Rk,9257
|
21
21
|
fabricatio/models/tool.py,sha256=WTFnpF6xZ1nJbmIOonLsGQcM-kkDCeZiAFqyil9xg2U,6988
|
@@ -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=apS92eztfWPO-xRlnon15y0Pq7qPT1nRn652Pd2RBRw,1261056
|
34
|
+
fabricatio-0.2.1.dev2.data/scripts/tdown.exe,sha256=f7ZxXFNyP5_SiScZWZcdWE0FJbTX7l4AAKZov5XpDHk,3397120
|
35
|
+
fabricatio-0.2.1.dev2.dist-info/RECORD,,
|
Binary file
|
File without changes
|
File without changes
|