fabricatio 0.2.13.dev2__cp312-cp312-win_amd64.whl → 0.3.13__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.
Files changed (42) hide show
  1. fabricatio/__init__.py +3 -3
  2. fabricatio/actions/article.py +32 -34
  3. fabricatio/actions/article_rag.py +89 -69
  4. fabricatio/actions/output.py +22 -21
  5. fabricatio/actions/rag.py +4 -3
  6. fabricatio/capabilities/check.py +29 -30
  7. fabricatio/capabilities/correct.py +23 -23
  8. fabricatio/capabilities/extract.py +36 -32
  9. fabricatio/capabilities/rag.py +34 -35
  10. fabricatio/capabilities/rating.py +77 -72
  11. fabricatio/capabilities/review.py +12 -11
  12. fabricatio/capabilities/task.py +4 -5
  13. fabricatio/core.py +22 -24
  14. fabricatio/decorators.py +10 -10
  15. fabricatio/fs/__init__.py +1 -2
  16. fabricatio/journal.py +2 -9
  17. fabricatio/models/action.py +2 -1
  18. fabricatio/models/extra/aricle_rag.py +10 -9
  19. fabricatio/models/extra/article_base.py +30 -6
  20. fabricatio/models/extra/article_main.py +11 -10
  21. fabricatio/models/extra/article_outline.py +5 -36
  22. fabricatio/models/generic.py +31 -59
  23. fabricatio/models/role.py +5 -3
  24. fabricatio/models/task.py +9 -9
  25. fabricatio/models/tool.py +5 -4
  26. fabricatio/models/usages.py +170 -161
  27. fabricatio/parser.py +2 -2
  28. fabricatio/rust.cp312-win_amd64.pyd +0 -0
  29. fabricatio/rust.pyi +496 -14
  30. fabricatio-0.3.13.data/scripts/tdown.exe +0 -0
  31. fabricatio-0.3.13.data/scripts/ttm.exe +0 -0
  32. {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/METADATA +1 -3
  33. fabricatio-0.3.13.dist-info/RECORD +63 -0
  34. fabricatio/config.py +0 -430
  35. fabricatio/constants.py +0 -20
  36. fabricatio/models/events.py +0 -120
  37. fabricatio/rust_instances.py +0 -10
  38. fabricatio-0.2.13.dev2.data/scripts/tdown.exe +0 -0
  39. fabricatio-0.2.13.dev2.data/scripts/ttm.exe +0 -0
  40. fabricatio-0.2.13.dev2.dist-info/RECORD +0 -67
  41. {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/WHEEL +0 -0
  42. {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/licenses/LICENSE +0 -0
@@ -4,16 +4,15 @@ from itertools import permutations
4
4
  from random import sample
5
5
  from typing import Dict, List, Optional, Set, Tuple, Union, Unpack, overload
6
6
 
7
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
7
8
  from more_itertools import flatten, windowed
8
9
  from pydantic import Field, NonNegativeInt, PositiveInt, create_model
9
10
 
10
11
  from fabricatio.capabilities.propose import Propose
11
- from fabricatio.config import configs
12
12
  from fabricatio.journal import logger
13
13
  from fabricatio.models.generic import Display, ProposedAble
14
14
  from fabricatio.models.kwargs_types import CompositeScoreKwargs, ValidateKwargs
15
15
  from fabricatio.parser import JsonCapture
16
- from fabricatio.rust_instances import TEMPLATE_MANAGER
17
16
  from fabricatio.utils import ok, override_kwargs
18
17
 
19
18
 
@@ -25,11 +24,11 @@ class Rating(Propose):
25
24
  """
26
25
 
27
26
  async def rate_fine_grind(
28
- self,
29
- to_rate: str | List[str],
30
- rating_manual: Dict[str, str],
31
- score_range: Tuple[float, float],
32
- **kwargs: Unpack[ValidateKwargs[Dict[str, float]]],
27
+ self,
28
+ to_rate: str | List[str],
29
+ rating_manual: Dict[str, str],
30
+ score_range: Tuple[float, float],
31
+ **kwargs: Unpack[ValidateKwargs[Dict[str, float]]],
33
32
  ) -> Dict[str, float] | List[Dict[str, float]] | List[Optional[Dict[str, float]]] | None:
34
33
  """Rate a given string based on a rating manual and score range.
35
34
 
@@ -66,13 +65,13 @@ class Rating(Propose):
66
65
  res = await self.propose(
67
66
  model,
68
67
  TEMPLATE_MANAGER.render_template(
69
- configs.templates.rate_fine_grind_template,
68
+ CONFIG.templates.rate_fine_grind_template,
70
69
  {"to_rate": to_rate, "min_score": min_score, "max_score": max_score},
71
70
  )
72
71
  if isinstance(to_rate, str)
73
72
  else [
74
73
  TEMPLATE_MANAGER.render_template(
75
- configs.templates.rate_fine_grind_template,
74
+ CONFIG.templates.rate_fine_grind_template,
76
75
  {"to_rate": t, "min_score": min_score, "max_score": max_score},
77
76
  )
78
77
  for t in to_rate
@@ -88,34 +87,36 @@ class Rating(Propose):
88
87
 
89
88
  @overload
90
89
  async def rate(
91
- self,
92
- to_rate: str,
93
- topic: str,
94
- criteria: Set[str],
95
- manual: Optional[Dict[str, str]] = None,
96
- score_range: Tuple[float, float] = (0.0, 1.0),
97
- **kwargs: Unpack[ValidateKwargs],
98
- ) -> Dict[str, float]: ...
90
+ self,
91
+ to_rate: str,
92
+ topic: str,
93
+ criteria: Set[str],
94
+ manual: Optional[Dict[str, str]] = None,
95
+ score_range: Tuple[float, float] = (0.0, 1.0),
96
+ **kwargs: Unpack[ValidateKwargs],
97
+ ) -> Dict[str, float]:
98
+ ...
99
99
 
100
100
  @overload
101
101
  async def rate(
102
- self,
103
- to_rate: List[str],
104
- topic: str,
105
- criteria: Set[str],
106
- manual: Optional[Dict[str, str]] = None,
107
- score_range: Tuple[float, float] = (0.0, 1.0),
108
- **kwargs: Unpack[ValidateKwargs],
109
- ) -> List[Dict[str, float]]: ...
102
+ self,
103
+ to_rate: List[str],
104
+ topic: str,
105
+ criteria: Set[str],
106
+ manual: Optional[Dict[str, str]] = None,
107
+ score_range: Tuple[float, float] = (0.0, 1.0),
108
+ **kwargs: Unpack[ValidateKwargs],
109
+ ) -> List[Dict[str, float]]:
110
+ ...
110
111
 
111
112
  async def rate(
112
- self,
113
- to_rate: Union[str, List[str]],
114
- topic: str,
115
- criteria: Set[str],
116
- manual: Optional[Dict[str, str]] = None,
117
- score_range: Tuple[float, float] = (0.0, 1.0),
118
- **kwargs: Unpack[ValidateKwargs],
113
+ self,
114
+ to_rate: Union[str, List[str]],
115
+ topic: str,
116
+ criteria: Set[str],
117
+ manual: Optional[Dict[str, str]] = None,
118
+ score_range: Tuple[float, float] = (0.0, 1.0),
119
+ **kwargs: Unpack[ValidateKwargs],
119
120
  ) -> Dict[str, float] | List[Dict[str, float]] | List[Optional[Dict[str, float]]] | None:
120
121
  """Rate a given string or a sequence of strings based on a topic, criteria, and score range.
121
122
 
@@ -132,15 +133,15 @@ class Rating(Propose):
132
133
  or a list of dictionaries with the ratings for each criterion if a sequence of strings is provided.
133
134
  """
134
135
  manual = (
135
- manual
136
- or await self.draft_rating_manual(topic, criteria, **override_kwargs(kwargs, default=None))
137
- or dict(zip(criteria, criteria, strict=True))
136
+ manual
137
+ or await self.draft_rating_manual(topic, criteria, **override_kwargs(kwargs, default=None))
138
+ or dict(zip(criteria, criteria, strict=True))
138
139
  )
139
140
 
140
141
  return await self.rate_fine_grind(to_rate, manual, score_range, **kwargs)
141
142
 
142
143
  async def draft_rating_manual(
143
- self, topic: str, criteria: Optional[Set[str]] = None, **kwargs: Unpack[ValidateKwargs[Dict[str, str]]]
144
+ self, topic: str, criteria: Optional[Set[str]] = None, **kwargs: Unpack[ValidateKwargs[Dict[str, str]]]
144
145
  ) -> Optional[Dict[str, str]]:
145
146
  """Drafts a rating manual based on a topic and dimensions.
146
147
 
@@ -155,9 +156,9 @@ class Rating(Propose):
155
156
 
156
157
  def _validator(response: str) -> Dict[str, str] | None:
157
158
  if (
158
- (json_data := JsonCapture.validate_with(response, target_type=dict, elements_type=str)) is not None
159
- and json_data.keys() == criteria
160
- and all(isinstance(v, str) for v in json_data.values())
159
+ (json_data := JsonCapture.validate_with(response, target_type=dict, elements_type=str)) is not None
160
+ and json_data.keys() == criteria
161
+ and all(isinstance(v, str) for v in json_data.values())
161
162
  ):
162
163
  return json_data
163
164
  return None
@@ -171,7 +172,7 @@ class Rating(Propose):
171
172
  return await self.aask_validate(
172
173
  question=(
173
174
  TEMPLATE_MANAGER.render_template(
174
- configs.templates.draft_rating_manual_template,
175
+ CONFIG.templates.draft_rating_manual_template,
175
176
  {
176
177
  "topic": topic,
177
178
  "criteria": list(criteria),
@@ -183,10 +184,10 @@ class Rating(Propose):
183
184
  )
184
185
 
185
186
  async def draft_rating_criteria(
186
- self,
187
- topic: str,
188
- criteria_count: NonNegativeInt = 0,
189
- **kwargs: Unpack[ValidateKwargs[Set[str]]],
187
+ self,
188
+ topic: str,
189
+ criteria_count: NonNegativeInt = 0,
190
+ **kwargs: Unpack[ValidateKwargs[Set[str]]],
190
191
  ) -> Optional[Set[str]]:
191
192
  """Drafts rating dimensions based on a topic.
192
193
 
@@ -201,7 +202,7 @@ class Rating(Propose):
201
202
  return await self.aask_validate(
202
203
  question=(
203
204
  TEMPLATE_MANAGER.render_template(
204
- configs.templates.draft_rating_criteria_template,
205
+ CONFIG.templates.draft_rating_criteria_template,
205
206
  {
206
207
  "topic": topic,
207
208
  "criteria_count": criteria_count,
@@ -215,13 +216,13 @@ class Rating(Propose):
215
216
  )
216
217
 
217
218
  async def draft_rating_criteria_from_examples(
218
- self,
219
- topic: str,
220
- examples: List[str],
221
- m: NonNegativeInt = 0,
222
- reasons_count: PositiveInt = 2,
223
- criteria_count: PositiveInt = 5,
224
- **kwargs: Unpack[ValidateKwargs],
219
+ self,
220
+ topic: str,
221
+ examples: List[str],
222
+ m: NonNegativeInt = 0,
223
+ reasons_count: PositiveInt = 2,
224
+ criteria_count: PositiveInt = 5,
225
+ **kwargs: Unpack[ValidateKwargs],
225
226
  ) -> Optional[Set[str]]:
226
227
  """Asynchronously drafts a set of rating criteria based on provided examples.
227
228
 
@@ -251,7 +252,7 @@ class Rating(Propose):
251
252
  await self.aask_validate( # pyright: ignore [reportArgumentType]
252
253
  question=[
253
254
  TEMPLATE_MANAGER.render_template(
254
- configs.templates.extract_reasons_from_examples_template,
255
+ CONFIG.templates.extract_reasons_from_examples_template,
255
256
  {
256
257
  "topic": topic,
257
258
  "first": pair[0],
@@ -271,7 +272,7 @@ class Rating(Propose):
271
272
  return await self.aask_validate(
272
273
  question=(
273
274
  TEMPLATE_MANAGER.render_template(
274
- configs.templates.extract_criteria_from_reasons_template,
275
+ CONFIG.templates.extract_criteria_from_reasons_template,
275
276
  {
276
277
  "topic": topic,
277
278
  "reasons": list(reasons),
@@ -286,10 +287,10 @@ class Rating(Propose):
286
287
  )
287
288
 
288
289
  async def drafting_rating_weights_klee(
289
- self,
290
- topic: str,
291
- criteria: Set[str],
292
- **kwargs: Unpack[ValidateKwargs[float]],
290
+ self,
291
+ topic: str,
292
+ criteria: Set[str],
293
+ **kwargs: Unpack[ValidateKwargs[float]],
293
294
  ) -> Dict[str, float]:
294
295
  """Drafts rating weights for a given topic and criteria using the Klee method.
295
296
 
@@ -311,7 +312,7 @@ class Rating(Propose):
311
312
  relative_weights = await self.aask_validate(
312
313
  question=[
313
314
  TEMPLATE_MANAGER.render_template(
314
- configs.templates.draft_rating_weights_klee_template,
315
+ CONFIG.templates.draft_rating_weights_klee_template,
315
316
  {
316
317
  "topic": topic,
317
318
  "first": pair[0],
@@ -332,14 +333,14 @@ class Rating(Propose):
332
333
  return dict(zip(criteria_seq, [w / total for w in weights], strict=True))
333
334
 
334
335
  async def composite_score(
335
- self,
336
- topic: str,
337
- to_rate: List[str],
338
- criteria: Optional[Set[str]] = None,
339
- weights: Optional[Dict[str, float]] = None,
340
- manual: Optional[Dict[str, str]] = None,
341
- approx: bool = False,
342
- **kwargs: Unpack[ValidateKwargs[List[Dict[str, float]]]],
336
+ self,
337
+ topic: str,
338
+ to_rate: List[str],
339
+ criteria: Optional[Set[str]] = None,
340
+ weights: Optional[Dict[str, float]] = None,
341
+ manual: Optional[Dict[str, str]] = None,
342
+ approx: bool = False,
343
+ **kwargs: Unpack[ValidateKwargs[List[Dict[str, float]]]],
343
344
  ) -> List[float]:
344
345
  """Calculates the composite scores for a list of items based on a given topic and criteria.
345
346
 
@@ -369,14 +370,17 @@ class Rating(Propose):
369
370
  return [sum(ratings[c] * weights[c] for c in criteria) for ratings in ratings_seq]
370
371
 
371
372
  @overload
372
- async def best(self, candidates: List[str], k: int = 1, **kwargs: Unpack[CompositeScoreKwargs]) -> List[str]: ...
373
+ async def best(self, candidates: List[str], k: int = 1, **kwargs: Unpack[CompositeScoreKwargs]) -> List[str]:
374
+ ...
375
+
373
376
  @overload
374
377
  async def best[T: Display](
375
- self, candidates: List[T], k: int = 1, **kwargs: Unpack[CompositeScoreKwargs]
376
- ) -> List[T]: ...
378
+ self, candidates: List[T], k: int = 1, **kwargs: Unpack[CompositeScoreKwargs]
379
+ ) -> List[T]:
380
+ ...
377
381
 
378
382
  async def best[T: Display](
379
- self, candidates: List[str] | List[T], k: int = 1, **kwargs: Unpack[CompositeScoreKwargs]
383
+ self, candidates: List[str] | List[T], k: int = 1, **kwargs: Unpack[CompositeScoreKwargs]
380
384
  ) -> Optional[List[str] | List[T]]:
381
385
  """Choose the best candidates from the list of candidates based on the composite score.
382
386
 
@@ -400,4 +404,5 @@ class Rating(Propose):
400
404
  rating_seq = await self.composite_score(
401
405
  to_rate=[c.display() if isinstance(c, Display) else c for c in candidates], **kwargs
402
406
  )
403
- return [a[0] for a in sorted(zip(candidates, rating_seq, strict=True), key=lambda x: x[1], reverse=True)[:k]] # pyright: ignore [reportReturnType]
407
+ return [a[0] for a in sorted(zip(candidates, rating_seq, strict=True), key=lambda x: x[1], reverse=True)[
408
+ :k]] # pyright: ignore [reportReturnType]
@@ -2,14 +2,14 @@
2
2
 
3
3
  from typing import Dict, Optional, Set, Unpack
4
4
 
5
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
6
+
5
7
  from fabricatio.capabilities.propose import Propose
6
8
  from fabricatio.capabilities.rating import Rating
7
- from fabricatio.config import configs
8
9
  from fabricatio.models.extra.problem import Improvement
9
10
  from fabricatio.models.generic import Display, WithBriefing
10
11
  from fabricatio.models.kwargs_types import ReviewKwargs, ValidateKwargs
11
12
  from fabricatio.models.task import Task
12
- from fabricatio.rust_instances import TEMPLATE_MANAGER
13
13
  from fabricatio.utils import ok
14
14
 
15
15
 
@@ -41,12 +41,12 @@ class Review(Rating, Propose):
41
41
  return await self.review_obj(task, **kwargs)
42
42
 
43
43
  async def review_string(
44
- self,
45
- input_text: str,
46
- topic: str,
47
- criteria: Optional[Set[str]] = None,
48
- rating_manual: Optional[Dict[str, str]] = None,
49
- **kwargs: Unpack[ValidateKwargs[Improvement]],
44
+ self,
45
+ input_text: str,
46
+ topic: str,
47
+ criteria: Optional[Set[str]] = None,
48
+ rating_manual: Optional[Dict[str, str]] = None,
49
+ **kwargs: Unpack[ValidateKwargs[Improvement]],
50
50
  ) -> Optional[Improvement]:
51
51
  """Review a string based on specified topic and criteria.
52
52
 
@@ -70,7 +70,7 @@ class Review(Rating, Propose):
70
70
  # this `default` is the default for the `propose` method
71
71
  default = kwargs.pop("default")
72
72
 
73
- criteria = ok(criteria or (await self.draft_rating_criteria(topic, **kwargs))," No criteria could be use.")
73
+ criteria = ok(criteria or (await self.draft_rating_criteria(topic, **kwargs)), " No criteria could be use.")
74
74
  manual = rating_manual or await self.draft_rating_manual(topic, criteria, **kwargs)
75
75
 
76
76
  if default is not None:
@@ -78,13 +78,14 @@ class Review(Rating, Propose):
78
78
  return await self.propose(
79
79
  Improvement,
80
80
  TEMPLATE_MANAGER.render_template(
81
- configs.templates.review_string_template,
81
+ CONFIG.templates.review_string_template,
82
82
  {"text": input_text, "topic": topic, "criteria_manual": manual},
83
83
  ),
84
84
  **kwargs,
85
85
  )
86
86
 
87
- async def review_obj[M: (Display, WithBriefing)](self, obj: M, **kwargs: Unpack[ReviewKwargs[Improvement]]) -> Optional[Improvement]:
87
+ async def review_obj[M: (Display, WithBriefing)](self, obj: M, **kwargs: Unpack[ReviewKwargs[Improvement]]) -> \
88
+ Optional[Improvement]:
88
89
  """Review an object that implements Display or WithBriefing interface.
89
90
 
90
91
  This method extracts displayable text from the object and performs a review
@@ -4,16 +4,15 @@ from types import CodeType
4
4
  from typing import Any, Dict, List, Optional, Tuple, Unpack
5
5
 
6
6
  import ujson
7
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
7
8
 
8
9
  from fabricatio.capabilities.propose import Propose
9
- from fabricatio.config import configs
10
10
  from fabricatio.journal import logger
11
11
  from fabricatio.models.kwargs_types import ChooseKwargs, ValidateKwargs
12
12
  from fabricatio.models.task import Task
13
13
  from fabricatio.models.tool import Tool, ToolExecutor
14
14
  from fabricatio.models.usages import ToolBoxUsage
15
15
  from fabricatio.parser import JsonCapture, PythonCapture
16
- from fabricatio.rust_instances import TEMPLATE_MANAGER
17
16
 
18
17
 
19
18
  class ProposeTask(Propose):
@@ -67,10 +66,10 @@ class HandleTask(ToolBoxUsage):
67
66
  return None
68
67
 
69
68
  q = TEMPLATE_MANAGER.render_template(
70
- configs.templates.draft_tool_usage_code_template,
69
+ CONFIG.templates.draft_tool_usage_code_template,
71
70
  {
72
- "data_module_name": configs.toolbox.data_module_name,
73
- "tool_module_name": configs.toolbox.tool_module_name,
71
+ "data_module_name": CONFIG.toolbox.data_module_name,
72
+ "tool_module_name": CONFIG.toolbox.tool_module_name,
74
73
  "task": task.briefing,
75
74
  "deps": task.dependencies_prompt,
76
75
  "tools": [{"name": t.name, "briefing": t.briefing} for t in tools],
fabricatio/core.py CHANGED
@@ -2,12 +2,10 @@
2
2
 
3
3
  from typing import Callable, Optional, Self, overload
4
4
 
5
+ from fabricatio.rust import CONFIG, Event
5
6
  from pydantic import BaseModel, ConfigDict, PrivateAttr
6
7
  from pymitter import EventEmitter
7
8
 
8
- from fabricatio.config import configs
9
- from fabricatio.models.events import Event
10
-
11
9
 
12
10
  class Env(BaseModel):
13
11
  """Environment class that manages event handling using EventEmitter."""
@@ -15,9 +13,9 @@ class Env(BaseModel):
15
13
  model_config = ConfigDict(use_attribute_docstrings=True)
16
14
  _ee: EventEmitter = PrivateAttr(
17
15
  default_factory=lambda: EventEmitter(
18
- delimiter=configs.pymitter.delimiter,
19
- new_listener=configs.pymitter.new_listener_event,
20
- max_listeners=configs.pymitter.max_listeners,
16
+ delimiter=CONFIG.pymitter.delimiter,
17
+ new_listener=CONFIG.pymitter.new_listener_event,
18
+ max_listeners=CONFIG.pymitter.max_listeners,
21
19
  wildcard=True,
22
20
  )
23
21
  )
@@ -38,11 +36,11 @@ class Env(BaseModel):
38
36
 
39
37
  @overload
40
38
  def on[**P, R](
41
- self,
42
- event: str | Event,
43
- func: Optional[Callable[P, R]] = None,
44
- /,
45
- ttl: int = -1,
39
+ self,
40
+ event: str | Event,
41
+ func: Optional[Callable[P, R]] = None,
42
+ /,
43
+ ttl: int = -1,
46
44
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
47
45
  """
48
46
  Registers an event listener with a specific function that listens indefinitely or for a specified number of times.
@@ -58,11 +56,11 @@ class Env(BaseModel):
58
56
  ...
59
57
 
60
58
  def on[**P, R](
61
- self,
62
- event: str | Event,
63
- func: Optional[Callable[P, R]] = None,
64
- /,
65
- ttl=-1,
59
+ self,
60
+ event: str | Event,
61
+ func: Optional[Callable[P, R]] = None,
62
+ /,
63
+ ttl=-1,
66
64
  ) -> Callable[[Callable[P, R]], Callable[P, R]] | Self:
67
65
  """Registers an event listener with a specific function that listens indefinitely or for a specified number of times.
68
66
 
@@ -83,8 +81,8 @@ class Env(BaseModel):
83
81
 
84
82
  @overload
85
83
  def once[**P, R](
86
- self,
87
- event: str | Event,
84
+ self,
85
+ event: str | Event,
88
86
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
89
87
  """
90
88
  Registers an event listener that listens only once.
@@ -99,9 +97,9 @@ class Env(BaseModel):
99
97
 
100
98
  @overload
101
99
  def once[**P, R](
102
- self,
103
- event: str | Event,
104
- func: Callable[[Callable[P, R]], Callable[P, R]],
100
+ self,
101
+ event: str | Event,
102
+ func: Callable[[Callable[P, R]], Callable[P, R]],
105
103
  ) -> Self:
106
104
  """
107
105
  Registers an event listener with a specific function that listens only once.
@@ -116,9 +114,9 @@ class Env(BaseModel):
116
114
  ...
117
115
 
118
116
  def once[**P, R](
119
- self,
120
- event: str | Event,
121
- func: Optional[Callable[P, R]] = None,
117
+ self,
118
+ event: str | Event,
119
+ func: Optional[Callable[P, R]] = None,
122
120
  ) -> Callable[[Callable[P, R]], Callable[P, R]] | Self:
123
121
  """Registers an event listener with a specific function that listens only once.
124
122
 
fabricatio/decorators.py CHANGED
@@ -8,7 +8,8 @@ from shutil import which
8
8
  from types import ModuleType
9
9
  from typing import Callable, Coroutine, List, Optional
10
10
 
11
- from fabricatio.config import configs
11
+ from fabricatio.rust import CONFIG
12
+
12
13
  from fabricatio.journal import logger
13
14
 
14
15
 
@@ -24,7 +25,7 @@ def precheck_package[**P, R](package_name: str, msg: str) -> Callable[[Callable[
24
25
  """
25
26
 
26
27
  def _wrapper(
27
- func: Callable[P, R] | Callable[P, Coroutine[None, None, R]],
28
+ func: Callable[P, R] | Callable[P, Coroutine[None, None, R]],
28
29
  ) -> Callable[P, R] | Callable[P, Coroutine[None, None, R]]:
29
30
  if iscoroutinefunction(func):
30
31
 
@@ -48,7 +49,7 @@ def precheck_package[**P, R](package_name: str, msg: str) -> Callable[[Callable[
48
49
 
49
50
 
50
51
  def depend_on_external_cmd[**P, R](
51
- bin_name: str, install_tip: Optional[str], homepage: Optional[str] = None
52
+ bin_name: str, install_tip: Optional[str], homepage: Optional[str] = None
52
53
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
53
54
  """Decorator to check for the presence of an external command.
54
55
 
@@ -113,7 +114,7 @@ def confirm_to_execute[**P, R](func: Callable[P, R]) -> Callable[P, Optional[R]]
113
114
  Returns:
114
115
  Callable: A decorator that wraps the function to confirm before execution.
115
116
  """
116
- if not configs.general.confirm_on_ops:
117
+ if not CONFIG.general.confirm_on_ops:
117
118
  # Skip confirmation if the configuration is set to False
118
119
  return func
119
120
  from questionary import confirm
@@ -123,8 +124,8 @@ def confirm_to_execute[**P, R](func: Callable[P, R]) -> Callable[P, Optional[R]]
123
124
  @wraps(func)
124
125
  async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
125
126
  if await confirm(
126
- f"Are you sure to execute function: {func.__name__}{signature(func)} \n📦 Args:{args}\n🔑 Kwargs:{kwargs}\n",
127
- instruction="Please input [Yes/No] to proceed (default: Yes):",
127
+ f"Are you sure to execute function: {func.__name__}{signature(func)} \n📦 Args:{args}\n🔑 Kwargs:{kwargs}\n",
128
+ instruction="Please input [Yes/No] to proceed (default: Yes):",
128
129
  ).ask_async():
129
130
  return await func(*args, **kwargs)
130
131
  logger.warning(f"Function: {func.__name__}{signature(func)} canceled by user.")
@@ -135,8 +136,8 @@ def confirm_to_execute[**P, R](func: Callable[P, R]) -> Callable[P, Optional[R]]
135
136
  @wraps(func)
136
137
  def _wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
137
138
  if confirm(
138
- f"Are you sure to execute function: {func.__name__}{signature(func)} \n📦 Args:{args}\n��� Kwargs:{kwargs}\n",
139
- instruction="Please input [Yes/No] to proceed (default: Yes):",
139
+ f"Are you sure to execute function: {func.__name__}{signature(func)} \n📦 Args:{args}\n��� Kwargs:{kwargs}\n",
140
+ instruction="Please input [Yes/No] to proceed (default: Yes):",
140
141
  ).ask():
141
142
  return func(*args, **kwargs)
142
143
  logger.warning(f"Function: {func.__name__}{signature(func)} canceled by user.")
@@ -218,7 +219,7 @@ def use_temp_module[**P, R](modules: ModuleType | List[ModuleType]) -> Callable[
218
219
 
219
220
 
220
221
  def logging_exec_time[**P, R](
221
- func: Callable[P, R] | Callable[P, Coroutine[None, None, R]],
222
+ func: Callable[P, R] | Callable[P, Coroutine[None, None, R]],
222
223
  ) -> Callable[P, R] | Callable[P, Coroutine[None, None, R]]:
223
224
  """Decorator to log the execution time of a function.
224
225
 
@@ -231,7 +232,6 @@ def logging_exec_time[**P, R](
231
232
  from time import time
232
233
 
233
234
  if iscoroutinefunction(func):
234
-
235
235
  @wraps(func)
236
236
  async def _async_wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
237
237
  start_time = time()
fabricatio/fs/__init__.py CHANGED
@@ -1,7 +1,6 @@
1
1
  """FileSystem manipulation module for Fabricatio."""
2
2
  from importlib.util import find_spec
3
3
 
4
- from fabricatio.config import configs
5
4
  from fabricatio.fs.curd import (
6
5
  absolute_path,
7
6
  copy_file,
@@ -32,5 +31,5 @@ __all__ = [
32
31
  if find_spec("magika"):
33
32
  from magika import Magika
34
33
 
35
- MAGIKA = Magika(model_dir=configs.magika.model_dir)
34
+ MAGIKA = Magika()
36
35
  __all__ += ["MAGIKA"]
fabricatio/journal.py CHANGED
@@ -2,20 +2,13 @@
2
2
 
3
3
  import sys
4
4
 
5
+ from fabricatio.rust import CONFIG
5
6
  from loguru import logger
6
7
  from rich import pretty, traceback
7
8
 
8
- from fabricatio.config import configs
9
-
10
9
  pretty.install()
11
10
  traceback.install()
12
11
  logger.remove()
13
- logger.add(
14
- configs.debug.log_file,
15
- level=configs.debug.log_level,
16
- rotation=f"{configs.debug.rotation} weeks",
17
- retention=f"{configs.debug.retention} weeks",
18
- )
19
- logger.add(sys.stderr, level=configs.debug.log_level)
12
+ logger.add(sys.stderr, level=CONFIG.debug.log_level)
20
13
 
21
14
  __all__ = ["logger"]
@@ -14,12 +14,13 @@ from abc import abstractmethod
14
14
  from asyncio import Queue, create_task
15
15
  from typing import Any, ClassVar, Dict, Self, Sequence, Tuple, Type, Union, final
16
16
 
17
+ from pydantic import Field, PrivateAttr
18
+
17
19
  from fabricatio.journal import logger
18
20
  from fabricatio.models.generic import WithBriefing
19
21
  from fabricatio.models.task import Task
20
22
  from fabricatio.models.usages import ToolBoxUsage
21
23
  from fabricatio.utils import override_kwargs
22
- from pydantic import Field, PrivateAttr
23
24
 
24
25
  OUTPUT_KEY = "task_output"
25
26
 
@@ -5,16 +5,17 @@ from itertools import groupby
5
5
  from pathlib import Path
6
6
  from typing import ClassVar, Dict, List, Optional, Self, Unpack
7
7
 
8
+ from fabricatio.rust import BibManager, blake3_hash, split_into_chunks
9
+ from more_itertools.more import first
10
+ from more_itertools.recipes import flatten, unique
11
+ from pydantic import Field
12
+
8
13
  from fabricatio.fs import safe_text_read
9
14
  from fabricatio.journal import logger
10
15
  from fabricatio.models.extra.rag import MilvusDataBase
11
16
  from fabricatio.models.generic import AsPrompt
12
17
  from fabricatio.models.kwargs_types import ChunkKwargs
13
- from fabricatio.rust import BibManager, blake3_hash, split_into_chunks
14
18
  from fabricatio.utils import ok, wrapp_in_block
15
- from more_itertools.more import first
16
- from more_itertools.recipes import flatten, unique
17
- from pydantic import Field
18
19
 
19
20
 
20
21
  class ArticleChunk(MilvusDataBase):
@@ -67,7 +68,7 @@ class ArticleChunk(MilvusDataBase):
67
68
 
68
69
  @classmethod
69
70
  def from_file[P: str | Path](
70
- cls, path: P | List[P], bib_mgr: BibManager, **kwargs: Unpack[ChunkKwargs]
71
+ cls, path: P | List[P], bib_mgr: BibManager, **kwargs: Unpack[ChunkKwargs]
71
72
  ) -> List[Self]:
72
73
  """Load the article chunks from the file."""
73
74
  if isinstance(path, list):
@@ -84,9 +85,9 @@ class ArticleChunk(MilvusDataBase):
84
85
  title_seg = path.stem.split(" - ").pop()
85
86
 
86
87
  key = (
87
- bib_mgr.get_cite_key_by_title(title_seg)
88
- or bib_mgr.get_cite_key_by_title_fuzzy(title_seg)
89
- or bib_mgr.get_cite_key_fuzzy(path.stem)
88
+ bib_mgr.get_cite_key_by_title(title_seg)
89
+ or bib_mgr.get_cite_key_by_title_fuzzy(title_seg)
90
+ or bib_mgr.get_cite_key_fuzzy(path.stem)
90
91
  )
91
92
  if key is None:
92
93
  logger.warning(f"no cite key found for {path.as_posix()}, skip.")
@@ -178,7 +179,7 @@ class CitationManager(AsPrompt):
178
179
  """Separator for abbreviated citation numbers."""
179
180
 
180
181
  def update_chunks(
181
- self, article_chunks: List[ArticleChunk], set_cite_number: bool = True, dedup: bool = True
182
+ self, article_chunks: List[ArticleChunk], set_cite_number: bool = True, dedup: bool = True
182
183
  ) -> Self:
183
184
  """Update article chunks."""
184
185
  self.article_chunks.clear()