fabricatio 0.2.1.dev1__cp312-cp312-manylinux_2_34_x86_64.whl → 0.2.1.dev3__cp312-cp312-manylinux_2_34_x86_64.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/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)
@@ -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="")
@@ -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 LLMKwargs
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 PositiveInt, ValidationError
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
- max_validations: PositiveInt = 2,
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[LLMKwargs],
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
- **kwargs: Unpack[LLMKwargs],
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.gather_tools(task)
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 ChooseKwargs(LLMKwargs):
22
- """A type representing the keyword arguments for the choose method."""
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, ToolBoxUsage):
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.1.dev1
3
+ Version: 0.2.1.dev3
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,6 +1,6 @@
1
- fabricatio-0.2.1.dev1.dist-info/METADATA,sha256=_O09SWlzb0GQzgGetoZTN2L3YxDOlOQf9F4nhRA3i7M,11972
2
- fabricatio-0.2.1.dev1.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
3
- fabricatio-0.2.1.dev1.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
1
+ fabricatio-0.2.1.dev3.dist-info/METADATA,sha256=HKe_w2CDh9Def3QfL-Hc5PFor_oplxEQZXKZ34E1h3E,11972
2
+ fabricatio-0.2.1.dev3.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
3
+ fabricatio-0.2.1.dev3.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
4
4
  fabricatio/fs/__init__.py,sha256=bYE9r8uR0dtknzbg_YaGv_6Wwa27ntkQt0Tl7Kb3HFI,117
5
5
  fabricatio/fs/readers.py,sha256=lqMrM5Nt3l6QJmPDoBno2PSaN2BbFwfUjBqaghrbK3A,1002
6
6
  fabricatio/fs/curd.py,sha256=g74Pc2WPSkPlCXX0cWj2jyiDYTfkLwpwM480eyCkmc8,3851
@@ -10,19 +10,19 @@ fabricatio/toolboxes/task.py,sha256=9J3W-48CCEUh5PFz0XEC47Hv23Ugn1BEg-J_woQE1UA,
10
10
  fabricatio/toolboxes/arithmetic.py,sha256=sSTPkKI6-mb278DwQKFO9jKyzc9kCx45xNH7V6bGBpE,1307
11
11
  fabricatio/__init__.py,sha256=h0FgwSAdI2yhxYiuQi46uFvzqkK5LfJLt5XsHZ9rWIo,1063
12
12
  fabricatio/core.py,sha256=apwXgI94DCWpGujGlsmXsTZQvJOQMB9llmuUo7ohd-4,5771
13
- fabricatio/config.py,sha256=qpqqB38LivPEqkEdnTRswKSR4pVi-lsJb-Ohz3hqjcE,9997
13
+ fabricatio/config.py,sha256=M8VinyP4crwRYFcaTKekeOEOY4H03FbutpdfIU72moc,10549
14
14
  fabricatio/decorators.py,sha256=cJHsxxbnMhc4SzPl4454CPLuDP3H0qbTrzV_U2rLPrs,6372
15
15
  fabricatio/journal.py,sha256=bzxZay48ZWI0VIkkDXm4Wc_Cc9lBQYa2VGx3Hxy_PtA,753
16
16
  fabricatio/models/generic.py,sha256=4j6DRNkHLNhx8U6aijf0Cz9HSahtEPQBh22i6d_PGTs,4981
17
- fabricatio/models/kwargs_types.py,sha256=INQIZiCOfGVkRbPmUMp-ZYtSkPwZmgFowid-D3A3TpE,875
18
- fabricatio/models/action.py,sha256=Kjq0ozqgPjHK0tP61k0yhrSZBxzE9m68MJCWZUUgh1c,5513
19
- fabricatio/models/task.py,sha256=0HXaf8Ig47UeMBN7n3iUp0oyOvN6-DlKxQForHnt8RI,8981
20
- fabricatio/models/role.py,sha256=TT_SxC1M8IawVA72BRI3h3KrK3XMb88UV7F897PuKyU,1754
17
+ fabricatio/models/kwargs_types.py,sha256=9LbvozHzlBijGjefWQEZZO4BrwcXjRcgtsRn_L4A768,993
18
+ fabricatio/models/action.py,sha256=ks7gWEMUT0p6Yrv8QAMj6x7lfOqaJt5xp_sc52ssh7I,5537
19
+ fabricatio/models/task.py,sha256=X2-Nivi_lG5j5u-I_ZqAY1mmDVCfHxQZK4-pQd0f5UM,9156
20
+ fabricatio/models/role.py,sha256=5hc11wF9hdiNHAhv3BirsbGPd-2GloaKZuJNnvs7g1s,1738
21
21
  fabricatio/models/tool.py,sha256=wgNXtobDSWZTVmIrSSaS5oyxhSUYWXhS0S2o9acE2ls,6800
22
22
  fabricatio/models/events.py,sha256=TkMSJYSzRgurbfY2knWIc8gYw7rmaWqB7KeYzy5jeWU,2637
23
23
  fabricatio/models/utils.py,sha256=u-eR_v-o0BSFSmCprP3mOyAO-WOyg_P68jjzLjyit_w,2457
24
24
  fabricatio/models/usages.py,sha256=xpUF6luEiQUyAvjc6xBdXwA5gZHGckPsT-g-49McwIg,25185
25
- fabricatio/models/advanced.py,sha256=RzQE4fsN1uuEgG43Ym_C2N5gZI-9keGYzkaXE4hYGws,4899
25
+ fabricatio/models/advanced.py,sha256=WCgz0RuWtS_GW1v7kvArL8VoBT3NMSLvKe924A0O7uQ,11131
26
26
  fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  fabricatio/_rust_instances.py,sha256=JAtO-vL8ihvduf1SHLNf0w7ZSVGCJeIv6zZ9Ekyy1hY,271
28
28
  fabricatio/actions/__init__.py,sha256=eLa_5ACZ-FqdrLtOfCHk5nQBxzhIs1kgMIXWmkm2P8Y,110
@@ -30,6 +30,6 @@ fabricatio/actions/communication.py,sha256=MrL_revv1zm1VXqjDMKZkg4PHmyMxYThAmmw2
30
30
  fabricatio/actions/transmission.py,sha256=WM-kssiqzTLZuZSiqbRvBaC2qynd9kjrKXya4f9Zcb0,839
31
31
  fabricatio/_rust.pyi,sha256=clhcURuiB9zlFo4m3VyoWQ8Xs4tvg6KNHXpF-ok9h4o,1703
32
32
  fabricatio/parser.py,sha256=Q4laV79Svggl09UKa3lAw6NYPuDz1sP2F-6U4tsSvQw,3429
33
- fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=QbhnJVpJF98TxjmOERX1yujuxipSkTEdS-U-uLVeF6E,1339504
34
- fabricatio-0.2.1.dev1.data/scripts/tdown,sha256=zC9af9TkkwUb7kbwHqOdjVevGf9XY36tW5j5kGEP6gY,4570976
35
- fabricatio-0.2.1.dev1.dist-info/RECORD,,
33
+ fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=wyOQQQjki23ZQn48Lpv9_7NtIrbYBqX7MIS1z6NR6LY,1340176
34
+ fabricatio-0.2.1.dev3.data/scripts/tdown,sha256=R0aC5Ur-Z8wjsaa8m2S2Q88Pa-5on2f8gnWpSrNV1SA,4571336
35
+ fabricatio-0.2.1.dev3.dist-info/RECORD,,