fabricatio 0.2.8.dev3__cp312-cp312-win_amd64.whl → 0.2.9__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 (48) hide show
  1. fabricatio/__init__.py +4 -11
  2. fabricatio/actions/__init__.py +1 -0
  3. fabricatio/actions/article.py +128 -165
  4. fabricatio/actions/article_rag.py +62 -46
  5. fabricatio/actions/output.py +60 -4
  6. fabricatio/actions/rag.py +2 -1
  7. fabricatio/actions/rules.py +72 -0
  8. fabricatio/capabilities/__init__.py +1 -0
  9. fabricatio/capabilities/censor.py +104 -0
  10. fabricatio/capabilities/check.py +148 -32
  11. fabricatio/capabilities/correct.py +162 -100
  12. fabricatio/capabilities/rag.py +5 -4
  13. fabricatio/capabilities/rating.py +109 -54
  14. fabricatio/capabilities/review.py +1 -1
  15. fabricatio/capabilities/task.py +2 -1
  16. fabricatio/config.py +14 -6
  17. fabricatio/fs/readers.py +20 -1
  18. fabricatio/models/action.py +63 -41
  19. fabricatio/models/adv_kwargs_types.py +25 -0
  20. fabricatio/models/extra/__init__.py +1 -0
  21. fabricatio/models/extra/advanced_judge.py +7 -4
  22. fabricatio/models/extra/article_base.py +125 -79
  23. fabricatio/models/extra/article_main.py +101 -19
  24. fabricatio/models/extra/article_outline.py +2 -3
  25. fabricatio/models/extra/article_proposal.py +15 -14
  26. fabricatio/models/extra/patches.py +20 -0
  27. fabricatio/models/extra/problem.py +64 -23
  28. fabricatio/models/extra/rule.py +39 -10
  29. fabricatio/models/generic.py +405 -75
  30. fabricatio/models/kwargs_types.py +23 -17
  31. fabricatio/models/task.py +1 -1
  32. fabricatio/models/tool.py +149 -14
  33. fabricatio/models/usages.py +55 -56
  34. fabricatio/parser.py +12 -13
  35. fabricatio/rust.cp312-win_amd64.pyd +0 -0
  36. fabricatio/{_rust.pyi → rust.pyi} +42 -4
  37. fabricatio/{_rust_instances.py → rust_instances.py} +1 -1
  38. fabricatio/utils.py +5 -5
  39. fabricatio/workflows/__init__.py +1 -0
  40. fabricatio/workflows/articles.py +3 -5
  41. fabricatio-0.2.9.data/scripts/tdown.exe +0 -0
  42. {fabricatio-0.2.8.dev3.dist-info → fabricatio-0.2.9.dist-info}/METADATA +1 -1
  43. fabricatio-0.2.9.dist-info/RECORD +61 -0
  44. fabricatio/_rust.cp312-win_amd64.pyd +0 -0
  45. fabricatio-0.2.8.dev3.data/scripts/tdown.exe +0 -0
  46. fabricatio-0.2.8.dev3.dist-info/RECORD +0 -53
  47. {fabricatio-0.2.8.dev3.dist-info → fabricatio-0.2.9.dist-info}/WHEEL +0 -0
  48. {fabricatio-0.2.8.dev3.dist-info → fabricatio-0.2.9.dist-info}/licenses/LICENSE +0 -0
@@ -1,52 +1,57 @@
1
1
  """A class representing a problem-solution pair identified during a review process."""
2
2
 
3
- from typing import List, Literal, Self
3
+ from itertools import chain
4
+ from typing import Any, List, Optional, Self, Tuple, Unpack
4
5
 
5
- from fabricatio.models.generic import Display, ProposedAble, ProposedUpdateAble, WithBriefing
6
+ from fabricatio.journal import logger
7
+ from fabricatio.models.generic import SketchedAble, WithBriefing
6
8
  from fabricatio.utils import ask_edit
9
+ from pydantic import Field
7
10
  from questionary import Choice, checkbox, text
8
11
  from rich import print as r_print
9
12
 
10
13
 
11
- class Problem(ProposedAble, WithBriefing, Display):
14
+ class Problem(SketchedAble, WithBriefing):
12
15
  """Represents a problem identified during review."""
13
16
 
14
- description: str
15
- """Description of the problem, The """
17
+ description: str = Field(alias="cause")
18
+ """The cause of the problem, including the root cause, the context, and the impact, make detailed enough for engineer to understand the problem and its impact."""
16
19
 
17
- severity: Literal["low", "medium", "high"]
18
- """Severity level of the problem."""
19
-
20
- category: str
21
- """Category of the problem."""
20
+ severity_level: int = Field(ge=0, le=10)
21
+ """Severity level of the problem, which is a number between 0 and 10, 0 means the problem is not severe, 10 means the problem is extremely severe."""
22
22
 
23
23
  location: str
24
24
  """Location where the problem was identified."""
25
25
 
26
- recommendation: str
27
- """Recommended solution or action."""
28
-
29
26
 
30
- class Solution(ProposedAble, WithBriefing, Display):
27
+ class Solution(SketchedAble, WithBriefing):
31
28
  """Represents a proposed solution to a problem."""
32
29
 
33
- operation: str
34
- """Description or identifier of the operation."""
30
+ description: str = Field(alias="mechanism")
31
+ """Description of the solution, including a detailed description of the execution steps, and the mechanics, principle or fact."""
35
32
 
36
- feasibility: Literal["low", "medium", "high"]
37
- """Feasibility level of the solution."""
33
+ execute_steps: List[str]
34
+ """A list of steps to execute to implement the solution, which is expected to be able to finally solve the corresponding problem, and which should be an Idiot-proof tutorial."""
38
35
 
39
- impact: Literal["low", "medium", "high"]
40
- """Impact level of the solution."""
36
+ feasibility_level: int = Field(ge=0, le=10)
37
+ """Feasibility level of the solution, which is a number between 0 and 10, 0 means the solution is not feasible, 10 means the solution is complete feasible."""
41
38
 
39
+ impact_level: int = Field(ge=0, le=10)
40
+ """Impact level of the solution, which is a number between 0 and 10, 0 means the solution is not impactful, 10 means the solution is extremely impactful."""
42
41
 
43
- class ProblemSolutions(ProposedUpdateAble):
42
+
43
+ class ProblemSolutions(SketchedAble):
44
44
  """Represents a problem-solution pair identified during a review process."""
45
45
 
46
46
  problem: Problem
47
47
  """The problem identified in the review."""
48
48
  solutions: List[Solution]
49
- """A collection of potential solutions."""
49
+ """A collection of potential solutions, spread the thought, add more solution as possible.Do not leave this as blank"""
50
+
51
+ def model_post_init(self, context: Any, /) -> None:
52
+ """Initialize the problem-solution pair with a problem and a list of solutions."""
53
+ if len(self.solutions) == 0:
54
+ logger.warning(f"No solution found for problem {self.problem.name}, please add more solutions manually.")
50
55
 
51
56
  def update_from_inner(self, other: Self) -> Self:
52
57
  """Update the current instance with another instance's attributes."""
@@ -64,6 +69,10 @@ class ProblemSolutions(ProposedUpdateAble):
64
69
  self.solutions = solutions
65
70
  return self
66
71
 
72
+ def has_solutions(self) -> bool:
73
+ """Check if the problem-solution pair has any solutions."""
74
+ return len(self.solutions) > 0
75
+
67
76
  async def edit_problem(self) -> Self:
68
77
  """Interactively edit the problem description."""
69
78
  self.problem = Problem.model_validate_strings(
@@ -78,13 +87,33 @@ class ProblemSolutions(ProposedUpdateAble):
78
87
  self.solutions = [Solution.model_validate_strings(s) for s in string_seq]
79
88
  return self
80
89
 
90
+ def decided(self) -> bool:
91
+ """Check if the improvement is decided."""
92
+ return len(self.solutions) == 1
93
+
94
+ def final_solution(self, always_use_first: bool = False) -> Optional[Solution]:
95
+ """Get the final solution."""
96
+ if not always_use_first and not self.decided():
97
+ logger.error(
98
+ f"There is {len(self.solutions)} solutions for problem {self.problem.name}, please decide which solution is eventually adopted."
99
+ )
100
+ return None
101
+ return self.solutions[0]
81
102
 
82
- class Improvement(ProposedAble, Display):
103
+
104
+ class Improvement(SketchedAble):
83
105
  """A class representing an improvement suggestion."""
84
106
 
107
+ focused_on: str
108
+ """The focused on topic of the improvement"""
109
+
85
110
  problem_solutions: List[ProblemSolutions]
86
111
  """Collection of problems identified during review along with their potential solutions."""
87
112
 
113
+ def all_problems_have_solutions(self) -> bool:
114
+ """Check if all problems have solutions."""
115
+ return all(ps.has_solutions() for ps in self.problem_solutions)
116
+
88
117
  async def supervisor_check(self, check_solutions: bool = True) -> Self:
89
118
  """Perform an interactive review session to filter problems and solutions.
90
119
 
@@ -118,3 +147,15 @@ class Improvement(ProposedAble, Display):
118
147
  await to_exam.edit_solutions()
119
148
 
120
149
  return self
150
+
151
+ def decided(self) -> bool:
152
+ """Check if the improvement is decided."""
153
+ return all(ps.decided() for ps in self.problem_solutions)
154
+
155
+ @classmethod
156
+ def gather(cls, *improvements: Unpack[Tuple["Improvement", ...]]) -> Self:
157
+ """Gather multiple improvements into a single instance."""
158
+ return cls(
159
+ focused_on=";".join(imp.focused_on for imp in improvements),
160
+ problem_solutions=list(chain(*(imp.problem_solutions for imp in improvements))),
161
+ )
@@ -1,23 +1,52 @@
1
- """A module containing classes related to rule sets and rules."""
1
+ """A module containing classes related to rule sets and rules.
2
2
 
3
- from typing import List
3
+ This module provides the `Rule` and `RuleSet` classes, which are used to define and manage
4
+ individual rules and collections of rules, respectively. These classes are designed to
5
+ facilitate the creation, organization, and application of rules in various contexts,
6
+ ensuring clarity, consistency, and enforceability. The module supports detailed
7
+ descriptions, examples, and metadata for each rule and rule set, making it suitable for
8
+ complex rule management systems.
9
+ """
4
10
 
5
- from fabricatio.models.generic import Described, Display, PersistentAble, ProposedAble, WithBriefing
11
+ from typing import List, Self, Tuple, Unpack
6
12
 
13
+ from fabricatio.models.generic import Language, PersistentAble, SketchedAble, WithBriefing
14
+ from more_itertools import flatten
7
15
 
8
- class Rule(WithBriefing,ProposedAble,Display):
16
+
17
+ class Rule(WithBriefing, Language, SketchedAble, PersistentAble):
9
18
  """Represents a rule or guideline for a specific topic."""
10
19
 
11
20
  violation_examples: List[str]
12
- """Examples of violations of the rule."""
21
+ """A list of concrete examples demonstrating violations of this rule. Each example should
22
+ be a clear scenario or case that illustrates how the rule can be broken, including the
23
+ context, actions, and consequences of the violation. These examples should help in
24
+ understanding the boundaries of the rule."""
25
+
13
26
  compliance_examples: List[str]
14
- """Examples of how to comply with the rule."""
27
+ """A list of concrete examples demonstrating proper compliance with this rule. Each example
28
+ should be a clear scenario or case that illustrates how to correctly follow the rule,
29
+ including the context, actions, and positive outcomes of compliance. These examples should
30
+ serve as practical guidance for implementing the rule correctly."""
15
31
 
16
32
 
17
- class RuleSet(ProposedAble, Display, PersistentAble, Described):
33
+ class RuleSet(SketchedAble, PersistentAble, WithBriefing, Language):
18
34
  """Represents a collection of rules and guidelines for a particular topic."""
19
35
 
20
- title: str
21
- """The title of the rule set."""
22
36
  rules: List[Rule]
23
- """The rules and guidelines contained in the rule set."""
37
+ """The collection of rules and guidelines contained in this rule set. Each rule should be
38
+ a well-defined, specific guideline that contributes to the overall purpose of the rule set.
39
+ The rules should be logically organized and consistent with each other, forming a coherent
40
+ framework for the topic or domain covered by the rule set."""
41
+
42
+ @classmethod
43
+ def gather(cls, *rulesets: Unpack[Tuple["RuleSet",...]]) -> Self:
44
+ """Gathers multiple rule sets into a single rule set."""
45
+ if not rulesets:
46
+ raise ValueError("No rulesets provided")
47
+ return cls(
48
+ language=rulesets[0].language,
49
+ name=";".join(ruleset.name for ruleset in rulesets),
50
+ description=";".join(ruleset.description for ruleset in rulesets),
51
+ rules=list(flatten(r.rules for r in rulesets)),
52
+ )