fabricatio 0.2.13.dev3__cp312-cp312-win_amd64.whl → 0.3.14__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 (53) hide show
  1. fabricatio/__init__.py +7 -14
  2. fabricatio/actions/article.py +58 -23
  3. fabricatio/actions/article_rag.py +6 -15
  4. fabricatio/actions/output.py +38 -3
  5. fabricatio/actions/rag.py +4 -4
  6. fabricatio/capabilities/advanced_judge.py +4 -7
  7. fabricatio/capabilities/advanced_rag.py +2 -1
  8. fabricatio/capabilities/censor.py +5 -4
  9. fabricatio/capabilities/check.py +6 -7
  10. fabricatio/capabilities/correct.py +5 -5
  11. fabricatio/capabilities/extract.py +7 -3
  12. fabricatio/capabilities/persist.py +103 -0
  13. fabricatio/capabilities/propose.py +2 -2
  14. fabricatio/capabilities/rag.py +43 -43
  15. fabricatio/capabilities/rating.py +11 -10
  16. fabricatio/capabilities/review.py +8 -6
  17. fabricatio/capabilities/task.py +22 -22
  18. fabricatio/decorators.py +4 -2
  19. fabricatio/{core.py → emitter.py} +35 -39
  20. fabricatio/fs/__init__.py +1 -2
  21. fabricatio/journal.py +2 -11
  22. fabricatio/models/action.py +14 -30
  23. fabricatio/models/extra/aricle_rag.py +14 -8
  24. fabricatio/models/extra/article_base.py +56 -25
  25. fabricatio/models/extra/article_essence.py +2 -1
  26. fabricatio/models/extra/article_main.py +16 -13
  27. fabricatio/models/extra/article_outline.py +2 -1
  28. fabricatio/models/extra/article_proposal.py +1 -1
  29. fabricatio/models/extra/rag.py +2 -2
  30. fabricatio/models/extra/rule.py +2 -1
  31. fabricatio/models/generic.py +56 -166
  32. fabricatio/models/kwargs_types.py +1 -54
  33. fabricatio/models/role.py +49 -26
  34. fabricatio/models/task.py +8 -9
  35. fabricatio/models/tool.py +7 -7
  36. fabricatio/models/usages.py +67 -61
  37. fabricatio/parser.py +60 -100
  38. fabricatio/rust.cp312-win_amd64.pyd +0 -0
  39. fabricatio/rust.pyi +469 -74
  40. fabricatio/utils.py +63 -162
  41. fabricatio-0.3.14.data/scripts/tdown.exe +0 -0
  42. fabricatio-0.3.14.data/scripts/ttm.exe +0 -0
  43. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.14.dist-info}/METADATA +10 -15
  44. fabricatio-0.3.14.dist-info/RECORD +64 -0
  45. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.14.dist-info}/WHEEL +1 -1
  46. fabricatio/config.py +0 -430
  47. fabricatio/constants.py +0 -20
  48. fabricatio/models/events.py +0 -120
  49. fabricatio/rust_instances.py +0 -10
  50. fabricatio-0.2.13.dev3.data/scripts/tdown.exe +0 -0
  51. fabricatio-0.2.13.dev3.data/scripts/ttm.exe +0 -0
  52. fabricatio-0.2.13.dev3.dist-info/RECORD +0 -67
  53. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.14.dist-info}/licenses/LICENSE +0 -0
@@ -1,5 +1,5 @@
1
1
  """A module for the task capabilities of the Fabricatio library."""
2
-
2
+ from abc import ABC
3
3
  from typing import List, Optional, Type, Unpack, overload
4
4
 
5
5
  from fabricatio.models.generic import ProposedAble
@@ -7,7 +7,7 @@ from fabricatio.models.kwargs_types import ValidateKwargs
7
7
  from fabricatio.models.usages import LLMUsage
8
8
 
9
9
 
10
- class Propose(LLMUsage):
10
+ class Propose(LLMUsage,ABC):
11
11
  """A class that proposes an Obj based on a prompt."""
12
12
 
13
13
  @overload
@@ -1,5 +1,7 @@
1
1
  """A module for the RAG (Retrieval Augmented Generation) model."""
2
2
 
3
+ from abc import ABC
4
+
3
5
  try:
4
6
  from pymilvus import MilvusClient
5
7
  except ImportError as e:
@@ -13,13 +15,12 @@ from typing import List, Optional, Self, Type, Unpack
13
15
  from more_itertools.recipes import flatten, unique
14
16
  from pydantic import Field, PrivateAttr
15
17
 
16
- from fabricatio.config import configs
17
18
  from fabricatio.journal import logger
18
19
  from fabricatio.models.adv_kwargs_types import CollectionConfigKwargs, FetchKwargs
19
20
  from fabricatio.models.extra.rag import MilvusDataBase
20
21
  from fabricatio.models.kwargs_types import ChooseKwargs
21
22
  from fabricatio.models.usages import EmbeddingUsage
22
- from fabricatio.rust_instances import TEMPLATE_MANAGER
23
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
23
24
  from fabricatio.utils import ok
24
25
 
25
26
 
@@ -33,7 +34,7 @@ def create_client(uri: str, token: str = "", timeout: Optional[float] = None) ->
33
34
  )
34
35
 
35
36
 
36
- class RAG(EmbeddingUsage):
37
+ class RAG(EmbeddingUsage, ABC):
37
38
  """A class representing the RAG (Retrieval Augmented Generation) model."""
38
39
 
39
40
  target_collection: Optional[str] = Field(default=None)
@@ -50,17 +51,17 @@ class RAG(EmbeddingUsage):
50
51
  return self._client
51
52
 
52
53
  def init_client(
53
- self,
54
- milvus_uri: Optional[str] = None,
55
- milvus_token: Optional[str] = None,
56
- milvus_timeout: Optional[float] = None,
54
+ self,
55
+ milvus_uri: Optional[str] = None,
56
+ milvus_token: Optional[str] = None,
57
+ milvus_timeout: Optional[float] = None,
57
58
  ) -> Self:
58
59
  """Initialize the Milvus client."""
59
60
  self._client = create_client(
60
- uri=milvus_uri or ok(self.milvus_uri or configs.rag.milvus_uri).unicode_string(),
61
+ uri=milvus_uri or ok(self.milvus_uri or CONFIG.rag.milvus_uri),
61
62
  token=milvus_token
62
- or (token.get_secret_value() if (token := (self.milvus_token or configs.rag.milvus_token)) else ""),
63
- timeout=milvus_timeout or self.milvus_timeout or configs.rag.milvus_timeout,
63
+ or (token.get_secret_value() if (token := (self.milvus_token or CONFIG.rag.milvus_token)) else ""),
64
+ timeout=milvus_timeout or self.milvus_timeout or CONFIG.rag.milvus_timeout,
64
65
  )
65
66
  return self
66
67
 
@@ -73,7 +74,7 @@ class RAG(EmbeddingUsage):
73
74
  return self
74
75
 
75
76
  def view(
76
- self, collection_name: Optional[str], create: bool = False, **kwargs: Unpack[CollectionConfigKwargs]
77
+ self, collection_name: Optional[str], create: bool = False, **kwargs: Unpack[CollectionConfigKwargs]
77
78
  ) -> Self:
78
79
  """View the specified collection.
79
80
 
@@ -86,9 +87,9 @@ class RAG(EmbeddingUsage):
86
87
  kwargs["dimension"] = ok(
87
88
  kwargs.get("dimension")
88
89
  or self.milvus_dimensions
89
- or configs.rag.milvus_dimensions
90
+ or CONFIG.rag.milvus_dimensions
90
91
  or self.embedding_dimensions
91
- or configs.embedding.dimensions,
92
+ or CONFIG.embedding.dimensions,
92
93
  "`dimension` is not set at any level.",
93
94
  )
94
95
  self.client.create_collection(collection_name, auto_id=True, **kwargs)
@@ -115,7 +116,7 @@ class RAG(EmbeddingUsage):
115
116
  return ok(self.target_collection, "No collection is being viewed. Have you called `self.view()`?")
116
117
 
117
118
  async def add_document[D: MilvusDataBase](
118
- self, data: List[D] | D, collection_name: Optional[str] = None, flush: bool = False
119
+ self, data: List[D] | D, collection_name: Optional[str] = None, flush: bool = False
119
120
  ) -> Self:
120
121
  """Adds a document to the specified collection.
121
122
 
@@ -142,15 +143,15 @@ class RAG(EmbeddingUsage):
142
143
  return self
143
144
 
144
145
  async def afetch_document[D: MilvusDataBase](
145
- self,
146
- query: List[str],
147
- document_model: Type[D],
148
- collection_name: Optional[str] = None,
149
- similarity_threshold: float = 0.37,
150
- result_per_query: int = 10,
151
- tei_endpoint: Optional[str] = None,
152
- reranker_threshold: float = 0.7,
153
- filter_expr: str = "",
146
+ self,
147
+ query: List[str],
148
+ document_model: Type[D],
149
+ collection_name: Optional[str] = None,
150
+ similarity_threshold: float = 0.37,
151
+ result_per_query: int = 10,
152
+ tei_endpoint: Optional[str] = None,
153
+ reranker_threshold: float = 0.7,
154
+ filter_expr: str = "",
154
155
  ) -> List[D]:
155
156
  """Asynchronously fetches documents from a Milvus database based on input vectors.
156
157
 
@@ -163,7 +164,7 @@ class RAG(EmbeddingUsage):
163
164
  result_per_query (int): The maximum number of results to return per query. Defaults to 10.
164
165
  tei_endpoint (str): the endpoint of the TEI api.
165
166
  reranker_threshold (float): The threshold used to filtered low relativity document.
166
- filter_expr (str): filter_expression parsed into pymilvus search.
167
+ filter_expr (str) : The filter expression used to filter out unwanted documents.
167
168
 
168
169
  Returns:
169
170
  List[D]: A list of document objects created from the fetched data.
@@ -178,9 +179,9 @@ class RAG(EmbeddingUsage):
178
179
  limit=result_per_query,
179
180
  )
180
181
  if tei_endpoint is not None:
181
- from fabricatio.utils import RerankerAPI
182
+ from fabricatio.rust import TEIClient
182
183
 
183
- reranker = RerankerAPI(base_url=tei_endpoint)
184
+ reranker = TEIClient(base_url=tei_endpoint)
184
185
 
185
186
  retrieved_id = set()
186
187
  raw_result = []
@@ -191,10 +192,9 @@ class RAG(EmbeddingUsage):
191
192
  retrieved_id.update(res["id"] for res in g)
192
193
  if not models:
193
194
  continue
194
- rank_scores = await reranker.arerank(q, [m.prepare_vectorization() for m in models], truncate=True)
195
- raw_result.extend(
196
- (models[s["index"]], s["score"]) for s in rank_scores if s["score"] > reranker_threshold
197
- )
195
+ rank_scores = await reranker.arerank(q, [m.prepare_vectorization() for m in models], truncate=True,
196
+ truncation_direction="Left")
197
+ raw_result.extend((models[idx], scr) for (idx, scr) in rank_scores if scr > reranker_threshold)
198
198
 
199
199
  raw_result_sorted = sorted(raw_result, key=lambda x: x[1], reverse=True)
200
200
  return [r[0] for r in raw_result_sorted]
@@ -215,11 +215,11 @@ class RAG(EmbeddingUsage):
215
215
  return document_model.from_sequence(resp)
216
216
 
217
217
  async def aretrieve[D: MilvusDataBase](
218
- self,
219
- query: List[str] | str,
220
- document_model: Type[D],
221
- max_accepted: int = 20,
222
- **kwargs: Unpack[FetchKwargs],
218
+ self,
219
+ query: List[str] | str,
220
+ document_model: Type[D],
221
+ max_accepted: int = 20,
222
+ **kwargs: Unpack[FetchKwargs],
223
223
  ) -> List[D]:
224
224
  """Retrieve data from the collection.
225
225
 
@@ -236,15 +236,15 @@ class RAG(EmbeddingUsage):
236
236
  query = [query]
237
237
 
238
238
  return (
239
- await self.afetch_document(
240
- query=query,
241
- document_model=document_model,
242
- **kwargs,
243
- )
244
- )[:max_accepted]
239
+ await self.afetch_document(
240
+ query=query,
241
+ document_model=document_model,
242
+ **kwargs,
243
+ )
244
+ )[:max_accepted]
245
245
 
246
246
  async def arefined_query(
247
- self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs[Optional[List[str]]]]
247
+ self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs[Optional[List[str]]]]
248
248
  ) -> Optional[List[str]]:
249
249
  """Refines the given question using a template.
250
250
 
@@ -257,7 +257,7 @@ class RAG(EmbeddingUsage):
257
257
  """
258
258
  return await self.alist_str(
259
259
  TEMPLATE_MANAGER.render_template(
260
- configs.templates.refined_query_template,
260
+ CONFIG.templates.refined_query_template,
261
261
  {"question": [question] if isinstance(question, str) else question},
262
262
  ),
263
263
  **kwargs,
@@ -1,5 +1,6 @@
1
1
  """A module that provides functionality to rate tasks based on a rating manual and score range."""
2
2
 
3
+ from abc import ABC
3
4
  from itertools import permutations
4
5
  from random import sample
5
6
  from typing import Dict, List, Optional, Set, Tuple, Union, Unpack, overload
@@ -8,16 +9,15 @@ 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
16
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
17
17
  from fabricatio.utils import ok, override_kwargs
18
18
 
19
19
 
20
- class Rating(Propose):
20
+ class Rating(Propose, ABC):
21
21
  """A class that provides functionality to rate tasks based on a rating manual and score range.
22
22
 
23
23
  References:
@@ -66,13 +66,13 @@ class Rating(Propose):
66
66
  res = await self.propose(
67
67
  model,
68
68
  TEMPLATE_MANAGER.render_template(
69
- configs.templates.rate_fine_grind_template,
69
+ CONFIG.templates.rate_fine_grind_template,
70
70
  {"to_rate": to_rate, "min_score": min_score, "max_score": max_score},
71
71
  )
72
72
  if isinstance(to_rate, str)
73
73
  else [
74
74
  TEMPLATE_MANAGER.render_template(
75
- configs.templates.rate_fine_grind_template,
75
+ CONFIG.templates.rate_fine_grind_template,
76
76
  {"to_rate": t, "min_score": min_score, "max_score": max_score},
77
77
  )
78
78
  for t in to_rate
@@ -171,7 +171,7 @@ class Rating(Propose):
171
171
  return await self.aask_validate(
172
172
  question=(
173
173
  TEMPLATE_MANAGER.render_template(
174
- configs.templates.draft_rating_manual_template,
174
+ CONFIG.templates.draft_rating_manual_template,
175
175
  {
176
176
  "topic": topic,
177
177
  "criteria": list(criteria),
@@ -201,7 +201,7 @@ class Rating(Propose):
201
201
  return await self.aask_validate(
202
202
  question=(
203
203
  TEMPLATE_MANAGER.render_template(
204
- configs.templates.draft_rating_criteria_template,
204
+ CONFIG.templates.draft_rating_criteria_template,
205
205
  {
206
206
  "topic": topic,
207
207
  "criteria_count": criteria_count,
@@ -251,7 +251,7 @@ class Rating(Propose):
251
251
  await self.aask_validate( # pyright: ignore [reportArgumentType]
252
252
  question=[
253
253
  TEMPLATE_MANAGER.render_template(
254
- configs.templates.extract_reasons_from_examples_template,
254
+ CONFIG.templates.extract_reasons_from_examples_template,
255
255
  {
256
256
  "topic": topic,
257
257
  "first": pair[0],
@@ -271,7 +271,7 @@ class Rating(Propose):
271
271
  return await self.aask_validate(
272
272
  question=(
273
273
  TEMPLATE_MANAGER.render_template(
274
- configs.templates.extract_criteria_from_reasons_template,
274
+ CONFIG.templates.extract_criteria_from_reasons_template,
275
275
  {
276
276
  "topic": topic,
277
277
  "reasons": list(reasons),
@@ -311,7 +311,7 @@ class Rating(Propose):
311
311
  relative_weights = await self.aask_validate(
312
312
  question=[
313
313
  TEMPLATE_MANAGER.render_template(
314
- configs.templates.draft_rating_weights_klee_template,
314
+ CONFIG.templates.draft_rating_weights_klee_template,
315
315
  {
316
316
  "topic": topic,
317
317
  "first": pair[0],
@@ -370,6 +370,7 @@ class Rating(Propose):
370
370
 
371
371
  @overload
372
372
  async def best(self, candidates: List[str], k: int = 1, **kwargs: Unpack[CompositeScoreKwargs]) -> List[str]: ...
373
+
373
374
  @overload
374
375
  async def best[T: Display](
375
376
  self, candidates: List[T], k: int = 1, **kwargs: Unpack[CompositeScoreKwargs]
@@ -1,19 +1,19 @@
1
1
  """A module that provides functionality to rate tasks based on a rating manual and score range."""
2
2
 
3
+ from abc import ABC
3
4
  from typing import Dict, Optional, Set, Unpack
4
5
 
5
6
  from fabricatio.capabilities.propose import Propose
6
7
  from fabricatio.capabilities.rating import Rating
7
- from fabricatio.config import configs
8
8
  from fabricatio.models.extra.problem import Improvement
9
9
  from fabricatio.models.generic import Display, WithBriefing
10
10
  from fabricatio.models.kwargs_types import ReviewKwargs, ValidateKwargs
11
11
  from fabricatio.models.task import Task
12
- from fabricatio.rust_instances import TEMPLATE_MANAGER
12
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
13
13
  from fabricatio.utils import ok
14
14
 
15
15
 
16
- class Review(Rating, Propose):
16
+ class Review(Rating, Propose, ABC):
17
17
  """Class that provides functionality to review tasks and strings using a language model.
18
18
 
19
19
  This class extends GiveRating and Propose capabilities to analyze content,
@@ -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,15 @@ 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)](
88
+ self, obj: M, **kwargs: Unpack[ReviewKwargs[Improvement]]
89
+ ) -> Optional[Improvement]:
88
90
  """Review an object that implements Display or WithBriefing interface.
89
91
 
90
92
  This method extracts displayable text from the object and performs a review
@@ -1,28 +1,28 @@
1
1
  """A module for the task capabilities of the Fabricatio library."""
2
2
 
3
+ from abc import ABC
3
4
  from types import CodeType
4
5
  from typing import Any, Dict, List, Optional, Tuple, Unpack
5
6
 
6
7
  import ujson
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
16
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
17
17
 
18
18
 
19
- class ProposeTask(Propose):
19
+ class ProposeTask(Propose, ABC):
20
20
  """A class that proposes a task based on a prompt."""
21
21
 
22
22
  async def propose_task[T](
23
- self,
24
- prompt: str,
25
- **kwargs: Unpack[ValidateKwargs[Task[T]]],
23
+ self,
24
+ prompt: str,
25
+ **kwargs: Unpack[ValidateKwargs[Task[T]]],
26
26
  ) -> Optional[Task[T]]:
27
27
  """Asynchronously proposes a task based on a given prompt and parameters.
28
28
 
@@ -40,15 +40,15 @@ class ProposeTask(Propose):
40
40
  return await self.propose(Task, prompt, **kwargs)
41
41
 
42
42
 
43
- class HandleTask(ToolBoxUsage):
43
+ class HandleTask(ToolBoxUsage,ABC):
44
44
  """A class that handles a task based on a task object."""
45
45
 
46
46
  async def draft_tool_usage_code(
47
- self,
48
- task: Task,
49
- tools: List[Tool],
50
- data: Dict[str, Any],
51
- **kwargs: Unpack[ValidateKwargs],
47
+ self,
48
+ task: Task,
49
+ tools: List[Tool],
50
+ data: Dict[str, Any],
51
+ **kwargs: Unpack[ValidateKwargs],
52
52
  ) -> Optional[Tuple[CodeType, List[str]]]:
53
53
  """Asynchronously drafts the tool usage code for a task based on a given task object and tools."""
54
54
  logger.info(f"Drafting tool usage code for task: {task.briefing}")
@@ -60,17 +60,17 @@ class HandleTask(ToolBoxUsage):
60
60
 
61
61
  def _validator(response: str) -> Tuple[CodeType, List[str]] | None:
62
62
  if (source := PythonCapture.convert_with(response, lambda resp: compile(resp, "<string>", "exec"))) and (
63
- to_extract := JsonCapture.convert_with(response, ujson.loads)
63
+ to_extract := JsonCapture.convert_with(response, ujson.loads)
64
64
  ):
65
65
  return source, to_extract
66
66
 
67
67
  return None
68
68
 
69
69
  q = TEMPLATE_MANAGER.render_template(
70
- configs.templates.draft_tool_usage_code_template,
70
+ CONFIG.templates.draft_tool_usage_code_template,
71
71
  {
72
- "data_module_name": configs.toolbox.data_module_name,
73
- "tool_module_name": configs.toolbox.tool_module_name,
72
+ "data_module_name": CONFIG.toolbox.data_module_name,
73
+ "tool_module_name": CONFIG.toolbox.tool_module_name,
74
74
  "task": task.briefing,
75
75
  "deps": task.dependencies_prompt,
76
76
  "tools": [{"name": t.name, "briefing": t.briefing} for t in tools],
@@ -85,12 +85,12 @@ class HandleTask(ToolBoxUsage):
85
85
  )
86
86
 
87
87
  async def handle_fine_grind(
88
- self,
89
- task: Task,
90
- data: Dict[str, Any],
91
- box_choose_kwargs: Optional[ChooseKwargs] = None,
92
- tool_choose_kwargs: Optional[ChooseKwargs] = None,
93
- **kwargs: Unpack[ValidateKwargs],
88
+ self,
89
+ task: Task,
90
+ data: Dict[str, Any],
91
+ box_choose_kwargs: Optional[ChooseKwargs] = None,
92
+ tool_choose_kwargs: Optional[ChooseKwargs] = None,
93
+ **kwargs: Unpack[ValidateKwargs],
94
94
  ) -> Optional[Tuple]:
95
95
  """Asynchronously handles a task based on a given task object and parameters."""
96
96
  logger.info(f"Handling task: \n{task.briefing}")
fabricatio/decorators.py CHANGED
@@ -8,8 +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
12
11
  from fabricatio.journal import logger
12
+ from fabricatio.rust import CONFIG
13
13
 
14
14
 
15
15
  def precheck_package[**P, R](package_name: str, msg: str) -> Callable[[Callable[P, R]], Callable[P, R]]:
@@ -113,7 +113,7 @@ def confirm_to_execute[**P, R](func: Callable[P, R]) -> Callable[P, Optional[R]]
113
113
  Returns:
114
114
  Callable: A decorator that wraps the function to confirm before execution.
115
115
  """
116
- if not configs.general.confirm_on_ops:
116
+ if not CONFIG.general.confirm_on_ops:
117
117
  # Skip confirmation if the configuration is set to False
118
118
  return func
119
119
  from questionary import confirm
@@ -235,6 +235,7 @@ def logging_exec_time[**P, R](
235
235
  @wraps(func)
236
236
  async def _async_wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
237
237
  start_time = time()
238
+ logger.debug(f"Starting execution of {func.__name__}")
238
239
  result = await func(*args, **kwargs)
239
240
  logger.debug(f"Execution time of `{func.__name__}`: {time() - start_time:.2f} s")
240
241
  return result
@@ -244,6 +245,7 @@ def logging_exec_time[**P, R](
244
245
  @wraps(func)
245
246
  def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
246
247
  start_time = time()
248
+ logger.debug(f"Starting execution of {func.__name__}")
247
249
  result = func(*args, **kwargs)
248
250
  logger.debug(f"Execution time of {func.__name__}: {(time() - start_time) * 1000:.2f} ms")
249
251
  return result
@@ -1,25 +1,21 @@
1
1
  """Core module that contains the Env class for managing event handling."""
2
+ from dataclasses import dataclass
3
+ from typing import Callable, ClassVar, Optional, Self, overload
2
4
 
3
- from typing import Callable, Optional, Self, overload
4
-
5
- from pydantic import BaseModel, ConfigDict, PrivateAttr
6
5
  from pymitter import EventEmitter
7
6
 
8
- from fabricatio.config import configs
9
- from fabricatio.models.events import Event
7
+ from fabricatio.rust import CONFIG, Event
10
8
 
11
9
 
12
- class Env(BaseModel):
10
+ @dataclass
11
+ class Env:
13
12
  """Environment class that manages event handling using EventEmitter."""
14
13
 
15
- model_config = ConfigDict(use_attribute_docstrings=True)
16
- _ee: EventEmitter = PrivateAttr(
17
- default_factory=lambda: EventEmitter(
18
- delimiter=configs.pymitter.delimiter,
19
- new_listener=configs.pymitter.new_listener_event,
20
- max_listeners=configs.pymitter.max_listeners,
21
- wildcard=True,
22
- )
14
+ ee: ClassVar[EventEmitter] = EventEmitter(
15
+ delimiter=CONFIG.pymitter.delimiter,
16
+ new_listener=CONFIG.pymitter.new_listener_event,
17
+ max_listeners=CONFIG.pymitter.max_listeners,
18
+ wildcard=True,
23
19
  )
24
20
 
25
21
  @overload
@@ -38,11 +34,11 @@ class Env(BaseModel):
38
34
 
39
35
  @overload
40
36
  def on[**P, R](
41
- self,
42
- event: str | Event,
43
- func: Optional[Callable[P, R]] = None,
44
- /,
45
- ttl: int = -1,
37
+ self,
38
+ event: str | Event,
39
+ func: Optional[Callable[P, R]] = None,
40
+ /,
41
+ ttl: int = -1,
46
42
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
47
43
  """
48
44
  Registers an event listener with a specific function that listens indefinitely or for a specified number of times.
@@ -58,11 +54,11 @@ class Env(BaseModel):
58
54
  ...
59
55
 
60
56
  def on[**P, R](
61
- self,
62
- event: str | Event,
63
- func: Optional[Callable[P, R]] = None,
64
- /,
65
- ttl=-1,
57
+ self,
58
+ event: str | Event,
59
+ func: Optional[Callable[P, R]] = None,
60
+ /,
61
+ ttl=-1,
66
62
  ) -> Callable[[Callable[P, R]], Callable[P, R]] | Self:
67
63
  """Registers an event listener with a specific function that listens indefinitely or for a specified number of times.
68
64
 
@@ -77,14 +73,14 @@ class Env(BaseModel):
77
73
  if isinstance(event, Event):
78
74
  event = event.collapse()
79
75
  if func is None:
80
- return self._ee.on(event, ttl=ttl)
81
- self._ee.on(event, func, ttl=ttl)
76
+ return self.ee.on(event, ttl=ttl)
77
+ self.ee.on(event, func, ttl=ttl)
82
78
  return self
83
79
 
84
80
  @overload
85
81
  def once[**P, R](
86
- self,
87
- event: str | Event,
82
+ self,
83
+ event: str | Event,
88
84
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
89
85
  """
90
86
  Registers an event listener that listens only once.
@@ -99,9 +95,9 @@ class Env(BaseModel):
99
95
 
100
96
  @overload
101
97
  def once[**P, R](
102
- self,
103
- event: str | Event,
104
- func: Callable[[Callable[P, R]], Callable[P, R]],
98
+ self,
99
+ event: str | Event,
100
+ func: Callable[[Callable[P, R]], Callable[P, R]],
105
101
  ) -> Self:
106
102
  """
107
103
  Registers an event listener with a specific function that listens only once.
@@ -116,9 +112,9 @@ class Env(BaseModel):
116
112
  ...
117
113
 
118
114
  def once[**P, R](
119
- self,
120
- event: str | Event,
121
- func: Optional[Callable[P, R]] = None,
115
+ self,
116
+ event: str | Event,
117
+ func: Optional[Callable[P, R]] = None,
122
118
  ) -> Callable[[Callable[P, R]], Callable[P, R]] | Self:
123
119
  """Registers an event listener with a specific function that listens only once.
124
120
 
@@ -132,9 +128,9 @@ class Env(BaseModel):
132
128
  if isinstance(event, Event):
133
129
  event = event.collapse()
134
130
  if func is None:
135
- return self._ee.once(event)
131
+ return self.ee.once(event)
136
132
 
137
- self._ee.once(event, func)
133
+ self.ee.once(event, func)
138
134
  return self
139
135
 
140
136
  def emit[**P](self, event: str | Event, *args: P.args, **kwargs: P.kwargs) -> None:
@@ -148,7 +144,7 @@ class Env(BaseModel):
148
144
  if isinstance(event, Event):
149
145
  event = event.collapse()
150
146
 
151
- self._ee.emit(event, *args, **kwargs)
147
+ self.ee.emit(event, *args, **kwargs)
152
148
 
153
149
  async def emit_async[**P](self, event: str | Event, *args: P.args, **kwargs: P.kwargs) -> None:
154
150
  """Asynchronously emits an event to all registered listeners.
@@ -160,7 +156,7 @@ class Env(BaseModel):
160
156
  """
161
157
  if isinstance(event, Event):
162
158
  event = event.collapse()
163
- return await self._ee.emit_async(event, *args, **kwargs)
159
+ return await self.ee.emit_async(event, *args, **kwargs)
164
160
 
165
161
  def emit_future[**P](self, event: str | Event, *args: P.args, **kwargs: P.kwargs) -> None:
166
162
  """Emits an event to all registered listeners and returns a future object.
@@ -175,7 +171,7 @@ class Env(BaseModel):
175
171
  """
176
172
  if isinstance(event, Event):
177
173
  event = event.collapse()
178
- return self._ee.emit_future(event, *args, **kwargs)
174
+ return self.ee.emit_future(event, *args, **kwargs)
179
175
 
180
176
 
181
177
  env = Env()
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
@@ -3,19 +3,10 @@
3
3
  import sys
4
4
 
5
5
  from loguru import logger
6
- from rich import pretty, traceback
7
6
 
8
- from fabricatio.config import configs
7
+ from fabricatio.rust import CONFIG
9
8
 
10
- pretty.install()
11
- traceback.install()
12
9
  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)
10
+ logger.add(sys.stderr, level=CONFIG.debug.log_level)
20
11
 
21
12
  __all__ = ["logger"]