fabricatio 0.3.15.dev5__cp313-cp313-win_amd64.whl → 0.4.0.dev0__cp313-cp313-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/__init__.py +8 -9
- fabricatio/rust.cp313-win_amd64.pyd +0 -0
- fabricatio/toolboxes/arithmetic.py +1 -1
- fabricatio/toolboxes/fs.py +2 -2
- fabricatio/workflows/rag.py +2 -1
- fabricatio-0.4.0.dev0.data/scripts/tdown.exe +0 -0
- {fabricatio-0.3.15.dev5.dist-info → fabricatio-0.4.0.dev0.dist-info}/METADATA +22 -16
- fabricatio-0.4.0.dev0.dist-info/RECORD +13 -0
- fabricatio/actions/__init__.py +0 -1
- fabricatio/actions/article.py +0 -415
- fabricatio/actions/article_rag.py +0 -407
- fabricatio/actions/fs.py +0 -25
- fabricatio/actions/output.py +0 -247
- fabricatio/actions/rag.py +0 -96
- fabricatio/actions/rules.py +0 -83
- fabricatio/capabilities/__init__.py +0 -1
- fabricatio/capabilities/advanced_judge.py +0 -20
- fabricatio/capabilities/advanced_rag.py +0 -61
- fabricatio/capabilities/censor.py +0 -105
- fabricatio/capabilities/check.py +0 -212
- fabricatio/capabilities/correct.py +0 -228
- fabricatio/capabilities/extract.py +0 -74
- fabricatio/capabilities/propose.py +0 -65
- fabricatio/capabilities/rag.py +0 -264
- fabricatio/capabilities/rating.py +0 -404
- fabricatio/capabilities/review.py +0 -114
- fabricatio/capabilities/task.py +0 -113
- fabricatio/decorators.py +0 -253
- fabricatio/emitter.py +0 -177
- fabricatio/fs/__init__.py +0 -35
- fabricatio/fs/curd.py +0 -153
- fabricatio/fs/readers.py +0 -61
- fabricatio/journal.py +0 -12
- fabricatio/models/action.py +0 -263
- fabricatio/models/adv_kwargs_types.py +0 -63
- fabricatio/models/extra/__init__.py +0 -1
- fabricatio/models/extra/advanced_judge.py +0 -32
- fabricatio/models/extra/aricle_rag.py +0 -286
- fabricatio/models/extra/article_base.py +0 -488
- fabricatio/models/extra/article_essence.py +0 -98
- fabricatio/models/extra/article_main.py +0 -285
- fabricatio/models/extra/article_outline.py +0 -45
- fabricatio/models/extra/article_proposal.py +0 -52
- fabricatio/models/extra/patches.py +0 -20
- fabricatio/models/extra/problem.py +0 -165
- fabricatio/models/extra/rag.py +0 -98
- fabricatio/models/extra/rule.py +0 -51
- fabricatio/models/generic.py +0 -904
- fabricatio/models/kwargs_types.py +0 -121
- fabricatio/models/role.py +0 -156
- fabricatio/models/task.py +0 -310
- fabricatio/models/tool.py +0 -328
- fabricatio/models/usages.py +0 -791
- fabricatio/parser.py +0 -114
- fabricatio/rust.pyi +0 -846
- fabricatio/utils.py +0 -156
- fabricatio/workflows/articles.py +0 -24
- fabricatio-0.3.15.dev5.data/scripts/tdown.exe +0 -0
- fabricatio-0.3.15.dev5.data/scripts/ttm.exe +0 -0
- fabricatio-0.3.15.dev5.dist-info/RECORD +0 -63
- {fabricatio-0.3.15.dev5.dist-info → fabricatio-0.4.0.dev0.dist-info}/WHEEL +0 -0
- {fabricatio-0.3.15.dev5.dist-info → fabricatio-0.4.0.dev0.dist-info}/licenses/LICENSE +0 -0
fabricatio/parser.py
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
"""A module for capturing patterns in text using regular expressions."""
|
2
|
-
|
3
|
-
import re
|
4
|
-
from dataclasses import dataclass, field
|
5
|
-
from functools import lru_cache
|
6
|
-
from typing import Any, Callable, Iterable, List, Optional, Self, Tuple, Type, Union
|
7
|
-
|
8
|
-
import ujson
|
9
|
-
from json_repair import repair_json
|
10
|
-
|
11
|
-
from fabricatio.journal import logger
|
12
|
-
from fabricatio.rust import CONFIG
|
13
|
-
|
14
|
-
|
15
|
-
@dataclass(frozen=True)
|
16
|
-
class Capture:
|
17
|
-
"""A class to capture patterns in text using regular expressions.
|
18
|
-
|
19
|
-
Attributes:
|
20
|
-
target_groups (Tuple[int, ...]): The target groups to extract from the match.
|
21
|
-
pattern (str): The regex pattern to search for.
|
22
|
-
flags (int): Flags to apply when compiling the regex.
|
23
|
-
capture_type (Optional[str]): Optional hint for post-processing (e.g., 'json').
|
24
|
-
"""
|
25
|
-
|
26
|
-
pattern: str = field()
|
27
|
-
"""The regular expression pattern to search for."""
|
28
|
-
flags: int = re.DOTALL | re.MULTILINE | re.IGNORECASE
|
29
|
-
"""Flags to control regex behavior (DOTALL, MULTILINE, IGNORECASE by default)."""
|
30
|
-
capture_type: Optional[str] = None
|
31
|
-
"""Optional type identifier for post-processing (e.g., 'json' for JSON repair)."""
|
32
|
-
target_groups: Tuple[int, ...] = field(default_factory=tuple)
|
33
|
-
"""Tuple of group indices to extract from the match (1-based indexing)."""
|
34
|
-
|
35
|
-
def fix(self, text: Union[str, Iterable[str], Any]) -> Union[str, List[str], Any]:
|
36
|
-
"""Fix the text based on capture_type (e.g., JSON repair)."""
|
37
|
-
match self.capture_type:
|
38
|
-
case "json" if CONFIG.general.use_json_repair:
|
39
|
-
logger.debug("Applying JSON repair to text.")
|
40
|
-
if isinstance(text, str):
|
41
|
-
return repair_json(text, ensure_ascii=False)
|
42
|
-
return [repair_json(item, ensure_ascii=False) for item in text]
|
43
|
-
case _:
|
44
|
-
return text
|
45
|
-
|
46
|
-
def capture(self, text: str) -> Optional[Union[str, Tuple[str, ...]]]:
|
47
|
-
"""Capture the first match of the pattern in the text."""
|
48
|
-
compiled = re.compile(self.pattern, self.flags)
|
49
|
-
match = compiled.match(text) or compiled.search(text)
|
50
|
-
if match is None:
|
51
|
-
logger.debug(f"Capture Failed: {text}")
|
52
|
-
return None
|
53
|
-
|
54
|
-
groups = self.fix(match.groups())
|
55
|
-
if self.target_groups:
|
56
|
-
cap = tuple(groups[g - 1] for g in self.target_groups)
|
57
|
-
logger.debug(f"Captured texts: {'\n==\n'.join(cap)}")
|
58
|
-
return cap
|
59
|
-
cap = groups[0]
|
60
|
-
logger.debug(f"Captured text: \n{cap}")
|
61
|
-
return cap
|
62
|
-
|
63
|
-
def convert_with(
|
64
|
-
self,
|
65
|
-
text: str,
|
66
|
-
convertor: Callable[[Union[str, Tuple[str, ...]]], Any],
|
67
|
-
) -> Optional[Any]:
|
68
|
-
"""Convert captured text using a provided function."""
|
69
|
-
if (cap := self.capture(text)) is None:
|
70
|
-
return None
|
71
|
-
try:
|
72
|
-
return convertor(cap)
|
73
|
-
except Exception as e: # noqa: BLE001
|
74
|
-
logger.error(f"Failed to convert text using {convertor.__name__}: {e}\n{cap}")
|
75
|
-
return None
|
76
|
-
|
77
|
-
def validate_with[T, K, E](
|
78
|
-
self,
|
79
|
-
text: str,
|
80
|
-
target_type: Type[T],
|
81
|
-
elements_type: Optional[Type[E]] = None,
|
82
|
-
length: Optional[int] = None,
|
83
|
-
deserializer: Callable[[Union[str, Tuple[str, ...]]], K] = lambda x: ujson.loads(x) if isinstance(x, str) else ujson.loads(x[0]),
|
84
|
-
) -> Optional[T]:
|
85
|
-
"""Deserialize and validate the captured text against expected types."""
|
86
|
-
judges = [lambda obj: isinstance(obj, target_type)]
|
87
|
-
if elements_type:
|
88
|
-
judges.append(lambda obj: all(isinstance(e, elements_type) for e in obj))
|
89
|
-
if length:
|
90
|
-
judges.append(lambda obj: len(obj) == length)
|
91
|
-
|
92
|
-
if (out := self.convert_with(text, deserializer)) and all(j(out) for j in judges):
|
93
|
-
return out # type: ignore
|
94
|
-
return None
|
95
|
-
|
96
|
-
@classmethod
|
97
|
-
@lru_cache(32)
|
98
|
-
def capture_code_block(cls, language: str) -> Self:
|
99
|
-
"""Capture a code block of the given language."""
|
100
|
-
return cls(pattern=f"```{language}(.*?)```", capture_type=language)
|
101
|
-
|
102
|
-
@classmethod
|
103
|
-
@lru_cache(32)
|
104
|
-
def capture_generic_block(cls, language: str) -> Self:
|
105
|
-
"""Capture a generic block of the given language."""
|
106
|
-
return cls(
|
107
|
-
pattern=f"--- Start of {language} ---(.*?)--- End of {language} ---",
|
108
|
-
capture_type=language,
|
109
|
-
)
|
110
|
-
|
111
|
-
|
112
|
-
JsonCapture = Capture.capture_code_block("json")
|
113
|
-
PythonCapture = Capture.capture_code_block("python")
|
114
|
-
GenericCapture = Capture.capture_generic_block("String")
|