fabricatio 0.2.13.dev3__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 (41) hide show
  1. fabricatio/__init__.py +3 -3
  2. fabricatio/actions/article.py +32 -34
  3. fabricatio/actions/article_rag.py +58 -58
  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 +5 -6
  20. fabricatio/models/extra/article_main.py +11 -10
  21. fabricatio/models/generic.py +31 -59
  22. fabricatio/models/role.py +5 -3
  23. fabricatio/models/task.py +9 -9
  24. fabricatio/models/tool.py +5 -4
  25. fabricatio/models/usages.py +170 -161
  26. fabricatio/parser.py +2 -2
  27. fabricatio/rust.cp312-win_amd64.pyd +0 -0
  28. fabricatio/rust.pyi +435 -17
  29. fabricatio-0.3.13.data/scripts/tdown.exe +0 -0
  30. fabricatio-0.3.13.data/scripts/ttm.exe +0 -0
  31. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/METADATA +1 -3
  32. fabricatio-0.3.13.dist-info/RECORD +63 -0
  33. fabricatio/config.py +0 -430
  34. fabricatio/constants.py +0 -20
  35. fabricatio/models/events.py +0 -120
  36. fabricatio/rust_instances.py +0 -10
  37. fabricatio-0.2.13.dev3.data/scripts/tdown.exe +0 -0
  38. fabricatio-0.2.13.dev3.data/scripts/ttm.exe +0 -0
  39. fabricatio-0.2.13.dev3.dist-info/RECORD +0 -67
  40. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/WHEEL +0 -0
  41. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/licenses/LICENSE +0 -0
@@ -1,11 +1,12 @@
1
1
  """A module containing the Correct capability for reviewing, validating, and improving objects."""
2
2
 
3
3
  from asyncio import gather
4
- from typing import Optional, Type, Unpack, cast
4
+ from typing import Optional, Unpack, cast
5
+
6
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
5
7
 
6
8
  from fabricatio.capabilities.propose import Propose
7
9
  from fabricatio.capabilities.rating import Rating
8
- from fabricatio.config import configs
9
10
  from fabricatio.journal import logger
10
11
  from fabricatio.models.adv_kwargs_types import CorrectKwargs
11
12
  from fabricatio.models.extra.problem import Improvement, ProblemSolutions
@@ -14,7 +15,6 @@ from fabricatio.models.kwargs_types import (
14
15
  BestKwargs,
15
16
  ValidateKwargs,
16
17
  )
17
- from fabricatio.rust_instances import TEMPLATE_MANAGER
18
18
  from fabricatio.utils import fallback_kwargs, ok, override_kwargs
19
19
 
20
20
 
@@ -22,7 +22,7 @@ class Correct(Rating, Propose):
22
22
  """A class that provides the capability to correct objects."""
23
23
 
24
24
  async def decide_solution(
25
- self, problem_solutions: ProblemSolutions, **kwargs: Unpack[BestKwargs]
25
+ self, problem_solutions: ProblemSolutions, **kwargs: Unpack[BestKwargs]
26
26
  ) -> ProblemSolutions:
27
27
  """Decide the best solution from a list of problem solutions.
28
28
 
@@ -72,11 +72,11 @@ class Correct(Rating, Propose):
72
72
  return improvement
73
73
 
74
74
  async def fix_troubled_obj[M: SketchedAble](
75
- self,
76
- obj: M,
77
- problem_solutions: ProblemSolutions,
78
- reference: str = "",
79
- **kwargs: Unpack[ValidateKwargs[M]],
75
+ self,
76
+ obj: M,
77
+ problem_solutions: ProblemSolutions,
78
+ reference: str = "",
79
+ **kwargs: Unpack[ValidateKwargs[M]],
80
80
  ) -> Optional[M]:
81
81
  """Fix a troubled object based on problem solutions.
82
82
 
@@ -92,7 +92,7 @@ class Correct(Rating, Propose):
92
92
  return await self.propose(
93
93
  cast("Type[M]", obj.__class__),
94
94
  TEMPLATE_MANAGER.render_template(
95
- configs.templates.fix_troubled_obj_template,
95
+ CONFIG.templates.fix_troubled_obj_template,
96
96
  {
97
97
  "problem": problem_solutions.problem.display(),
98
98
  "solution": ok(
@@ -106,11 +106,11 @@ class Correct(Rating, Propose):
106
106
  )
107
107
 
108
108
  async def fix_troubled_string(
109
- self,
110
- input_text: str,
111
- problem_solutions: ProblemSolutions,
112
- reference: str = "",
113
- **kwargs: Unpack[ValidateKwargs[str]],
109
+ self,
110
+ input_text: str,
111
+ problem_solutions: ProblemSolutions,
112
+ reference: str = "",
113
+ **kwargs: Unpack[ValidateKwargs[str]],
114
114
  ) -> Optional[str]:
115
115
  """Fix a troubled string based on problem solutions.
116
116
 
@@ -125,7 +125,7 @@ class Correct(Rating, Propose):
125
125
  """
126
126
  return await self.ageneric_string(
127
127
  TEMPLATE_MANAGER.render_template(
128
- configs.templates.fix_troubled_string_template,
128
+ CONFIG.templates.fix_troubled_string_template,
129
129
  {
130
130
  "problem": problem_solutions.problem.display(),
131
131
  "solution": ok(
@@ -140,11 +140,11 @@ class Correct(Rating, Propose):
140
140
  )
141
141
 
142
142
  async def correct_obj[M: SketchedAble](
143
- self,
144
- obj: M,
145
- improvement: Improvement,
146
- reference: str = "",
147
- **kwargs: Unpack[ValidateKwargs[M]],
143
+ self,
144
+ obj: M,
145
+ improvement: Improvement,
146
+ reference: str = "",
147
+ **kwargs: Unpack[ValidateKwargs[M]],
148
148
  ) -> Optional[M]:
149
149
  """Review and correct an object based on defined criteria and templates.
150
150
 
@@ -178,7 +178,7 @@ class Correct(Rating, Propose):
178
178
  return obj
179
179
 
180
180
  async def correct_string(
181
- self, input_text: str, improvement: Improvement, reference: str = "", **kwargs: Unpack[ValidateKwargs[str]]
181
+ self, input_text: str, improvement: Improvement, reference: str = "", **kwargs: Unpack[ValidateKwargs[str]]
182
182
  ) -> Optional[str]:
183
183
  """Review and correct a string based on defined criteria and templates.
184
184
 
@@ -210,7 +210,7 @@ class Correct(Rating, Propose):
210
210
  return input_text
211
211
 
212
212
  async def correct_obj_inplace[M: ProposedUpdateAble](
213
- self, obj: M, **kwargs: Unpack[CorrectKwargs[M]]
213
+ self, obj: M, **kwargs: Unpack[CorrectKwargs[M]]
214
214
  ) -> Optional[M]:
215
215
  """Correct an object in place based on defined criteria and templates.
216
216
 
@@ -2,9 +2,10 @@
2
2
 
3
3
  from typing import List, Optional, Type, Unpack, overload
4
4
 
5
+ from fabricatio.rust import CONFIG
6
+
5
7
  from fabricatio import TEMPLATE_MANAGER
6
8
  from fabricatio.capabilities.propose import Propose
7
- from fabricatio.config import configs
8
9
  from fabricatio.models.generic import ProposedAble
9
10
  from fabricatio.models.kwargs_types import ValidateKwargs
10
11
 
@@ -14,54 +15,57 @@ class Extract(Propose):
14
15
 
15
16
  @overload
16
17
  async def extract[M: ProposedAble](
17
- self,
18
- cls: Type[M],
19
- source: str,
20
- extract_requirement: Optional[str] = None,
21
- align_language: bool = True,
22
- **kwargs: Unpack[ValidateKwargs[M]],
18
+ self,
19
+ cls: Type[M],
20
+ source: str,
21
+ extract_requirement: Optional[str] = None,
22
+ align_language: bool = True,
23
+ **kwargs: Unpack[ValidateKwargs[M]],
23
24
  ) -> M: ...
25
+
24
26
  @overload
25
27
  async def extract[M: ProposedAble](
26
- self,
27
- cls: Type[M],
28
- source: str,
29
- extract_requirement: Optional[str] = None,
30
- align_language: bool = True,
31
- **kwargs: Unpack[ValidateKwargs[None]],
28
+ self,
29
+ cls: Type[M],
30
+ source: str,
31
+ extract_requirement: Optional[str] = None,
32
+ align_language: bool = True,
33
+ **kwargs: Unpack[ValidateKwargs[None]],
32
34
  ) -> Optional[M]: ...
33
35
 
34
36
  @overload
35
37
  async def extract[M: ProposedAble](
36
- self,
37
- cls: Type[M],
38
- source: List[str],
39
- extract_requirement: Optional[str] = None,
40
- align_language: bool = True,
41
- **kwargs: Unpack[ValidateKwargs[M]],
38
+ self,
39
+ cls: Type[M],
40
+ source: List[str],
41
+ extract_requirement: Optional[str] = None,
42
+ align_language: bool = True,
43
+ **kwargs: Unpack[ValidateKwargs[M]],
42
44
  ) -> List[M]: ...
45
+
43
46
  @overload
44
47
  async def extract[M: ProposedAble](
45
- self,
46
- cls: Type[M],
47
- source: List[str],
48
- extract_requirement: Optional[str] = None,
49
- align_language: bool = True,
50
- **kwargs: Unpack[ValidateKwargs[None]],
48
+ self,
49
+ cls: Type[M],
50
+ source: List[str],
51
+ extract_requirement: Optional[str] = None,
52
+ align_language: bool = True,
53
+ **kwargs: Unpack[ValidateKwargs[None]],
51
54
  ) -> List[Optional[M]]: ...
55
+
52
56
  async def extract[M: ProposedAble](
53
- self,
54
- cls: Type[M],
55
- source: List[str] | str,
56
- extract_requirement: Optional[str] = None,
57
- align_language: bool = True,
58
- **kwargs: Unpack[ValidateKwargs[Optional[M]]],
57
+ self,
58
+ cls: Type[M],
59
+ source: List[str] | str,
60
+ extract_requirement: Optional[str] = None,
61
+ align_language: bool = True,
62
+ **kwargs: Unpack[ValidateKwargs[Optional[M]]],
59
63
  ) -> M | List[M] | Optional[M] | List[Optional[M]]:
60
64
  """Extract information from a given source to a model."""
61
65
  return await self.propose(
62
66
  cls,
63
67
  prompt=TEMPLATE_MANAGER.render_template(
64
- configs.templates.extract_template,
68
+ CONFIG.templates.extract_template,
65
69
  [{"source": s, "extract_requirement": extract_requirement} for s in source]
66
70
  if isinstance(source, list)
67
71
  else {"source": source, "extract_requirement": extract_requirement, "align_language": align_language},
@@ -10,16 +10,15 @@ from functools import lru_cache
10
10
  from operator import itemgetter
11
11
  from typing import List, Optional, Self, Type, Unpack
12
12
 
13
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
13
14
  from more_itertools.recipes import flatten, unique
14
15
  from pydantic import Field, PrivateAttr
15
16
 
16
- from fabricatio.config import configs
17
17
  from fabricatio.journal import logger
18
18
  from fabricatio.models.adv_kwargs_types import CollectionConfigKwargs, FetchKwargs
19
19
  from fabricatio.models.extra.rag import MilvusDataBase
20
20
  from fabricatio.models.kwargs_types import ChooseKwargs
21
21
  from fabricatio.models.usages import EmbeddingUsage
22
- from fabricatio.rust_instances import TEMPLATE_MANAGER
23
22
  from fabricatio.utils import ok
24
23
 
25
24
 
@@ -50,17 +49,17 @@ class RAG(EmbeddingUsage):
50
49
  return self._client
51
50
 
52
51
  def init_client(
53
- self,
54
- milvus_uri: Optional[str] = None,
55
- milvus_token: Optional[str] = None,
56
- milvus_timeout: Optional[float] = None,
52
+ self,
53
+ milvus_uri: Optional[str] = None,
54
+ milvus_token: Optional[str] = None,
55
+ milvus_timeout: Optional[float] = None,
57
56
  ) -> Self:
58
57
  """Initialize the Milvus client."""
59
58
  self._client = create_client(
60
- uri=milvus_uri or ok(self.milvus_uri or configs.rag.milvus_uri).unicode_string(),
59
+ uri=milvus_uri or ok(self.milvus_uri or CONFIG.rag.milvus_uri).unicode_string(),
61
60
  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,
61
+ or (token.get_secret_value() if (token := (self.milvus_token or CONFIG.rag.milvus_token)) else ""),
62
+ timeout=milvus_timeout or self.milvus_timeout or CONFIG.rag.milvus_timeout,
64
63
  )
65
64
  return self
66
65
 
@@ -73,7 +72,7 @@ class RAG(EmbeddingUsage):
73
72
  return self
74
73
 
75
74
  def view(
76
- self, collection_name: Optional[str], create: bool = False, **kwargs: Unpack[CollectionConfigKwargs]
75
+ self, collection_name: Optional[str], create: bool = False, **kwargs: Unpack[CollectionConfigKwargs]
77
76
  ) -> Self:
78
77
  """View the specified collection.
79
78
 
@@ -86,9 +85,9 @@ class RAG(EmbeddingUsage):
86
85
  kwargs["dimension"] = ok(
87
86
  kwargs.get("dimension")
88
87
  or self.milvus_dimensions
89
- or configs.rag.milvus_dimensions
88
+ or CONFIG.rag.milvus_dimensions
90
89
  or self.embedding_dimensions
91
- or configs.embedding.dimensions,
90
+ or CONFIG.embedding.dimensions,
92
91
  "`dimension` is not set at any level.",
93
92
  )
94
93
  self.client.create_collection(collection_name, auto_id=True, **kwargs)
@@ -115,7 +114,7 @@ class RAG(EmbeddingUsage):
115
114
  return ok(self.target_collection, "No collection is being viewed. Have you called `self.view()`?")
116
115
 
117
116
  async def add_document[D: MilvusDataBase](
118
- self, data: List[D] | D, collection_name: Optional[str] = None, flush: bool = False
117
+ self, data: List[D] | D, collection_name: Optional[str] = None, flush: bool = False
119
118
  ) -> Self:
120
119
  """Adds a document to the specified collection.
121
120
 
@@ -142,15 +141,15 @@ class RAG(EmbeddingUsage):
142
141
  return self
143
142
 
144
143
  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 = "",
144
+ self,
145
+ query: List[str],
146
+ document_model: Type[D],
147
+ collection_name: Optional[str] = None,
148
+ similarity_threshold: float = 0.37,
149
+ result_per_query: int = 10,
150
+ tei_endpoint: Optional[str] = None,
151
+ reranker_threshold: float = 0.7,
152
+ filter_expr: str = "",
154
153
  ) -> List[D]:
155
154
  """Asynchronously fetches documents from a Milvus database based on input vectors.
156
155
 
@@ -215,11 +214,11 @@ class RAG(EmbeddingUsage):
215
214
  return document_model.from_sequence(resp)
216
215
 
217
216
  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],
217
+ self,
218
+ query: List[str] | str,
219
+ document_model: Type[D],
220
+ max_accepted: int = 20,
221
+ **kwargs: Unpack[FetchKwargs],
223
222
  ) -> List[D]:
224
223
  """Retrieve data from the collection.
225
224
 
@@ -236,15 +235,15 @@ class RAG(EmbeddingUsage):
236
235
  query = [query]
237
236
 
238
237
  return (
239
- await self.afetch_document(
240
- query=query,
241
- document_model=document_model,
242
- **kwargs,
243
- )
244
- )[:max_accepted]
238
+ await self.afetch_document(
239
+ query=query,
240
+ document_model=document_model,
241
+ **kwargs,
242
+ )
243
+ )[:max_accepted]
245
244
 
246
245
  async def arefined_query(
247
- self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs[Optional[List[str]]]]
246
+ self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs[Optional[List[str]]]]
248
247
  ) -> Optional[List[str]]:
249
248
  """Refines the given question using a template.
250
249
 
@@ -257,7 +256,7 @@ class RAG(EmbeddingUsage):
257
256
  """
258
257
  return await self.alist_str(
259
258
  TEMPLATE_MANAGER.render_template(
260
- configs.templates.refined_query_template,
259
+ CONFIG.templates.refined_query_template,
261
260
  {"question": [question] if isinstance(question, str) else question},
262
261
  ),
263
262
  **kwargs,
@@ -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]