fabricatio 0.2.8.dev3__cp312-cp312-win_amd64.whl → 0.2.8.dev4__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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  import traceback
4
4
  from asyncio import gather
5
- from typing import Callable, Dict, Iterable, List, Optional, Self, Sequence, Set, Type, Union, Unpack, overload
5
+ from typing import Callable, Dict, Iterable, List, Optional, Self, Sequence, Set, Union, Unpack, overload
6
6
 
7
7
  import asyncstdlib
8
8
  import litellm
@@ -53,10 +53,6 @@ class LLMUsage(ScopedConfig):
53
53
  self._added_deployment = ROUTER.upsert_deployment(deployment)
54
54
  return ROUTER
55
55
 
56
- @classmethod
57
- def _scoped_model(cls) -> Type["LLMUsage"]:
58
- return LLMUsage
59
-
60
56
  # noinspection PyTypeChecker,PydanticTypeChecker
61
57
  async def aquery(
62
58
  self,
@@ -303,12 +299,11 @@ class LLMUsage(ScopedConfig):
303
299
  async def _inner(q: str) -> Optional[T]:
304
300
  for lap in range(max_validations):
305
301
  try:
306
- if (
307
- (response := await self.aask(question=q, **kwargs))
308
- or (
309
- co_extractor
310
- and (
311
- response := await self.aask(
302
+ if ((validated := validator(response := await self.aask(question=q, **kwargs))) is not None) or (
303
+ co_extractor
304
+ and (
305
+ validated := validator(
306
+ await self.aask(
312
307
  question=(
313
308
  TEMPLATE_MANAGER.render_template(
314
309
  configs.templates.co_validation_template,
@@ -319,7 +314,8 @@ class LLMUsage(ScopedConfig):
319
314
  )
320
315
  )
321
316
  )
322
- ) and (validated := validator(response)):
317
+ is not None
318
+ ):
323
319
  logger.debug(f"Successfully validated the response at {lap}th attempt.")
324
320
  return validated
325
321
 
@@ -361,7 +357,6 @@ class LLMUsage(ScopedConfig):
361
357
  **kwargs,
362
358
  )
363
359
 
364
-
365
360
  async def apathstr(self, requirement: str, **kwargs: Unpack[ChooseKwargs[List[str]]]) -> Optional[List[str]]:
366
361
  """Asynchronously generates a list of strings based on a given requirement.
367
362
 
@@ -552,7 +547,7 @@ class EmbeddingUsage(LLMUsage):
552
547
  """
553
548
  # check seq length
554
549
  max_len = self.embedding_max_sequence_length or configs.embedding.max_sequence_length
555
- if max_len and any(length:=(token_counter(text=t)) > max_len for t in input_text):
550
+ if max_len and any(length := (token_counter(text=t)) > max_len for t in input_text):
556
551
  logger.error(err := f"Input text exceeds maximum sequence length {max_len}, got {length}.")
557
552
  raise ValueError(err)
558
553
 
@@ -714,7 +709,7 @@ class ToolBoxUsage(LLMUsage):
714
709
  """
715
710
  if isinstance(others, ToolBoxUsage):
716
711
  others = [others]
717
- for other in others:
712
+ for other in (x for x in others if isinstance(x, ToolBoxUsage)):
718
713
  self.toolboxes.update(other.toolboxes)
719
714
  return self
720
715
 
@@ -730,6 +725,6 @@ class ToolBoxUsage(LLMUsage):
730
725
  """
731
726
  if isinstance(others, ToolBoxUsage):
732
727
  others = [others]
733
- for other in others:
728
+ for other in (x for x in others if isinstance(x, ToolBoxUsage)):
734
729
  other.toolboxes.update(self.toolboxes)
735
730
  return self
fabricatio/parser.py CHANGED
@@ -45,14 +45,14 @@ class Capture(BaseModel):
45
45
  str | List[str]: The fixed text with the same type as input.
46
46
  """
47
47
  match self.capture_type:
48
- case "json":
48
+ case "json" if configs.general.use_json_repair:
49
+ logger.debug("Applying json repair to text.")
49
50
  if isinstance(text, str):
50
51
  return repair_json(text, ensure_ascii=False)
51
52
  return [repair_json(item, ensure_ascii=False) for item in text]
52
53
  case _:
53
54
  return text
54
55
 
55
-
56
56
  def capture(self, text: str) -> Tuple[str, ...] | str | None:
57
57
  """Capture the first occurrence of the pattern in the given text.
58
58
 
@@ -63,11 +63,10 @@ class Capture(BaseModel):
63
63
  str | None: The captured text if the pattern is found, otherwise None.
64
64
 
65
65
  """
66
- match = self._compiled.search(text)
67
- if match is None:
68
- logger.debug(f"Capture Failed: \n{text}")
66
+ if (match :=self._compiled.match(text) or self._compiled.search(text) ) is None:
67
+ logger.debug(f"Capture Failed {type(text)}: \n{text}")
69
68
  return None
70
- groups = self.fix(match.groups()) if configs.general.use_json_repair else match.groups()
69
+ groups = self.fix(match.groups())
71
70
  if self.target_groups:
72
71
  cap = tuple(groups[g - 1] for g in self.target_groups)
73
72
  logger.debug(f"Captured text: {'\n\n'.join(cap)}")
@@ -134,7 +133,7 @@ class Capture(BaseModel):
134
133
  Returns:
135
134
  Self: The instance of the class with the captured code block.
136
135
  """
137
- return cls(pattern=f"```{language}\n(.*?)\n```", capture_type=language)
136
+ return cls(pattern=f"```{language}(.*?)```", capture_type=language)
138
137
 
139
138
  @classmethod
140
139
  def capture_generic_block(cls, language: str) -> Self:
@@ -143,7 +142,7 @@ class Capture(BaseModel):
143
142
  Returns:
144
143
  Self: The instance of the class with the captured code block.
145
144
  """
146
- return cls(pattern=f"--- Start of {language} ---\n(.*?)\n--- end of {language} ---", capture_type=language)
145
+ return cls(pattern=f"--- Start of {language} ---(.*?)--- end of {language} ---", capture_type=language)
147
146
 
148
147
 
149
148
  JsonCapture = Capture.capture_code_block("json")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.8.dev3
3
+ Version: 0.2.8.dev4
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,43 +1,46 @@
1
- fabricatio-0.2.8.dev3.dist-info/METADATA,sha256=dd-agw0ROR-UiBU9QvouJoQ2GCWKGev24EU51ddF1kc,5288
2
- fabricatio-0.2.8.dev3.dist-info/WHEEL,sha256=jABKVkLC9kJr8mi_er5jOqpiQUjARSLXDUIIxDqsS50,96
3
- fabricatio-0.2.8.dev3.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
4
- fabricatio/actions/article.py,sha256=cvUoP6a1iQklOmwPeBskJE6L5NdmF99rQEVvXOV-uR0,13733
5
- fabricatio/actions/article_rag.py,sha256=-nFpxn2Qg1MQE6yS97P_wnSrGxJWQWlz05OX3Cdr4XE,3852
1
+ fabricatio-0.2.8.dev4.dist-info/METADATA,sha256=m8008QWQ2qtSzryx4jr2DpTqfNQDyhBUscJQgQzmM0I,5288
2
+ fabricatio-0.2.8.dev4.dist-info/WHEEL,sha256=jABKVkLC9kJr8mi_er5jOqpiQUjARSLXDUIIxDqsS50,96
3
+ fabricatio-0.2.8.dev4.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
4
+ fabricatio/actions/article.py,sha256=i5-u5tCiJd7b_lQ4_vHjV57ZXDoUIAHmgD9QFoFaTuM,12787
5
+ fabricatio/actions/article_rag.py,sha256=dkfskNqntVPi81Xm_NFdTQM8v2nR9FJIexzkK9rg-NU,4352
6
6
  fabricatio/actions/output.py,sha256=-FfTzXEHIb_zOT-j4T4b5ND96zHLDEGdjlmmPviIbiM,3754
7
7
  fabricatio/actions/rag.py,sha256=wb3vt-gS6fDHYJ57Yfu_OR0kpewT9vMqwtXsqXd42Kg,2735
8
8
  fabricatio/capabilities/advanced_judge.py,sha256=selB0Gwf1F4gGJlwBiRo6gI4KOUROgh3WnzO3mZFEls,706
9
- fabricatio/capabilities/check.py,sha256=XiA03x2lGcCzpTVICOHs-e7qzNODQwBwtjDxU8ucgdM,3915
10
- fabricatio/capabilities/correct.py,sha256=55Zk1AzeQfoD-8k58VruGUxAMQR7q68ffGniCu6aogM,7282
9
+ fabricatio/capabilities/censor.py,sha256=-FZTDFfqlIwqMd4hkKzEHAknlp2pH5sawXDQ-7XJcXA,3784
10
+ fabricatio/capabilities/check.py,sha256=_4FS0kTa37A3M8Cjl1oVxp1j971W5O58NxmtsU1TizA,8005
11
+ fabricatio/capabilities/correct.py,sha256=8ax8oa9e4EIzho-cTXku-Sy7rC1zrOdlo23ooDZEyuM,9178
11
12
  fabricatio/capabilities/propose.py,sha256=hkBeSlmcTdfYWT-ph6nlbtHXBozi_JXqXlWcnBy3W78,2007
12
13
  fabricatio/capabilities/rag.py,sha256=7xDxDEvhlmb7Y-mEquSgvlVIYpHsM2YFxA9LjRpVajo,17720
13
- fabricatio/capabilities/rating.py,sha256=_PCJUeNA_1hwcP37r1GsWfHt6Gpwf8TuaAlKajUiyK8,14693
14
+ fabricatio/capabilities/rating.py,sha256=3gBqmYpEpzKge4mpxclJ4f9Nl_MTnADjuj4uqxw2Ilo,17011
14
15
  fabricatio/capabilities/review.py,sha256=1MGyJudPxHVOQod_GYKJ7NyB3jOWuwZhqBP30hAZ5Z4,5061
15
16
  fabricatio/capabilities/task.py,sha256=JG9kD2n86FvZQIjqZq-aqw8j9jpuuDpEDKTJCB6HzX4,4416
16
- fabricatio/config.py,sha256=-K3_PXAnwEDRu6OvMwbghZWeZzHKWyswWHfBeRi7cDk,17066
17
+ fabricatio/config.py,sha256=aA-wirVVfjRuk1AXj-l9UFQFaDEBtV3YnzQIwCPE_G0,17503
17
18
  fabricatio/core.py,sha256=VQ_JKgUGIy2gZ8xsTBZCdr_IP7wC5aPg0_bsOmjQ588,6458
18
19
  fabricatio/decorators.py,sha256=C0Gi7wcXC-0sWITqsSv3JdBGcgVJOlRvOt0FfO0aUsA,7554
19
20
  fabricatio/fs/curd.py,sha256=p8y0LGKgVDk-CWOlm37E6wg7RK6RCD6denKo-VsW28c,4763
20
21
  fabricatio/fs/readers.py,sha256=EZKN_AZdrp8DggJECP53QHw3uHeSDf-AwCAA_V7fNKU,1202
21
22
  fabricatio/fs/__init__.py,sha256=PCf0s_9KDjVfNw7AfPoJzGt3jMq4gJOfbcT4pb0D0ZY,588
22
23
  fabricatio/journal.py,sha256=stnEP88aUBA_GmU9gfTF2EZI8FS2OyMLGaMSTgK4QgA,476
23
- fabricatio/models/action.py,sha256=N5_j7u1sd-EzuQACwPAJNUWgg328xenJ-DfZ4DOkh_s,9132
24
+ fabricatio/models/action.py,sha256=dZkPP-7DaJIOjsFYWnp6vcOObMgjvda1O2FjboSDYjo,9003
25
+ fabricatio/models/adv_kwargs_types.py,sha256=dcYMLn6xcnWLZTLTBdtpgUZWi-VBeub721GzHRZFT1g,860
24
26
  fabricatio/models/events.py,sha256=QvlnS8FEELg6KNabcJMeh2GV_y0ZBzKOPphcteKYWYU,4183
25
- fabricatio/models/extra/advanced_judge.py,sha256=tmCD7mnPlpuykOxvXxWEk3bKzC7mUNSoOwSquT6fF7E,937
26
- fabricatio/models/extra/article_base.py,sha256=mpetbUlZ334YAd46sqd-pBaoelozIg0XJgPWHbSdZ6k,17531
27
+ fabricatio/models/extra/advanced_judge.py,sha256=mi3KiB8FUuSYICzXPXKwVhCyRE1GL3gHLkwuc-4mh3c,999
28
+ fabricatio/models/extra/article_base.py,sha256=1Fg3iWbod1TCU3nIJK9mOq_8K3oGBtSW03VUwi2I5tg,17058
27
29
  fabricatio/models/extra/article_essence.py,sha256=xd6j-PDqjhrMjgUmyfk6HqkyMLu-sS9feUo0sZ3QABY,2825
28
- fabricatio/models/extra/article_main.py,sha256=OYOnv09n8hB8ChtCSXO9V18tt3ouoSWnG_0MsRkRzJk,8206
30
+ fabricatio/models/extra/article_main.py,sha256=0Xj54pRxUw5Iaj9npYmHKT-ZMvEIBlZ6G1ysNJRgceM,8225
29
31
  fabricatio/models/extra/article_outline.py,sha256=jFbVgiwlo7rnwCGS6ToVgeMUOoRe99Edgbx95THR6z8,1450
30
32
  fabricatio/models/extra/article_proposal.py,sha256=L2kPvH1XCCQSNcI1KQU3ULGq7C24Y88ssugX43LgbsE,2043
31
- fabricatio/models/extra/problem.py,sha256=CX93lMFl-UQDCO3JvD4nCMllXId_FlPwGiLpxOyO5Dc,4502
32
- fabricatio/models/extra/rule.py,sha256=OIyn_r1lwLa-lhFsl--PQHqY_Qi2LIaT24zQSBazf38,781
33
- fabricatio/models/generic.py,sha256=yHcYyM6NhK3tJCpPKG0lzb58y3KI3W8VtVH49FAynU0,19360
34
- fabricatio/models/kwargs_types.py,sha256=chJ-rHaeBVRUPuORHuGR3DdNxxTUrotz0eflPEh4l4w,5474
33
+ fabricatio/models/extra/patches.py,sha256=_yyyDbaQ8wkj6QP-NU-3I74HehFgwD889vD0SlCjynU,303
34
+ fabricatio/models/extra/problem.py,sha256=KwYkc7kjoEG7cwj9C8sWLoZgtBqJVuxlU_7KkvtSgO0,5828
35
+ fabricatio/models/extra/rule.py,sha256=_ThlHOViuHcJdAhc6qdEUHaFOevvQYHvH89STzucUyM,719
36
+ fabricatio/models/generic.py,sha256=uuCwpG4DS5DwnZ-2lRMBDufWbKp_5x4yuh1eAFwkFKY,20682
37
+ fabricatio/models/kwargs_types.py,sha256=sMDA85SoC1AOJ5k6qC8qUiUv0Ne0_5ThU9FZITRNen4,5673
35
38
  fabricatio/models/role.py,sha256=-CRcj5_M3_ciLPzwiNn92grBmwoSLQ-n4koVZiCNTBM,2953
36
39
  fabricatio/models/task.py,sha256=8NaR7ojQWyM740EDTqt9stwHKdrD6axCRpLKo0QzS-I,10492
37
40
  fabricatio/models/tool.py,sha256=kD0eB7OxO9geZOxO6JIKvCBeG-KOpRAkfRZqK_WGfW4,7105
38
- fabricatio/models/usages.py,sha256=HuU9X_8o6-UilHEy1LlszVVs36OMRKTDL07YstMFk5I,31808
41
+ fabricatio/models/usages.py,sha256=UC-igtnfW0scIkedb5leZuuR4XoSZYI7kf1S0L418CU,31813
39
42
  fabricatio/models/utils.py,sha256=Ac5g-8ic6q_w7dhNuh-iiofpL1sqOACxbjPPTljP2LY,4417
40
- fabricatio/parser.py,sha256=9Jzw-yV6uKbFvf6sPna-XHdziVGVBZWvPctgX_6ODL8,6251
43
+ fabricatio/parser.py,sha256=UOSvXigEXK-eXsr3m3b7glOhbBWs4kDJTeTNyuqA9ic,6315
41
44
  fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
45
  fabricatio/toolboxes/arithmetic.py,sha256=WLqhY-Pikv11Y_0SGajwZx3WhsLNpHKf9drzAqOf_nY,1369
43
46
  fabricatio/toolboxes/fs.py,sha256=l4L1CVxJmjw9Ld2XUpIlWfV0_Fu_2Og6d3E13I-S4aE,736
@@ -48,6 +51,6 @@ fabricatio/workflows/rag.py,sha256=-YYp2tlE9Vtfgpg6ROpu6QVO8j8yVSPa6yDzlN3qVxs,5
48
51
  fabricatio/_rust.pyi,sha256=_N8Jw1DMOFAaoibSQolxkKZ07nCfJao7Z9qkojHtLy0,5104
49
52
  fabricatio/_rust_instances.py,sha256=2GwF8aVfYNemRI2feBzH1CZfBGno-XJJE5imJokGEYw,314
50
53
  fabricatio/__init__.py,sha256=SzBYsRhZeL77jLtfJEjmoHOSwHwUGyvMATX6xfndLDM,1135
51
- fabricatio/_rust.cp312-win_amd64.pyd,sha256=655GgiDLplHhewnAbEen77GKKxhllgjljHPx2q0cEps,1888256
52
- fabricatio-0.2.8.dev3.data/scripts/tdown.exe,sha256=giKHqYYYtXEQg7gdrGBRA93R0HkoKPUoFqdyFKP9ZQM,3402752
53
- fabricatio-0.2.8.dev3.dist-info/RECORD,,
54
+ fabricatio/_rust.cp312-win_amd64.pyd,sha256=y_AwUxK1t-eJJnlDm9MowMbM8s_GzUXAPX5W9Ao_06U,1892352
55
+ fabricatio-0.2.8.dev4.data/scripts/tdown.exe,sha256=OKVp-_Q3lDufrVIc_ZmFJRKukM6TGqWnMMs0YOXULQE,3402240
56
+ fabricatio-0.2.8.dev4.dist-info/RECORD,,