fabricatio 0.2.1.dev4__cp312-cp312-win_amd64.whl → 0.2.2__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.
Binary file
@@ -12,7 +12,7 @@ from fabricatio.models.generic import WithBriefing
12
12
  from fabricatio.models.kwargs_types import GenerateKwargs, ValidateKwargs
13
13
  from fabricatio.models.usages import LLMUsage
14
14
  from fabricatio.parser import JsonCapture
15
- from more_itertools import flatten
15
+ from more_itertools import flatten, windowed
16
16
  from pydantic import NonNegativeInt, PositiveInt
17
17
 
18
18
 
@@ -275,3 +275,81 @@ class GiveRating(WithBriefing, LLMUsage):
275
275
  validator=_criteria_validator,
276
276
  **kwargs,
277
277
  )
278
+
279
+ async def drafting_rating_weights_klee(
280
+ self,
281
+ topic: str,
282
+ criteria: Set[str],
283
+ **kwargs: Unpack[ValidateKwargs],
284
+ ) -> Dict[str, float]:
285
+ """Drafts rating weights for a given topic and criteria using the Klee method.
286
+
287
+ Args:
288
+ topic (str): The topic for the rating weights.
289
+ criteria (Set[str]): A set of criteria for the rating weights.
290
+ **kwargs (Unpack[ValidateKwargs]): Additional keyword arguments for the LLM usage.
291
+
292
+ Returns:
293
+ Dict[str, float]: A dictionary representing the drafted rating weights for each criterion.
294
+ """
295
+ if len(criteria) < 2: # noqa: PLR2004
296
+ raise ValueError("At least two criteria are required to draft rating weights")
297
+
298
+ def _validator(resp: str) -> float | None:
299
+ if (cap := JsonCapture.convert_with(resp, orjson.loads)) is not None and isinstance(cap, float):
300
+ return cap
301
+ return None
302
+
303
+ criteria = list(criteria) # freeze the order
304
+ windows = windowed(criteria, 2)
305
+
306
+ # get the importance multiplier indicating how important is second criterion compared to the first one
307
+ relative_weights = await self.aask_validate_batch(
308
+ questions=[
309
+ template_manager.render_template(
310
+ configs.templates.draft_rating_weights_klee_template,
311
+ {
312
+ "topic": topic,
313
+ "first": pair[0],
314
+ "second": pair[1],
315
+ },
316
+ )
317
+ for pair in windows
318
+ ],
319
+ validator=_validator,
320
+ **GenerateKwargs(system_message=f"# your personal briefing: \n{self.briefing}", **kwargs),
321
+ )
322
+ weights = [1]
323
+ for rw in relative_weights:
324
+ weights.append(weights[-1] * rw)
325
+ total = sum(weights)
326
+ return dict(zip(criteria, [w / total for w in weights], strict=True))
327
+
328
+ async def composite_score(
329
+ self,
330
+ topic: str,
331
+ to_rate: List[str],
332
+ reasons_count: PositiveInt = 2,
333
+ criteria_count: PositiveInt = 5,
334
+ **kwargs: Unpack[ValidateKwargs],
335
+ ) -> List[float]:
336
+ """Calculates the composite scores for a list of items based on a given topic and criteria.
337
+
338
+ Args:
339
+ topic (str): The topic for the rating.
340
+ to_rate (List[str]): A list of strings to be rated.
341
+ reasons_count (PositiveInt, optional): The number of reasons to extract from each pair of examples. Defaults to 2.
342
+ criteria_count (PositiveInt, optional): The number of criteria to draft. Defaults to 5.
343
+ **kwargs (Unpack[ValidateKwargs]): Additional keyword arguments for the LLM usage.
344
+
345
+ Returns:
346
+ List[float]: A list of composite scores for the items.
347
+ """
348
+ criteria = await self.draft_rating_criteria_from_examples(
349
+ topic, to_rate, reasons_count, criteria_count, **kwargs
350
+ )
351
+ weights = await self.drafting_rating_weights_klee(topic, criteria, **kwargs)
352
+ logger.info(f"Criteria: {criteria}\nWeights: {weights}")
353
+ ratings_seq = await self.rate(to_rate, topic, criteria, **kwargs)
354
+
355
+ return [sum(ratings[c] * weights[c] for c in criteria) for ratings in ratings_seq]
fabricatio/config.py CHANGED
@@ -172,6 +172,9 @@ class TemplateConfig(BaseModel):
172
172
  extract_criteria_from_reasons_template: str = Field(default="extract_criteria_from_reasons")
173
173
  """The name of the extract criteria from reasons template which will be used to extract criteria from reasons."""
174
174
 
175
+ draft_rating_weights_klee_template: str = Field(default="draft_rating_weights_klee")
176
+ """The name of the draft rating weights klee template which will be used to draft rating weights with Klee method."""
177
+
175
178
 
176
179
  class MagikaConfig(BaseModel):
177
180
  """Magika configuration class."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.1.dev4
3
+ Version: 0.2.2
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,12 +1,12 @@
1
- fabricatio-0.2.1.dev4.dist-info/METADATA,sha256=SBDI22unUkO_lKW7mxoSTy0IHsbXYGTtOOJJvfDiFJw,12339
2
- fabricatio-0.2.1.dev4.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
- fabricatio-0.2.1.dev4.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
1
+ fabricatio-0.2.2.dist-info/METADATA,sha256=Xnkw59IiSN4arPkzglC1JKpJACZlGkjbr5raJLdrmb8,12334
2
+ fabricatio-0.2.2.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
+ fabricatio-0.2.2.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/capabilities/rating.py,sha256=9GjlANrLs6Wg8VS4Q60qAD8ASlL4PONSBxe6mZs22FY,11470
7
+ fabricatio/capabilities/rating.py,sha256=zmTUvsUfxFgovRQzy4djL2zKRYTHmN6JY7A4lyT5uVQ,14907
8
8
  fabricatio/capabilities/task.py,sha256=d2xtrwQxXWI40UskQCR5YhHarY7ST0ppr8TjY12uWQE,5327
9
- fabricatio/config.py,sha256=uzuAezdC7U4eMQoVlMErjDfuzYW9WQZZuUzS660J48A,11252
9
+ fabricatio/config.py,sha256=wzaaUHZZMRCYc37M_M4qKuLOYtwdEjYtyG77-AGkqCg,11467
10
10
  fabricatio/core.py,sha256=yQK2ZrbPYDJOaNDp0Bky3muTkB-ZaQ1ld_Qfflm2dY0,5938
11
11
  fabricatio/decorators.py,sha256=uzsP4tFKQNjDHBkofsjjoJA0IUAaYOtt6YVedoyOqlo,6551
12
12
  fabricatio/fs/curd.py,sha256=faMstgGUiQ4k2AW3OXfvvWWTldTtKXco7QINYaMjmyA,3981
@@ -31,6 +31,6 @@ fabricatio/toolboxes/__init__.py,sha256=b13KmASO8q5fBLwew964fn9oH86ER5g-S1PgA4fZ
31
31
  fabricatio/_rust.pyi,sha256=0wCqtwWkVxxoqprvk8T27T8QYKIAKHS7xgsmdMNjQKc,1756
32
32
  fabricatio/_rust_instances.py,sha256=dl0-yZ4UvT5g20tQgnPJpmqtkjFGXNG_YK4eLfi_ugQ,279
33
33
  fabricatio/__init__.py,sha256=opIrN8lGyT-h2If4Qez0bRuWBa3uIT9GsM9CZy7_XJ0,1100
34
- fabricatio/_rust.cp312-win_amd64.pyd,sha256=rVDkEhNlZd9HcwAXEu5fYPS75LL0JKYyd0RcSoqxAwg,1262080
35
- fabricatio-0.2.1.dev4.data/scripts/tdown.exe,sha256=HZaFnRZcdp6sMliJZDCRtbfQXsDNjTDTx9cmhNCYpXA,3396608
36
- fabricatio-0.2.1.dev4.dist-info/RECORD,,
34
+ fabricatio/_rust.cp312-win_amd64.pyd,sha256=4hsd6r-pYsSUSW2cSq9Ik-SSTYVXacEYygliOFx2sfk,1262080
35
+ fabricatio-0.2.2.data/scripts/tdown.exe,sha256=T_R2-mppH1q8T8LtZdR_pa7QNrdVfrC2nRQuWgalpqQ,3396608
36
+ fabricatio-0.2.2.dist-info/RECORD,,