fabricatio 0.2.8.dev2__cp312-cp312-win_amd64.whl → 0.2.8.dev4__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. fabricatio/_rust.cp312-win_amd64.pyd +0 -0
  2. fabricatio/_rust.pyi +1 -1
  3. fabricatio/actions/article.py +112 -121
  4. fabricatio/actions/article_rag.py +55 -45
  5. fabricatio/actions/output.py +4 -3
  6. fabricatio/actions/rag.py +3 -3
  7. fabricatio/capabilities/censor.py +87 -0
  8. fabricatio/capabilities/check.py +194 -0
  9. fabricatio/capabilities/correct.py +142 -98
  10. fabricatio/capabilities/propose.py +20 -4
  11. fabricatio/capabilities/rag.py +3 -2
  12. fabricatio/capabilities/rating.py +67 -22
  13. fabricatio/capabilities/review.py +18 -187
  14. fabricatio/capabilities/task.py +8 -9
  15. fabricatio/config.py +11 -3
  16. fabricatio/models/action.py +8 -5
  17. fabricatio/models/adv_kwargs_types.py +25 -0
  18. fabricatio/models/extra/advanced_judge.py +10 -7
  19. fabricatio/models/extra/article_base.py +47 -27
  20. fabricatio/models/extra/article_essence.py +40 -209
  21. fabricatio/models/extra/article_main.py +3 -4
  22. fabricatio/models/extra/patches.py +7 -0
  23. fabricatio/models/extra/problem.py +153 -0
  24. fabricatio/models/extra/rule.py +21 -0
  25. fabricatio/models/generic.py +71 -37
  26. fabricatio/models/kwargs_types.py +23 -17
  27. fabricatio/models/role.py +4 -1
  28. fabricatio/models/usages.py +17 -20
  29. fabricatio/models/utils.py +0 -46
  30. fabricatio/parser.py +7 -8
  31. fabricatio/utils.py +54 -0
  32. {fabricatio-0.2.8.dev2.data → fabricatio-0.2.8.dev4.data}/scripts/tdown.exe +0 -0
  33. {fabricatio-0.2.8.dev2.dist-info → fabricatio-0.2.8.dev4.dist-info}/METADATA +2 -1
  34. fabricatio-0.2.8.dev4.dist-info/RECORD +56 -0
  35. fabricatio-0.2.8.dev2.dist-info/RECORD +0 -49
  36. {fabricatio-0.2.8.dev2.dist-info → fabricatio-0.2.8.dev4.dist-info}/WHEEL +0 -0
  37. {fabricatio-0.2.8.dev2.dist-info → fabricatio-0.2.8.dev4.dist-info}/licenses/LICENSE +0 -0
@@ -7,16 +7,16 @@ from typing import Dict, List, Optional, Set, Tuple, Union, Unpack, overload
7
7
  from fabricatio._rust_instances import TEMPLATE_MANAGER
8
8
  from fabricatio.config import configs
9
9
  from fabricatio.journal import logger
10
- from fabricatio.models.generic import WithBriefing
11
- from fabricatio.models.kwargs_types import ValidateKwargs
10
+ from fabricatio.models.generic import Display
11
+ from fabricatio.models.kwargs_types import CompositeScoreKwargs, ValidateKwargs
12
12
  from fabricatio.models.usages import LLMUsage
13
- from fabricatio.models.utils import override_kwargs
14
13
  from fabricatio.parser import JsonCapture
14
+ from fabricatio.utils import ok, override_kwargs
15
15
  from more_itertools import flatten, windowed
16
16
  from pydantic import NonNegativeInt, PositiveInt
17
17
 
18
18
 
19
- class Rating(WithBriefing, LLMUsage):
19
+ class Rating(LLMUsage):
20
20
  """A class that provides functionality to rate tasks based on a rating manual and score range.
21
21
 
22
22
  References:
@@ -87,6 +87,7 @@ class Rating(WithBriefing, LLMUsage):
87
87
  to_rate: str,
88
88
  topic: str,
89
89
  criteria: Set[str],
90
+ manual: Optional[Dict[str, str]],
90
91
  score_range: Tuple[float, float] = (0.0, 1.0),
91
92
  **kwargs: Unpack[ValidateKwargs],
92
93
  ) -> Dict[str, float]: ...
@@ -97,6 +98,7 @@ class Rating(WithBriefing, LLMUsage):
97
98
  to_rate: List[str],
98
99
  topic: str,
99
100
  criteria: Set[str],
101
+ manual: Optional[Dict[str, str]],
100
102
  score_range: Tuple[float, float] = (0.0, 1.0),
101
103
  **kwargs: Unpack[ValidateKwargs],
102
104
  ) -> List[Dict[str, float]]: ...
@@ -106,6 +108,7 @@ class Rating(WithBriefing, LLMUsage):
106
108
  to_rate: Union[str, List[str]],
107
109
  topic: str,
108
110
  criteria: Set[str],
111
+ manual: Optional[Dict[str, str]],
109
112
  score_range: Tuple[float, float] = (0.0, 1.0),
110
113
  **kwargs: Unpack[ValidateKwargs],
111
114
  ) -> Optional[Dict[str, float] | List[Dict[str, float]]]:
@@ -115,6 +118,7 @@ class Rating(WithBriefing, LLMUsage):
115
118
  to_rate (Union[str, List[str]]): The string or sequence of strings to be rated.
116
119
  topic (str): The topic related to the task.
117
120
  criteria (Set[str]): A set of criteria for rating.
121
+ manual (Optional[Dict[str, str]]): A dictionary containing the rating criteria. If not provided, then this method will draft the criteria automatically.
118
122
  score_range (Tuple[float, float], optional): A tuple representing the valid score range. Defaults to (0.0, 1.0).
119
123
  **kwargs (Unpack[ValidateKwargs]): Additional keyword arguments for the LLM usage.
120
124
 
@@ -122,7 +126,11 @@ class Rating(WithBriefing, LLMUsage):
122
126
  Union[Dict[str, float], List[Dict[str, float]]]: A dictionary with the ratings for each criterion if a single string is provided,
123
127
  or a list of dictionaries with the ratings for each criterion if a sequence of strings is provided.
124
128
  """
125
- manual = await self.draft_rating_manual(topic, criteria, **kwargs) or dict(zip(criteria, criteria, strict=True))
129
+ manual = (
130
+ manual
131
+ or await self.draft_rating_manual(topic, criteria, **override_kwargs(kwargs, default=None))
132
+ or dict(zip(criteria, criteria, strict=True))
133
+ )
126
134
 
127
135
  return await self.rate_fine_grind(to_rate, manual, score_range, **kwargs)
128
136
 
@@ -149,9 +157,7 @@ class Rating(WithBriefing, LLMUsage):
149
157
  return json_data
150
158
  return None
151
159
 
152
- criteria = criteria or await self.draft_rating_criteria(
153
- topic, **self.prepend_sys_msg(override_kwargs(dict(kwargs), default=None))
154
- )
160
+ criteria = criteria or await self.draft_rating_criteria(topic, **override_kwargs(dict(kwargs), default=None))
155
161
 
156
162
  if criteria is None:
157
163
  logger.error(f"Failed to draft rating criteria for topic {topic}")
@@ -168,7 +174,7 @@ class Rating(WithBriefing, LLMUsage):
168
174
  )
169
175
  ),
170
176
  validator=_validator,
171
- **self.prepend_sys_msg(kwargs),
177
+ **kwargs,
172
178
  )
173
179
 
174
180
  async def draft_rating_criteria(
@@ -200,7 +206,7 @@ class Rating(WithBriefing, LLMUsage):
200
206
  validator=lambda resp: set(out)
201
207
  if (out := JsonCapture.validate_with(resp, list, str, criteria_count)) is not None
202
208
  else out,
203
- **self.prepend_sys_msg(kwargs),
209
+ **kwargs,
204
210
  )
205
211
 
206
212
  async def draft_rating_criteria_from_examples(
@@ -253,7 +259,7 @@ class Rating(WithBriefing, LLMUsage):
253
259
  validator=lambda resp: JsonCapture.validate_with(
254
260
  resp, target_type=list, elements_type=str, length=reasons_count
255
261
  ),
256
- **self.prepend_sys_msg(kwargs),
262
+ **kwargs,
257
263
  )
258
264
  )
259
265
  # extract certain mount of criteria from reasons according to their importance and frequency
@@ -310,9 +316,9 @@ class Rating(WithBriefing, LLMUsage):
310
316
  for pair in windows
311
317
  ],
312
318
  validator=lambda resp: JsonCapture.validate_with(resp, target_type=float),
313
- **self.prepend_sys_msg(kwargs),
319
+ **kwargs,
314
320
  )
315
- weights = [1]
321
+ weights = [1.0]
316
322
  for rw in relative_weights:
317
323
  weights.append(weights[-1] * rw)
318
324
  total = sum(weights)
@@ -322,27 +328,66 @@ class Rating(WithBriefing, LLMUsage):
322
328
  self,
323
329
  topic: str,
324
330
  to_rate: List[str],
325
- reasons_count: PositiveInt = 2,
326
- criteria_count: PositiveInt = 5,
327
- **kwargs: Unpack[ValidateKwargs],
331
+ criteria: Optional[Set[str]] = None,
332
+ weights: Optional[Dict[str, float]] = None,
333
+ manual: Optional[Dict[str, str]] = None,
334
+ **kwargs: Unpack[ValidateKwargs[List[Dict[str, float]]]],
328
335
  ) -> List[float]:
329
336
  """Calculates the composite scores for a list of items based on a given topic and criteria.
330
337
 
331
338
  Args:
332
339
  topic (str): The topic for the rating.
333
340
  to_rate (List[str]): A list of strings to be rated.
334
- reasons_count (PositiveInt, optional): The number of reasons to extract from each pair of examples. Defaults to 2.
335
- criteria_count (PositiveInt, optional): The number of criteria to draft. Defaults to 5.
341
+ criteria (Optional[Set[str]]): A set of criteria for the rating. Defaults to None.
342
+ weights (Optional[Dict[str, float]]): A dictionary of rating weights for each criterion. Defaults to None.
343
+ manual (Optional[Dict[str, str]]): A dictionary of manual ratings for each item. Defaults to None.
336
344
  **kwargs (Unpack[ValidateKwargs]): Additional keyword arguments for the LLM usage.
337
345
 
338
346
  Returns:
339
347
  List[float]: A list of composite scores for the items.
340
348
  """
341
- criteria = await self.draft_rating_criteria_from_examples(
342
- topic, to_rate, reasons_count, criteria_count, **kwargs
349
+ criteria = ok(
350
+ criteria
351
+ or await self.draft_rating_criteria_from_examples(topic, to_rate, **override_kwargs(kwargs, default=None))
352
+ )
353
+ weights = ok(
354
+ weights or await self.drafting_rating_weights_klee(topic, criteria, **override_kwargs(kwargs, default=None))
343
355
  )
344
- weights = await self.drafting_rating_weights_klee(topic, criteria, **kwargs)
345
356
  logger.info(f"Criteria: {criteria}\nWeights: {weights}")
346
- ratings_seq = await self.rate(to_rate, topic, criteria, **kwargs)
357
+ ratings_seq = await self.rate(to_rate, topic, criteria, manual, **kwargs)
347
358
 
348
359
  return [sum(ratings[c] * weights[c] for c in criteria) for ratings in ratings_seq]
360
+
361
+ @overload
362
+ async def best(self, candidates: List[str], k: int=1, **kwargs: Unpack[CompositeScoreKwargs]) -> List[str]: ...
363
+ @overload
364
+ async def best[T: Display](
365
+ self, candidates: List[T], k: int=1, **kwargs: Unpack[CompositeScoreKwargs]
366
+ ) -> List[T]: ...
367
+
368
+ async def best[T: Display](
369
+ self, candidates: List[str] | List[T], k: int=1, **kwargs: Unpack[CompositeScoreKwargs]
370
+ ) -> Optional[List[str] | List[T]]:
371
+ """Choose the best candidates from the list of candidates based on the composite score.
372
+
373
+ Args:
374
+ k (int): The number of best candidates to choose.
375
+ candidates (List[str]): A list of candidates to choose from.
376
+ **kwargs (CompositeScoreKwargs): Additional keyword arguments for the composite score calculation.
377
+
378
+ Returns:
379
+ List[str]: The best candidates.
380
+ """
381
+ if (leng := len(candidates)) == 0:
382
+ logger.warning(f"No candidates, got {leng}, return None.")
383
+ return None
384
+
385
+ if leng == 1:
386
+ logger.warning(f"Only one candidate, got {leng}, return it.")
387
+ return candidates
388
+ logger.info(f"Choose best {k} from {leng} candidates.")
389
+
390
+ rating_seq = await self.composite_score(
391
+ to_rate=[c.display() if isinstance(c, Display) else c for c in candidates], **kwargs
392
+ )
393
+ return [a[0] for a in sorted(zip(candidates, rating_seq, strict=True), key=lambda x: x[1], reverse=True)[:k]] # pyright: ignore [reportReturnType]
@@ -1,178 +1,16 @@
1
1
  """A module that provides functionality to rate tasks based on a rating manual and score range."""
2
2
 
3
- from typing import Dict, List, Optional, Self, Set, Unpack, cast
3
+ from typing import Dict, Optional, Set, Unpack
4
4
 
5
5
  from fabricatio._rust_instances import TEMPLATE_MANAGER
6
6
  from fabricatio.capabilities.propose import Propose
7
7
  from fabricatio.capabilities.rating import Rating
8
8
  from fabricatio.config import configs
9
- from fabricatio.models.generic import Base, Display, ProposedAble, WithBriefing
9
+ from fabricatio.models.extra.problem import Improvement
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.models.utils import ask_edit
13
- from questionary import Choice, checkbox, text
14
- from questionary import print as q_print
15
- from rich import print as r_print
16
-
17
-
18
- class ProblemSolutions(Base):
19
- """Represents a problem-solution pair identified during a review process.
20
-
21
- This class encapsulates a single problem with its corresponding potential solutions,
22
- providing a structured way to manage review findings.
23
-
24
- Attributes:
25
- problem (str): The problem statement identified during review.
26
- solutions (List[str]): A collection of potential solutions to address the problem.
27
- """
28
-
29
- problem: str
30
- """The problem identified in the review."""
31
- solutions: List[str]
32
- """A collection of potential solutions to address the problem."""
33
-
34
- def update_problem(self, problem: str) -> Self:
35
- """Update the problem description.
36
-
37
- Args:
38
- problem (str): The new problem description to replace the current one.
39
-
40
- Returns:
41
- Self: The current instance with updated problem description.
42
- """
43
- self.problem = problem
44
- return self
45
-
46
- def update_solutions(self, solutions: List[str]) -> Self:
47
- """Update the list of potential solutions.
48
-
49
- Args:
50
- solutions (List[str]): The new collection of solutions to replace the current ones.
51
-
52
- Returns:
53
- Self: The current instance with updated solutions.
54
- """
55
- self.solutions = solutions
56
- return self
57
-
58
- async def edit_problem(self) -> Self:
59
- """Interactively edit the problem description using a prompt.
60
-
61
- Returns:
62
- Self: The current instance with updated problem description.
63
- """
64
- self.problem = await text("Please edit the problem below:", default=self.problem).ask_async()
65
- return self
66
-
67
- async def edit_solutions(self) -> Self:
68
- """Interactively edit the list of potential solutions using a prompt.
69
-
70
- Returns:
71
- Self: The current instance with updated solutions.
72
- """
73
- q_print(self.problem, style="bold cyan")
74
- self.solutions = await ask_edit(self.solutions)
75
- return self
76
-
77
-
78
- class ReviewResult[T](ProposedAble, Display):
79
- """Represents the outcome of a review process with identified problems and solutions.
80
-
81
- This class maintains a structured collection of problems found during a review,
82
- their proposed solutions, and a reference to the original reviewed object.
83
-
84
- Attributes:
85
- review_topic (str): The subject or focus area of the review.
86
- problem_solutions (List[ProblemSolutions]): Collection of problems identified
87
- during review along with their potential solutions.
88
-
89
- Type Parameters:
90
- T: The type of the object being reviewed.
91
- """
92
-
93
- review_topic: str
94
- """The subject or focus area of the review."""
95
-
96
- problem_solutions: List[ProblemSolutions]
97
- """Collection of problems identified during review along with their potential solutions."""
98
-
99
- _ref: T
100
- """Reference to the original object that was reviewed."""
101
-
102
- def update_topic(self, topic: str) -> Self:
103
- """Update the review topic.
104
-
105
- Args:
106
- topic (str): The new topic to be associated with this review.
107
-
108
- Returns:
109
- Self: The current instance with updated review topic.
110
- """
111
- self.review_topic = topic
112
- return self
113
-
114
- def update_ref[K](self, ref: K) -> "ReviewResult[K]":
115
- """Update the reference to the reviewed object.
116
-
117
- Args:
118
- ref (K): The new reference object to be associated with this review.
119
-
120
- Returns:
121
- ReviewResult[K]: The current instance with updated reference type.
122
- """
123
- self._ref = ref # pyright: ignore [reportAttributeAccessIssue]
124
- return cast("ReviewResult[K]", self)
125
-
126
- def deref(self) -> T:
127
- """Retrieve the referenced object that was reviewed.
128
-
129
- Returns:
130
- T: The original object that was reviewed.
131
- """
132
- return self._ref
133
-
134
- async def supervisor_check(self, check_solutions: bool = True) -> Self:
135
- """Perform an interactive review session to filter problems and solutions.
136
-
137
- Presents an interactive prompt allowing a supervisor to select which
138
- problems (and optionally solutions) should be retained in the final review.
139
-
140
- Args:
141
- check_solutions (bool, optional): When True, also prompts for filtering
142
- individual solutions for each retained problem. Defaults to False.
143
-
144
- Returns:
145
- Self: The current instance with filtered problems and solutions.
146
- """
147
- if isinstance(self._ref, str):
148
- display = self._ref
149
- elif isinstance(self._ref, WithBriefing):
150
- display = self._ref.briefing
151
- elif isinstance(self._ref, Display):
152
- display = self._ref.display()
153
- else:
154
- raise TypeError(f"Unsupported type for review: {type(self._ref)}")
155
- # Choose the problems to retain
156
- r_print(display)
157
- chosen_ones: List[ProblemSolutions] = await checkbox(
158
- f"Please choose the problems you want to retain.(Default: retain all)\n\t`{self.review_topic}`",
159
- choices=[Choice(p.problem, p, checked=True) for p in self.problem_solutions],
160
- ).ask_async()
161
- self.problem_solutions = [await p.edit_problem() for p in chosen_ones]
162
- if not check_solutions:
163
- return self
164
-
165
- # Choose the solutions to retain
166
- for to_exam in self.problem_solutions:
167
- to_exam.update_solutions(
168
- await checkbox(
169
- f"Please choose the solutions you want to retain.(Default: retain all)\n\t`{to_exam.problem}`",
170
- choices=[Choice(s, s, checked=True) for s in to_exam.solutions],
171
- ).ask_async()
172
- )
173
- await to_exam.edit_solutions()
174
-
175
- return self
13
+ from fabricatio.utils import ok
176
14
 
177
15
 
178
16
  class Review(Rating, Propose):
@@ -185,7 +23,7 @@ class Review(Rating, Propose):
185
23
  appropriate topic and criteria.
186
24
  """
187
25
 
188
- async def review_task[T](self, task: Task[T], **kwargs: Unpack[ReviewKwargs]) -> ReviewResult[Task[T]]:
26
+ async def review_task[T](self, task: Task[T], **kwargs: Unpack[ReviewKwargs]) -> Optional[Improvement]:
189
27
  """Review a task using specified review criteria.
190
28
 
191
29
  This method analyzes a task object to identify problems and propose solutions
@@ -197,10 +35,10 @@ class Review(Rating, Propose):
197
35
  including topic and optional criteria.
198
36
 
199
37
  Returns:
200
- ReviewResult[Task[T]]: A review result containing identified problems and proposed solutions,
38
+ Improvement[Task[T]]: A review result containing identified problems and proposed solutions,
201
39
  with a reference to the original task.
202
40
  """
203
- return cast("ReviewResult[Task[T]]", await self.review_obj(task, **kwargs))
41
+ return await self.review_obj(task, **kwargs)
204
42
 
205
43
  async def review_string(
206
44
  self,
@@ -208,8 +46,8 @@ class Review(Rating, Propose):
208
46
  topic: str,
209
47
  criteria: Optional[Set[str]] = None,
210
48
  rating_manual: Optional[Dict[str, str]] = None,
211
- **kwargs: Unpack[ValidateKwargs[ReviewResult[str]]],
212
- ) -> ReviewResult[str]:
49
+ **kwargs: Unpack[ValidateKwargs[Improvement]],
50
+ ) -> Optional[Improvement]:
213
51
  """Review a string based on specified topic and criteria.
214
52
 
215
53
  This method analyzes a text string to identify problems and propose solutions
@@ -224,7 +62,7 @@ class Review(Rating, Propose):
224
62
  **kwargs (Unpack[ValidateKwargs]): Additional keyword arguments for the LLM usage.
225
63
 
226
64
  Returns:
227
- ReviewResult[str]: A review result containing identified problems and proposed solutions,
65
+ Improvement: A review result containing identified problems and proposed solutions,
228
66
  with a reference to the original text.
229
67
  """
230
68
  default = None
@@ -232,28 +70,21 @@ class Review(Rating, Propose):
232
70
  # this `default` is the default for the `propose` method
233
71
  default = kwargs.pop("default")
234
72
 
235
- criteria = criteria or (await self.draft_rating_criteria(topic, **kwargs))
236
- if not criteria:
237
- raise ValueError("No criteria provided for review.")
73
+ criteria = ok(criteria or (await self.draft_rating_criteria(topic, **kwargs))," No criteria could be use.")
238
74
  manual = rating_manual or await self.draft_rating_manual(topic, criteria, **kwargs)
239
75
 
240
76
  if default is not None:
241
77
  kwargs["default"] = default
242
- res = await self.propose(
243
- ReviewResult,
78
+ return await self.propose(
79
+ Improvement,
244
80
  TEMPLATE_MANAGER.render_template(
245
81
  configs.templates.review_string_template,
246
82
  {"text": input_text, "topic": topic, "criteria_manual": manual},
247
83
  ),
248
84
  **kwargs,
249
85
  )
250
- if not res:
251
- raise ValueError("Failed to generate review result.")
252
- return res.update_ref(input_text).update_topic(topic)
253
86
 
254
- async def review_obj[M: (Display, WithBriefing)](
255
- self, obj: M, **kwargs: Unpack[ReviewKwargs[ReviewResult[str]]]
256
- ) -> ReviewResult[M]:
87
+ async def review_obj[M: (Display, WithBriefing)](self, obj: M, **kwargs: Unpack[ReviewKwargs[Improvement]]) -> Optional[Improvement]:
257
88
  """Review an object that implements Display or WithBriefing interface.
258
89
 
259
90
  This method extracts displayable text from the object and performs a review
@@ -268,14 +99,14 @@ class Review(Rating, Propose):
268
99
  TypeError: If the object does not implement Display or WithBriefing.
269
100
 
270
101
  Returns:
271
- ReviewResult[M]: A review result containing identified problems and proposed solutions,
102
+ Improvement: A review result containing identified problems and proposed solutions,
272
103
  with a reference to the original object.
273
104
  """
274
105
  if isinstance(obj, Display):
275
- text = obj.display()
106
+ text_to_review = obj.display()
276
107
  elif isinstance(obj, WithBriefing):
277
- text = obj.briefing
108
+ text_to_review = obj.briefing
278
109
  else:
279
110
  raise TypeError(f"Unsupported type for review: {type(obj)}")
280
111
 
281
- return (await self.review_string(text, **kwargs)).update_ref(obj)
112
+ return await self.review_string(text_to_review, **kwargs)
@@ -1,14 +1,13 @@
1
1
  """A module for the task capabilities of the Fabricatio library."""
2
2
 
3
3
  from types import CodeType
4
- from typing import Any, Dict, List, Optional, Tuple, Unpack, cast
4
+ from typing import Any, Dict, List, Optional, Tuple, Unpack
5
5
 
6
6
  import orjson
7
7
  from fabricatio._rust_instances import TEMPLATE_MANAGER
8
8
  from fabricatio.capabilities.propose import Propose
9
9
  from fabricatio.config import configs
10
10
  from fabricatio.journal import logger
11
- from fabricatio.models.generic import WithBriefing
12
11
  from fabricatio.models.kwargs_types import ChooseKwargs, ValidateKwargs
13
12
  from fabricatio.models.task import Task
14
13
  from fabricatio.models.tool import Tool, ToolExecutor
@@ -16,7 +15,7 @@ from fabricatio.models.usages import ToolBoxUsage
16
15
  from fabricatio.parser import JsonCapture, PythonCapture
17
16
 
18
17
 
19
- class ProposeTask(WithBriefing, Propose):
18
+ class ProposeTask(Propose):
20
19
  """A class that proposes a task based on a prompt."""
21
20
 
22
21
  async def propose_task[T](
@@ -34,13 +33,13 @@ class ProposeTask(WithBriefing, Propose):
34
33
  A Task object based on the proposal result.
35
34
  """
36
35
  if not prompt:
37
- logger.error(err := f"{self.name}: Prompt must be provided.")
36
+ logger.error(err := "Prompt must be provided.")
38
37
  raise ValueError(err)
39
38
 
40
- return await self.propose(Task, prompt, **self.prepend_sys_msg(cast("Dict[str, Any]", kwargs)))
39
+ return await self.propose(Task, prompt, **kwargs)
41
40
 
42
41
 
43
- class HandleTask(WithBriefing, ToolBoxUsage):
42
+ class HandleTask(ToolBoxUsage):
44
43
  """A class that handles a task based on a task object."""
45
44
 
46
45
  async def draft_tool_usage_code(
@@ -54,7 +53,7 @@ class HandleTask(WithBriefing, ToolBoxUsage):
54
53
  logger.info(f"Drafting tool usage code for task: {task.briefing}")
55
54
 
56
55
  if not tools:
57
- err = f"{self.name}: Tools must be provided to draft the tool usage code."
56
+ err = "Tools must be provided to draft the tool usage code."
58
57
  logger.error(err)
59
58
  raise ValueError(err)
60
59
 
@@ -81,7 +80,7 @@ class HandleTask(WithBriefing, ToolBoxUsage):
81
80
  return await self.aask_validate(
82
81
  question=q,
83
82
  validator=_validator,
84
- **self.prepend_sys_msg(cast("Dict[str, Any]", kwargs)),
83
+ **kwargs,
85
84
  )
86
85
 
87
86
  async def handle_fine_grind(
@@ -96,7 +95,7 @@ class HandleTask(WithBriefing, ToolBoxUsage):
96
95
  logger.info(f"Handling task: \n{task.briefing}")
97
96
 
98
97
  tools = await self.gather_tools_fine_grind(task, box_choose_kwargs, tool_choose_kwargs)
99
- logger.info(f"{self.name} have gathered {[t.name for t in tools]}")
98
+ logger.info(f"Gathered {[t.name for t in tools]}")
100
99
 
101
100
  if tools and (pack := await self.draft_tool_usage_code(task, tools, data, **kwargs)):
102
101
  executor = ToolExecutor(candidates=tools, data=data)
fabricatio/config.py CHANGED
@@ -229,15 +229,23 @@ class TemplateConfig(BaseModel):
229
229
  generic_string_template: str = Field(default="generic_string")
230
230
  """The name of the generic string template which will be used to review a string."""
231
231
 
232
- correct_template: str = Field(default="correct")
233
- """The name of the correct template which will be used to correct a string."""
234
-
235
232
  co_validation_template: str = Field(default="co_validation")
236
233
  """The name of the co-validation template which will be used to co-validate a string."""
237
234
 
238
235
  as_prompt_template: str = Field(default="as_prompt")
239
236
  """The name of the as prompt template which will be used to convert a string to a prompt."""
240
237
 
238
+ check_string_template: str = Field(default="check_string")
239
+ """The name of the check string template which will be used to check a string."""
240
+
241
+ ruleset_requirement_breakdown_template: str = Field(default="ruleset_requirement_breakdown")
242
+ """The name of the ruleset requirement breakdown template which will be used to breakdown a ruleset requirement."""
243
+
244
+ fix_troubled_obj_template: str = Field(default="fix_troubled_obj")
245
+ """The name of the fix troubled object template which will be used to fix a troubled object."""
246
+
247
+ fix_troubled_string_template: str = Field(default="fix_troubled_string")
248
+ """The name of the fix troubled string template which will be used to fix a troubled string."""
241
249
 
242
250
  class MagikaConfig(BaseModel):
243
251
  """Magika configuration class."""
@@ -9,16 +9,14 @@ from abc import abstractmethod
9
9
  from asyncio import Queue, create_task
10
10
  from typing import Any, Dict, Self, Tuple, Type, Union, final
11
11
 
12
- from fabricatio.capabilities.correct import Correct
13
- from fabricatio.capabilities.task import HandleTask, ProposeTask
14
12
  from fabricatio.journal import logger
15
13
  from fabricatio.models.generic import WithBriefing
16
14
  from fabricatio.models.task import Task
17
- from fabricatio.models.usages import ToolBoxUsage
15
+ from fabricatio.models.usages import LLMUsage, ToolBoxUsage
18
16
  from pydantic import Field, PrivateAttr
19
17
 
20
18
 
21
- class Action(HandleTask, ProposeTask, Correct):
19
+ class Action(WithBriefing, LLMUsage):
22
20
  """Class that represents an action to be executed in a workflow.
23
21
 
24
22
  Actions are the atomic units of work in a workflow. Each action performs
@@ -98,13 +96,18 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
98
96
  a shared context between them and handling task lifecycle events.
99
97
  """
100
98
 
99
+ description: str = ""
100
+ """The description of the workflow, which describes the workflow's purpose and requirements."""
101
+
101
102
  _context: Queue[Dict[str, Any]] = PrivateAttr(default_factory=lambda: Queue(maxsize=1))
102
103
  """Queue for storing the workflow execution context."""
103
104
 
104
105
  _instances: Tuple[Action, ...] = PrivateAttr(default_factory=tuple)
105
106
  """Instantiated action objects to be executed in this workflow."""
106
107
 
107
- steps: Tuple[Union[Type[Action], Action], ...] = Field(frozen=True,)
108
+ steps: Tuple[Union[Type[Action], Action], ...] = Field(
109
+ frozen=True,
110
+ )
108
111
  """The sequence of actions to be executed, can be action classes or instances."""
109
112
 
110
113
  task_input_key: str = Field(default="task_input")
@@ -0,0 +1,25 @@
1
+ """A module containing kwargs types for content correction and checking operations."""
2
+ from fabricatio.models.extra.problem import Improvement
3
+ from fabricatio.models.extra.rule import RuleSet
4
+ from fabricatio.models.generic import SketchedAble
5
+ from fabricatio.models.kwargs_types import ReferencedKwargs
6
+
7
+
8
+ class CorrectKwargs[T: SketchedAble](ReferencedKwargs[T], total=False):
9
+ """Arguments for content correction operations.
10
+
11
+ Extends GenerateKwargs with parameters for correcting content based on
12
+ specific criteria and templates.
13
+ """
14
+
15
+ improvement: Improvement
16
+
17
+
18
+ class CheckKwargs(ReferencedKwargs[Improvement], total=False):
19
+ """Arguments for content checking operations.
20
+
21
+ Extends GenerateKwargs with parameters for checking content against
22
+ specific criteria and templates.
23
+ """
24
+
25
+ ruleset: RuleSet
@@ -2,23 +2,26 @@
2
2
 
3
3
  from typing import List
4
4
 
5
- from fabricatio.models.generic import ProposedAble
5
+ from fabricatio.models.generic import Display, ProposedAble
6
6
 
7
7
 
8
- class JudgeMent(ProposedAble):
8
+ class JudgeMent(ProposedAble, Display):
9
9
  """Represents a judgment result containing supporting/denying evidence and final verdict.
10
10
 
11
- The class stores both affirmative and denies evidence lists along with the final boolean judgment.
11
+ The class stores both affirmative and denies evidence, truth and reasons lists along with the final boolean judgment.
12
12
  """
13
13
 
14
- affirm_evidence: List[str]
15
- """List of evidence supporting the affirmation."""
14
+ issue_to_judge: str
15
+ """The issue to be judged"""
16
16
 
17
17
  deny_evidence: List[str]
18
- """List of evidence supporting the denial."""
18
+ """List of clues supporting the denial."""
19
+
20
+ affirm_evidence: List[str]
21
+ """List of clues supporting the affirmation."""
19
22
 
20
23
  final_judgement: bool
21
- """The final judgment made according to all extracted evidence."""
24
+ """The final judgment made according to all extracted clues."""
22
25
 
23
26
  def __bool__(self) -> bool:
24
27
  """Return the final judgment value.