fabricatio 0.2.8.dev3__cp312-cp312-win_amd64.whl → 0.2.9.dev0__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 +4 -11
  2. fabricatio/actions/__init__.py +1 -0
  3. fabricatio/actions/article.py +63 -87
  4. fabricatio/actions/article_rag.py +54 -43
  5. fabricatio/actions/rag.py +2 -1
  6. fabricatio/actions/rules.py +39 -0
  7. fabricatio/capabilities/__init__.py +1 -0
  8. fabricatio/capabilities/censor.py +90 -0
  9. fabricatio/capabilities/check.py +127 -29
  10. fabricatio/capabilities/correct.py +143 -100
  11. fabricatio/capabilities/rag.py +5 -4
  12. fabricatio/capabilities/rating.py +65 -16
  13. fabricatio/capabilities/review.py +1 -1
  14. fabricatio/capabilities/task.py +2 -1
  15. fabricatio/config.py +11 -3
  16. fabricatio/models/action.py +14 -7
  17. fabricatio/models/adv_kwargs_types.py +25 -0
  18. fabricatio/models/extra/__init__.py +1 -0
  19. fabricatio/models/extra/advanced_judge.py +5 -2
  20. fabricatio/models/extra/article_base.py +3 -20
  21. fabricatio/models/extra/article_main.py +2 -3
  22. fabricatio/models/extra/patches.py +20 -0
  23. fabricatio/models/extra/problem.py +41 -8
  24. fabricatio/models/extra/rule.py +26 -9
  25. fabricatio/models/generic.py +310 -55
  26. fabricatio/models/kwargs_types.py +23 -17
  27. fabricatio/models/task.py +1 -1
  28. fabricatio/models/tool.py +149 -14
  29. fabricatio/models/usages.py +50 -42
  30. fabricatio/parser.py +7 -8
  31. fabricatio/rust.cp312-win_amd64.pyd +0 -0
  32. fabricatio/{_rust_instances.py → rust_instances.py} +1 -1
  33. fabricatio/workflows/__init__.py +1 -0
  34. fabricatio-0.2.9.dev0.data/scripts/tdown.exe +0 -0
  35. {fabricatio-0.2.8.dev3.dist-info → fabricatio-0.2.9.dev0.dist-info}/METADATA +1 -1
  36. fabricatio-0.2.9.dev0.dist-info/RECORD +61 -0
  37. fabricatio/_rust.cp312-win_amd64.pyd +0 -0
  38. fabricatio-0.2.8.dev3.data/scripts/tdown.exe +0 -0
  39. fabricatio-0.2.8.dev3.dist-info/RECORD +0 -53
  40. /fabricatio/{_rust.pyi → rust.pyi} +0 -0
  41. {fabricatio-0.2.8.dev3.dist-info → fabricatio-0.2.9.dev0.dist-info}/WHEEL +0 -0
  42. {fabricatio-0.2.8.dev3.dist-info → fabricatio-0.2.9.dev0.dist-info}/licenses/LICENSE +0 -0
@@ -1,10 +1,12 @@
1
1
  """A class that provides the capability to check strings and objects against rules and guidelines."""
2
+
2
3
  from typing import Optional, Unpack
3
4
 
4
5
  from fabricatio import TEMPLATE_MANAGER
5
6
  from fabricatio.capabilities.advanced_judge import AdvancedJudge
6
7
  from fabricatio.capabilities.propose import Propose
7
8
  from fabricatio.config import configs
9
+ from fabricatio.models.extra.patches import RuleSetBriefingPatch
8
10
  from fabricatio.models.extra.problem import Improvement
9
11
  from fabricatio.models.extra.rule import Rule, RuleSet
10
12
  from fabricatio.models.generic import Display, WithBriefing
@@ -13,49 +15,80 @@ from fabricatio.utils import override_kwargs
13
15
 
14
16
 
15
17
  class Check(AdvancedJudge, Propose):
16
- """Class that provides the capability to validate strings/objects against predefined rules and guidelines."""
18
+ """Class for validating strings/objects against predefined rules and guidelines.
19
+
20
+ This capability combines rule-based judgment and proposal generation to provide
21
+ structured validation results with actionable improvement suggestions.
22
+ """
17
23
 
18
24
  async def draft_ruleset(
19
- self, ruleset_requirement: str, **kwargs: Unpack[ValidateKwargs[RuleSet]]
25
+ self, ruleset_requirement: str, rule_count: int = 0, **kwargs: Unpack[ValidateKwargs[Rule]]
20
26
  ) -> Optional[RuleSet]:
21
- """Generate a rule set based on specified requirements.
27
+ """Generate rule set based on requirement description.
22
28
 
23
29
  Args:
24
- ruleset_requirement (str): Description of desired rule set characteristics
25
- **kwargs: Validation configuration parameters
30
+ ruleset_requirement (str): Natural language description of desired ruleset characteristics
31
+ rule_count (int): Number of rules to generate (0 for default count)
32
+ **kwargs: Validation parameters for rule generation
26
33
 
27
34
  Returns:
28
- Optional[RuleSet]: Generated rule set if successful
35
+ Optional[RuleSet]: Validated ruleset object or None if generation fails
36
+
37
+ Notes:
38
+ - Requires valid template configuration in configs.templates
39
+ - Returns None if any step in rule generation fails
40
+ - Uses `alist_str` for requirement breakdown and iterative rule proposal
29
41
  """
30
- return await self.propose(RuleSet, ruleset_requirement, **kwargs)
42
+ rule_reqs = await self.alist_str(
43
+ TEMPLATE_MANAGER.render_template(
44
+ configs.templates.ruleset_requirement_breakdown_template, {"ruleset_requirement": ruleset_requirement}
45
+ ),
46
+ rule_count,
47
+ **override_kwargs(kwargs, default=None),
48
+ )
31
49
 
32
- async def draft_rule(self, rule_requirement: str, **kwargs: Unpack[ValidateKwargs[Rule]]) -> Optional[Rule]:
33
- """Create a specific rule based on given specifications.
50
+ if rule_reqs is None:
51
+ return None
34
52
 
35
- Args:
36
- rule_requirement (str): Detailed rule description requirements
37
- **kwargs: Validation configuration parameters
53
+ rules = await self.propose(Rule, [TEMPLATE_MANAGER.render_template(configs.templates.rule_requirement_template, {"rule_requirement": r}) for r in rule_reqs], **kwargs)
54
+ if any(r for r in rules if r is None):
55
+ return None
38
56
 
39
- Returns:
40
- Optional[Rule]: Generated rule instance if successful
41
- """
42
- return await self.propose(Rule, rule_requirement, **kwargs)
57
+ ruleset_patch = await self.propose(
58
+ RuleSetBriefingPatch,
59
+ f"# Rules Requirements\n{rule_reqs}\n# Generated Rules\n{Display.seq_display(rules)}\n\n"
60
+ f"You need to write a concise and detailed patch for this ruleset that can be applied to the ruleset nicely.\n"
61
+ f"Note that all fields in this patch will be directly copied to the ruleset obj, including `name` and `description`, so write when knowing the subject.\n",
62
+ **override_kwargs(kwargs, default=None),
63
+ )
43
64
 
44
- async def check_string(
65
+ if ruleset_patch is None:
66
+ return None
67
+
68
+ return RuleSet(rules=rules, **ruleset_patch.as_kwargs())
69
+
70
+ async def check_string_against_rule(
45
71
  self,
46
72
  input_text: str,
47
73
  rule: Rule,
74
+ reference: str = "",
48
75
  **kwargs: Unpack[ValidateKwargs[Improvement]],
49
76
  ) -> Optional[Improvement]:
50
- """Evaluate text against a specific rule.
77
+ """Validate text against specific rule.
51
78
 
52
79
  Args:
53
- input_text (str): Text content to be evaluated
54
- rule (Rule): Rule instance used for validation
55
- **kwargs: Validation configuration parameters
80
+ input_text (str): Text content to validate
81
+ rule (Rule): Rule instance for validation
82
+ reference (str): Reference text for comparison (default: "")
83
+ **kwargs: Configuration for validation process
56
84
 
57
85
  Returns:
58
- Optional[Improvement]: Suggested improvement if violations found, else None
86
+ Optional[Improvement]: Suggested improvement if violation detected
87
+
88
+ Notes:
89
+ - Uses `evidently_judge` to determine violation presence
90
+ - Renders template using `check_string_template` for proposal
91
+ - Proposes Improvement only when violation is confirmed
59
92
  """
60
93
  if judge := await self.evidently_judge(
61
94
  f"# Content to exam\n{input_text}\n\n# Rule Must to follow\n{rule.display()}\nDoes `Content to exam` provided above violate the `Rule Must to follow` provided above?",
@@ -65,27 +98,34 @@ class Check(AdvancedJudge, Propose):
65
98
  Improvement,
66
99
  TEMPLATE_MANAGER.render_template(
67
100
  configs.templates.check_string_template,
68
- {"to_check": input_text, "rule": rule, "judge": judge.display()},
101
+ {"to_check": input_text, "rule": rule, "judge": judge.display(), "reference": reference},
69
102
  ),
70
103
  **kwargs,
71
104
  )
72
105
  return None
73
106
 
74
- async def check_obj[M: (Display, WithBriefing)](
107
+ async def check_obj_against_rule[M: (Display, WithBriefing)](
75
108
  self,
76
109
  obj: M,
77
110
  rule: Rule,
111
+ reference: str = "",
78
112
  **kwargs: Unpack[ValidateKwargs[Improvement]],
79
113
  ) -> Optional[Improvement]:
80
- """Validate an object against specified rule.
114
+ """Validate object against rule using text representation.
81
115
 
82
116
  Args:
83
- obj (M): Object implementing Display or WithBriefing interface
84
- rule (Rule): Validation rule to apply
117
+ obj (M): Object implementing Display/WithBriefing interface
118
+ rule (Rule): Validation rule
119
+ reference (str): Reference text for comparison (default: "")
85
120
  **kwargs: Validation configuration parameters
86
121
 
87
122
  Returns:
88
- Optional[Improvement]: Improvement suggestion if issues detected
123
+ Optional[Improvement]: Improvement suggestion if issues found
124
+
125
+ Notes:
126
+ - Requires obj to implement display() or briefing property
127
+ - Raises TypeError for incompatible object types
128
+ - Converts object to text before string validation
89
129
  """
90
130
  if isinstance(obj, Display):
91
131
  input_text = obj.display()
@@ -94,4 +134,62 @@ class Check(AdvancedJudge, Propose):
94
134
  else:
95
135
  raise TypeError("obj must be either Display or WithBriefing")
96
136
 
97
- return await self.check_string(input_text, rule, **kwargs)
137
+ return await self.check_string_against_rule(input_text, rule, reference, **kwargs)
138
+
139
+ async def check_string(
140
+ self,
141
+ input_text: str,
142
+ ruleset: RuleSet,
143
+ reference: str = "",
144
+ **kwargs: Unpack[ValidateKwargs[Improvement]],
145
+ ) -> Optional[Improvement]:
146
+ """Validate text against full ruleset.
147
+
148
+ Args:
149
+ input_text (str): Text content to validate
150
+ ruleset (RuleSet): Collection of validation rules
151
+ reference (str): Reference text for comparison
152
+ **kwargs: Validation configuration parameters
153
+
154
+ Returns:
155
+ Optional[Improvement]: First detected improvement
156
+
157
+ Notes:
158
+ - Checks rules sequentially and returns first violation
159
+ - Halts validation after first successful improvement proposal
160
+ - Maintains rule execution order from ruleset.rules list
161
+ """
162
+ imp_seq = [
163
+ await self.check_string_against_rule(input_text, rule, reference, **kwargs) for rule in ruleset.rules
164
+ ]
165
+ if all(isinstance(i, Improvement) for i in imp_seq):
166
+ return Improvement.gather(*imp_seq) # pyright: ignore [reportArgumentType]
167
+ return None
168
+
169
+ async def check_obj[M: (Display, WithBriefing)](
170
+ self,
171
+ obj: M,
172
+ ruleset: RuleSet,
173
+ reference: str = "",
174
+ **kwargs: Unpack[ValidateKwargs[Improvement]],
175
+ ) -> Optional[Improvement]:
176
+ """Validate object against full ruleset.
177
+
178
+ Args:
179
+ obj (M): Object implementing Display/WithBriefing interface
180
+ ruleset (RuleSet): Collection of validation rules
181
+ reference (str): Reference text for comparison (default: "")
182
+ **kwargs: Validation configuration parameters
183
+
184
+ Returns:
185
+ Optional[Improvement]: First detected improvement
186
+
187
+ Notes:
188
+ - Uses check_obj_against_rule for individual rule checks
189
+ - Maintains same early termination behavior as check_string
190
+ - Validates object through text conversion mechanism
191
+ """
192
+ imp_seq = [await self.check_obj_against_rule(obj, rule, reference, **kwargs) for rule in ruleset.rules]
193
+ if all(isinstance(i, Improvement) for i in imp_seq):
194
+ return Improvement.gather(*imp_seq) # pyright: ignore [reportArgumentType]
195
+ return None
@@ -1,160 +1,203 @@
1
- """Correct capability module providing advanced review and validation functionality.
1
+ """A module containing the Correct capability for reviewing, validating, and improving objects."""
2
2
 
3
- This module implements the Correct capability, which extends the Review functionality
4
- to provide mechanisms for reviewing, validating, and correcting various objects and tasks
5
- based on predefined criteria and templates.
6
- """
3
+ from typing import Optional, Type, Unpack, cast
7
4
 
8
- from typing import Optional, Unpack, cast
9
-
10
- from fabricatio._rust_instances import TEMPLATE_MANAGER
11
- from fabricatio.capabilities.review import Review
5
+ from fabricatio.capabilities.propose import Propose
6
+ from fabricatio.capabilities.rating import Rating
12
7
  from fabricatio.config import configs
13
- from fabricatio.models.extra.problem import Improvement
14
- from fabricatio.models.generic import CensoredAble, Display, ProposedAble, ProposedUpdateAble, WithBriefing
15
- from fabricatio.models.kwargs_types import CensoredCorrectKwargs, CorrectKwargs, ReviewKwargs
16
- from fabricatio.models.task import Task
17
- from questionary import confirm, text
18
- from rich import print as rprint
8
+ from fabricatio.journal import logger
9
+ from fabricatio.models.adv_kwargs_types import CorrectKwargs
10
+ from fabricatio.models.extra.problem import Improvement, ProblemSolutions
11
+ from fabricatio.models.generic import ProposedUpdateAble, SketchedAble
12
+ from fabricatio.models.kwargs_types import (
13
+ BestKwargs,
14
+ ValidateKwargs,
15
+ )
16
+ from fabricatio.rust_instances import TEMPLATE_MANAGER
17
+ from fabricatio.utils import ok, override_kwargs
18
+
19
+
20
+ class Correct(Rating, Propose):
21
+ """A class that provides the capability to correct objects."""
22
+
23
+ async def decide_solution(
24
+ self, problem_solutions: ProblemSolutions, **kwargs: Unpack[BestKwargs]
25
+ ) -> ProblemSolutions:
26
+ """Decide the best solution from a list of problem solutions.
27
+
28
+ Args:
29
+ problem_solutions (ProblemSolutions): The problem solutions to evaluate.
30
+ **kwargs (Unpack[BestKwargs]): Additional keyword arguments for the decision process.
19
31
 
32
+ Returns:
33
+ ProblemSolutions: The problem solutions with the best solution selected.
34
+ """
35
+ if (leng := len(problem_solutions.solutions)) == 0:
36
+ logger.error(f"No solutions found in ProblemSolutions, Skip: {problem_solutions.problem}")
37
+ if leng > 1:
38
+ problem_solutions.solutions = await self.best(problem_solutions.solutions, **kwargs)
39
+ return problem_solutions
20
40
 
21
- class Correct(Review):
22
- """Correct capability for reviewing, validating, and improving objects.
41
+ async def decide_improvement(self, improvement: Improvement, **kwargs: Unpack[BestKwargs]) -> Improvement:
42
+ """Decide the best solution for each problem solution in an improvement.
23
43
 
24
- This class enhances the Review capability with specialized functionality for
25
- correcting and improving objects based on review feedback. It can process
26
- various inputs including tasks, strings, and generic objects that implement
27
- the required interfaces, applying corrections based on templated review processes.
28
- """
44
+ Args:
45
+ improvement (Improvement): The improvement containing problem solutions to evaluate.
46
+ **kwargs (Unpack[BestKwargs]): Additional keyword arguments for the decision process.
29
47
 
30
- async def correct_obj[M: ProposedAble](
48
+ Returns:
49
+ Improvement: The improvement with the best solutions selected for each problem solution.
50
+ """
51
+ if (leng := len(improvement.problem_solutions)) == 0:
52
+ logger.error(f"No problem_solutions found in Improvement, Skip: {improvement}")
53
+ if leng > 1:
54
+ for ps in improvement.problem_solutions:
55
+ ps.solutions = await self.best(ps.solutions, **kwargs)
56
+ return improvement
57
+
58
+ async def fix_troubled_obj[M: SketchedAble](
31
59
  self,
32
60
  obj: M,
61
+ problem_solutions: ProblemSolutions,
33
62
  reference: str = "",
34
- supervisor_check: bool = True,
35
- **kwargs: Unpack[ReviewKwargs[Improvement]],
63
+ **kwargs: Unpack[ValidateKwargs[M]],
36
64
  ) -> Optional[M]:
37
- """Review and correct an object based on defined criteria and templates.
38
-
39
- This method first conducts a review of the given object, then uses the review results
40
- to generate a corrected version of the object using appropriate templates.
65
+ """Fix a troubled object based on problem solutions.
41
66
 
42
67
  Args:
43
- obj (M): The object to be reviewed and corrected. Must implement ProposedAble.
68
+ obj (M): The object to be fixed.
69
+ problem_solutions (ProblemSolutions): The problem solutions to apply.
44
70
  reference (str): A reference or contextual information for the object.
45
- supervisor_check (bool, optional): Whether to perform a supervisor check on the review results. Defaults to True.
46
- **kwargs: Review configuration parameters including criteria and review options.
71
+ **kwargs (Unpack[ValidateKwargs[M]]): Additional keyword arguments for the validation process.
47
72
 
48
73
  Returns:
49
- Optional[M]: A corrected version of the input object, or None if correction fails.
50
-
51
- Raises:
52
- TypeError: If the provided object doesn't implement Display or WithBriefing interfaces.
74
+ Optional[M]: The fixed object, or None if fixing fails.
53
75
  """
54
- if not isinstance(obj, (Display, WithBriefing)):
55
- raise TypeError(f"Expected Display or WithBriefing, got {type(obj)}")
56
-
57
- review_res = await self.review_obj(obj, **kwargs)
58
- if supervisor_check:
59
- await review_res.supervisor_check()
60
- if "default" in kwargs:
61
- cast("ReviewKwargs[None]", kwargs)["default"] = None
62
76
  return await self.propose(
63
- obj.__class__,
77
+ cast("Type[M]", obj.__class__),
64
78
  TEMPLATE_MANAGER.render_template(
65
- configs.templates.correct_template,
79
+ configs.templates.fix_troubled_obj_template,
66
80
  {
67
- "content": f"{(reference + '\n\nAbove is referencing material') if reference else ''}{obj.display() if isinstance(obj, Display) else obj.briefing}",
68
- "review": review_res.display(),
81
+ "problem": problem_solutions.problem,
82
+ "solution": ok(
83
+ problem_solutions.final_solution(),
84
+ f"No solution found for problem: {problem_solutions.problem}",
85
+ ),
86
+ "reference": reference,
69
87
  },
70
88
  ),
71
89
  **kwargs,
72
90
  )
73
91
 
74
- async def correct_string(
75
- self, input_text: str, supervisor_check: bool = True, **kwargs: Unpack[ReviewKwargs[Improvement]]
92
+ async def fix_troubled_string(
93
+ self,
94
+ input_text: str,
95
+ problem_solutions: ProblemSolutions,
96
+ reference: str = "",
97
+ **kwargs: Unpack[ValidateKwargs[str]],
76
98
  ) -> Optional[str]:
77
- """Review and correct a string based on defined criteria and templates.
78
-
79
- This method applies the review process to the input text and generates
80
- a corrected version based on the review results.
99
+ """Fix a troubled string based on problem solutions.
81
100
 
82
101
  Args:
83
- input_text (str): The text content to be reviewed and corrected.
84
- supervisor_check (bool, optional): Whether to perform a supervisor check on the review results. Defaults to True.
85
- **kwargs: Review configuration parameters including criteria and review options.
102
+ input_text (str): The string to be fixed.
103
+ problem_solutions (ProblemSolutions): The problem solutions to apply.
104
+ reference (str): A reference or contextual information for the string.
105
+ **kwargs (Unpack[ValidateKwargs[str]]): Additional keyword arguments for the validation process.
86
106
 
87
107
  Returns:
88
- Optional[str]: The corrected text content, or None if correction fails.
108
+ Optional[str]: The fixed string, or None if fixing fails.
89
109
  """
90
- review_res = await self.review_string(input_text, **kwargs)
91
- if supervisor_check:
92
- await review_res.supervisor_check()
93
-
94
- if "default" in kwargs:
95
- cast("ReviewKwargs[None]", kwargs)["default"] = None
96
110
  return await self.ageneric_string(
97
111
  TEMPLATE_MANAGER.render_template(
98
- configs.templates.correct_template, {"content": input_text, "review": review_res.display()}
112
+ configs.templates.fix_troubled_string_template,
113
+ {
114
+ "problem": problem_solutions.problem,
115
+ "solution": ok(
116
+ problem_solutions.final_solution(),
117
+ f"No solution found for problem: {problem_solutions.problem}",
118
+ ),
119
+ "reference": reference,
120
+ "string_to_fix": input_text,
121
+ },
99
122
  ),
100
123
  **kwargs,
101
124
  )
102
125
 
103
- async def correct_task[T](
104
- self, task: Task[T], **kwargs: Unpack[CorrectKwargs[Improvement]]
105
- ) -> Optional[Task[T]]:
106
- """Review and correct a task object based on defined criteria.
126
+ async def correct_obj[M: SketchedAble](
127
+ self,
128
+ obj: M,
129
+ improvement: Improvement,
130
+ reference: str = "",
131
+ **kwargs: Unpack[ValidateKwargs[M]],
132
+ ) -> Optional[M]:
133
+ """Review and correct an object based on defined criteria and templates.
107
134
 
108
- This is a specialized version of correct_obj specifically for Task objects,
109
- applying the same review and correction process to task definitions.
135
+ This method first conducts a review of the given object, then uses the review results
136
+ to generate a corrected version of the object using appropriate templates.
110
137
 
111
138
  Args:
112
- task (Task[T]): The task to be reviewed and corrected.
113
- **kwargs: Review configuration parameters including criteria and review options.
139
+ obj (M): The object to be reviewed and corrected. Must implement ProposedAble.
140
+ improvement (Improvement): The improvement object containing the review results.
141
+ reference (str): A reference or contextual information for the object.
142
+ **kwargs (Unpack[ValidateKwargs[M]]): Review configuration parameters including criteria and review options.
114
143
 
115
144
  Returns:
116
- Optional[Task[T]]: The corrected task, or None if correction fails.
145
+ Optional[M]: A corrected version of the input object, or None if correction fails.
146
+
147
+ Raises:
148
+ TypeError: If the provided object doesn't implement Display or WithBriefing interfaces.
117
149
  """
118
- return await self.correct_obj(task, **kwargs)
150
+ if not improvement.decided():
151
+ improvement = await self.decide_improvement(improvement, **override_kwargs(kwargs, default=None))
152
+
153
+ for ps in improvement.problem_solutions:
154
+ fixed_obj = await self.fix_troubled_obj(obj, ps, reference, **kwargs)
155
+ if fixed_obj is None:
156
+ logger.error(
157
+ f"Failed to fix troubling obj {obj.__class__.__name__} when deal with problem: {ps.problem}",
158
+ )
159
+ return None
160
+ obj = fixed_obj
161
+ return obj
162
+
163
+ async def correct_string(
164
+ self, input_text: str, improvement: Improvement, reference: str = "", **kwargs: Unpack[ValidateKwargs[str]]
165
+ ) -> Optional[str]:
166
+ """Review and correct a string based on defined criteria and templates.
119
167
 
120
- async def censor_obj[M: CensoredAble](
121
- self, obj: M, **kwargs: Unpack[CensoredCorrectKwargs[Improvement]]
122
- ) -> M:
123
- """Censor and correct an object based on defined criteria and templates.
168
+ This method first conducts a review of the given string, then uses the review results
169
+ to generate a corrected version of the string using appropriate templates.
124
170
 
125
171
  Args:
126
- obj (M): The object to be reviewed and corrected.
127
- **kwargs (Unpack[CensoredCorrectKwargs]): Additional keyword
172
+ input_text (str): The string to be reviewed and corrected.
173
+ improvement (Improvement): The improvement object containing the review results.
174
+ reference (str): A reference or contextual information for the string.
175
+ **kwargs (Unpack[ValidateKwargs[str]]): Review configuration parameters including criteria and review options.
128
176
 
129
177
  Returns:
130
- M: The censored and corrected object.
178
+ Optional[str]: A corrected version of the input string, or None if correction fails.
131
179
  """
132
- last_modified_obj = obj
133
- modified_obj = None
134
- rprint(obj.finalized_dump())
135
- while await confirm("Begin to correct obj above with human censorship?").ask_async():
136
- while (topic := await text("What is the topic of the obj reviewing?").ask_async()) is not None and topic:
137
- ...
138
- if (
139
- modified_obj := await self.correct_obj(
140
- last_modified_obj,
141
- topic=topic,
142
- **kwargs,
180
+ if not improvement.decided():
181
+ improvement = await self.decide_improvement(improvement, **override_kwargs(kwargs, default=None))
182
+
183
+ for ps in improvement.problem_solutions:
184
+ fixed_string = await self.fix_troubled_string(input_text, ps, reference, **kwargs)
185
+ if fixed_string is None:
186
+ logger.error(
187
+ f"Failed to fix troubling string when deal with problem: {ps.problem}",
143
188
  )
144
- ) is None:
145
- break
146
- last_modified_obj = modified_obj
147
- rprint(last_modified_obj.finalized_dump())
148
- return modified_obj or last_modified_obj
189
+ return None
190
+ input_text = fixed_string
191
+ return input_text
149
192
 
150
193
  async def correct_obj_inplace[M: ProposedUpdateAble](
151
- self, obj: M, **kwargs: Unpack[CorrectKwargs[Improvement]]
194
+ self, obj: M, **kwargs: Unpack[CorrectKwargs[M]]
152
195
  ) -> Optional[M]:
153
196
  """Correct an object in place based on defined criteria and templates.
154
197
 
155
198
  Args:
156
199
  obj (M): The object to be corrected.
157
- **kwargs (Unpack[CensoredCorrectKwargs]): Additional keyword arguments for the correction process.
200
+ **kwargs (Unpack[CorrectKwargs[M]]): Additional keyword arguments for the correction process.
158
201
 
159
202
  Returns:
160
203
  Optional[M]: The corrected object, or None if correction fails.
@@ -3,14 +3,16 @@
3
3
  try:
4
4
  from pymilvus import MilvusClient
5
5
  except ImportError as e:
6
- raise RuntimeError("pymilvus is not installed. Have you installed `fabricatio[rag]` instead of `fabricatio`") from e
6
+ raise RuntimeError("pymilvus is not installed. Have you installed `fabricatio[rag]` instead of `fabricatio`?") from e
7
7
  from functools import lru_cache
8
8
  from operator import itemgetter
9
9
  from os import PathLike
10
10
  from pathlib import Path
11
11
  from typing import Any, Callable, Dict, List, Optional, Self, Union, Unpack, cast, overload
12
12
 
13
- from fabricatio._rust_instances import TEMPLATE_MANAGER
13
+ from more_itertools.recipes import flatten, unique
14
+ from pydantic import Field, PrivateAttr
15
+
14
16
  from fabricatio.config import configs
15
17
  from fabricatio.journal import logger
16
18
  from fabricatio.models.kwargs_types import (
@@ -23,9 +25,8 @@ from fabricatio.models.kwargs_types import (
23
25
  )
24
26
  from fabricatio.models.usages import EmbeddingUsage
25
27
  from fabricatio.models.utils import MilvusData
28
+ from fabricatio.rust_instances import TEMPLATE_MANAGER
26
29
  from fabricatio.utils import ok
27
- from more_itertools.recipes import flatten, unique
28
- from pydantic import Field, PrivateAttr
29
30
 
30
31
 
31
32
  @lru_cache(maxsize=None)