fabricatio 0.2.7.dev4__cp312-cp312-win_amd64.whl → 0.2.8__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.
- fabricatio/__init__.py +4 -11
- fabricatio/actions/article.py +226 -92
- fabricatio/actions/article_rag.py +86 -21
- fabricatio/actions/output.py +71 -3
- fabricatio/actions/rag.py +3 -3
- fabricatio/actions/rules.py +39 -0
- fabricatio/capabilities/advanced_judge.py +23 -0
- fabricatio/capabilities/censor.py +90 -0
- fabricatio/capabilities/check.py +195 -0
- fabricatio/capabilities/correct.py +160 -96
- fabricatio/capabilities/propose.py +20 -4
- fabricatio/capabilities/rag.py +5 -4
- fabricatio/capabilities/rating.py +68 -23
- fabricatio/capabilities/review.py +21 -190
- fabricatio/capabilities/task.py +9 -10
- fabricatio/config.py +11 -3
- fabricatio/fs/curd.py +4 -0
- fabricatio/models/action.py +24 -10
- fabricatio/models/adv_kwargs_types.py +25 -0
- fabricatio/models/extra/__init__.py +1 -0
- fabricatio/models/extra/advanced_judge.py +32 -0
- fabricatio/models/extra/article_base.py +324 -89
- fabricatio/models/extra/article_essence.py +49 -176
- fabricatio/models/extra/article_main.py +48 -127
- fabricatio/models/extra/article_outline.py +12 -152
- fabricatio/models/extra/article_proposal.py +29 -13
- fabricatio/models/extra/patches.py +7 -0
- fabricatio/models/extra/problem.py +153 -0
- fabricatio/models/extra/rule.py +65 -0
- fabricatio/models/generic.py +360 -88
- fabricatio/models/kwargs_types.py +23 -17
- fabricatio/models/role.py +4 -1
- fabricatio/models/task.py +1 -1
- fabricatio/models/tool.py +149 -14
- fabricatio/models/usages.py +61 -47
- fabricatio/models/utils.py +0 -46
- fabricatio/parser.py +7 -8
- fabricatio/rust.cp312-win_amd64.pyd +0 -0
- fabricatio/{_rust.pyi → rust.pyi} +50 -0
- fabricatio/{_rust_instances.py → rust_instances.py} +1 -1
- fabricatio/utils.py +54 -0
- fabricatio-0.2.8.data/scripts/tdown.exe +0 -0
- {fabricatio-0.2.7.dev4.dist-info → fabricatio-0.2.8.dist-info}/METADATA +2 -1
- fabricatio-0.2.8.dist-info/RECORD +58 -0
- fabricatio/_rust.cp312-win_amd64.pyd +0 -0
- fabricatio-0.2.7.dev4.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.7.dev4.dist-info/RECORD +0 -47
- {fabricatio-0.2.7.dev4.dist-info → fabricatio-0.2.8.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.7.dev4.dist-info → fabricatio-0.2.8.dist-info}/licenses/LICENSE +0 -0
@@ -1,181 +1,19 @@
|
|
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,
|
3
|
+
from typing import Dict, Optional, Set, Unpack
|
4
4
|
|
5
|
-
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
6
5
|
from fabricatio.capabilities.propose import Propose
|
7
|
-
from fabricatio.capabilities.rating import
|
6
|
+
from fabricatio.capabilities.rating import Rating
|
8
7
|
from fabricatio.config import configs
|
9
|
-
from fabricatio.models.
|
8
|
+
from fabricatio.models.extra.problem import Improvement
|
9
|
+
from fabricatio.models.generic import Display, WithBriefing
|
10
10
|
from fabricatio.models.kwargs_types import ReviewKwargs, ValidateKwargs
|
11
11
|
from fabricatio.models.task import Task
|
12
|
-
from fabricatio.
|
13
|
-
from
|
14
|
-
from questionary import print as q_print
|
15
|
-
from rich import print as r_print
|
12
|
+
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
13
|
+
from fabricatio.utils import ok
|
16
14
|
|
17
15
|
|
18
|
-
class
|
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
|
176
|
-
|
177
|
-
|
178
|
-
class Review(GiveRating, Propose):
|
16
|
+
class Review(Rating, Propose):
|
179
17
|
"""Class that provides functionality to review tasks and strings using a language model.
|
180
18
|
|
181
19
|
This class extends GiveRating and Propose capabilities to analyze content,
|
@@ -185,7 +23,7 @@ class Review(GiveRating, Propose):
|
|
185
23
|
appropriate topic and criteria.
|
186
24
|
"""
|
187
25
|
|
188
|
-
async def review_task[T](self, task: Task[T], **kwargs: Unpack[ReviewKwargs]) ->
|
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(GiveRating, Propose):
|
|
197
35
|
including topic and optional criteria.
|
198
36
|
|
199
37
|
Returns:
|
200
|
-
|
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
|
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(GiveRating, 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[
|
212
|
-
) ->
|
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(GiveRating, Propose):
|
|
224
62
|
**kwargs (Unpack[ValidateKwargs]): Additional keyword arguments for the LLM usage.
|
225
63
|
|
226
64
|
Returns:
|
227
|
-
|
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(GiveRating, 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
|
-
|
243
|
-
|
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(GiveRating, Propose):
|
|
268
99
|
TypeError: If the object does not implement Display or WithBriefing.
|
269
100
|
|
270
101
|
Returns:
|
271
|
-
|
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
|
-
|
106
|
+
text_to_review = obj.display()
|
276
107
|
elif isinstance(obj, WithBriefing):
|
277
|
-
|
108
|
+
text_to_review = obj.briefing
|
278
109
|
else:
|
279
110
|
raise TypeError(f"Unsupported type for review: {type(obj)}")
|
280
111
|
|
281
|
-
return
|
112
|
+
return await self.review_string(text_to_review, **kwargs)
|
fabricatio/capabilities/task.py
CHANGED
@@ -1,22 +1,21 @@
|
|
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
|
4
|
+
from typing import Any, Dict, List, Optional, Tuple, Unpack
|
5
5
|
|
6
6
|
import orjson
|
7
|
-
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
8
7
|
from fabricatio.capabilities.propose import Propose
|
9
8
|
from fabricatio.config import configs
|
10
9
|
from fabricatio.journal import logger
|
11
|
-
from fabricatio.models.generic import WithBriefing
|
12
10
|
from fabricatio.models.kwargs_types import ChooseKwargs, ValidateKwargs
|
13
11
|
from fabricatio.models.task import Task
|
14
12
|
from fabricatio.models.tool import Tool, ToolExecutor
|
15
13
|
from fabricatio.models.usages import ToolBoxUsage
|
16
14
|
from fabricatio.parser import JsonCapture, PythonCapture
|
15
|
+
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
17
16
|
|
18
17
|
|
19
|
-
class ProposeTask(
|
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 :=
|
36
|
+
logger.error(err := "Prompt must be provided.")
|
38
37
|
raise ValueError(err)
|
39
38
|
|
40
|
-
return await self.propose(Task, prompt, **
|
39
|
+
return await self.propose(Task, prompt, **kwargs)
|
41
40
|
|
42
41
|
|
43
|
-
class HandleTask(
|
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 =
|
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
|
-
**
|
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"
|
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."""
|
fabricatio/fs/curd.py
CHANGED
@@ -145,5 +145,9 @@ def gather_files(directory: str | Path | PathLike, extension: str) -> list[str]:
|
|
145
145
|
|
146
146
|
Returns:
|
147
147
|
list[str]: A list of file paths with the specified extension.
|
148
|
+
|
149
|
+
Example:
|
150
|
+
>>> gather_files('/path/to/directory', 'txt')
|
151
|
+
['/path/to/directory/file1.txt', '/path/to/directory/file2.txt']
|
148
152
|
"""
|
149
153
|
return [file.as_posix() for file in Path(directory).rglob(f"*.{extension}")]
|
fabricatio/models/action.py
CHANGED
@@ -9,16 +9,18 @@ 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
|
|
18
|
+
OUTPUT_KEY = "task_output"
|
20
19
|
|
21
|
-
|
20
|
+
INPUT_KEY = "task_input"
|
21
|
+
|
22
|
+
|
23
|
+
class Action(WithBriefing, LLMUsage):
|
22
24
|
"""Class that represents an action to be executed in a workflow.
|
23
25
|
|
24
26
|
Actions are the atomic units of work in a workflow. Each action performs
|
@@ -90,6 +92,10 @@ class Action(HandleTask, ProposeTask, Correct):
|
|
90
92
|
return f"## Your personality: \n{self.personality}\n# The action you are going to perform: \n{super().briefing}"
|
91
93
|
return f"# The action you are going to perform: \n{super().briefing}"
|
92
94
|
|
95
|
+
def to_task_output(self)->Self:
|
96
|
+
"""Set the output key to OUTPUT_KEY and return the action instance."""
|
97
|
+
self.output_key=OUTPUT_KEY
|
98
|
+
return self
|
93
99
|
|
94
100
|
class WorkFlow(WithBriefing, ToolBoxUsage):
|
95
101
|
"""Class that represents a sequence of actions to be executed for a task.
|
@@ -98,19 +104,24 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
98
104
|
a shared context between them and handling task lifecycle events.
|
99
105
|
"""
|
100
106
|
|
107
|
+
description: str = ""
|
108
|
+
"""The description of the workflow, which describes the workflow's purpose and requirements."""
|
109
|
+
|
101
110
|
_context: Queue[Dict[str, Any]] = PrivateAttr(default_factory=lambda: Queue(maxsize=1))
|
102
111
|
"""Queue for storing the workflow execution context."""
|
103
112
|
|
104
113
|
_instances: Tuple[Action, ...] = PrivateAttr(default_factory=tuple)
|
105
114
|
"""Instantiated action objects to be executed in this workflow."""
|
106
115
|
|
107
|
-
steps: Tuple[Union[Type[Action], Action], ...] = Field(
|
116
|
+
steps: Tuple[Union[Type[Action], Action], ...] = Field(
|
117
|
+
frozen=True,
|
118
|
+
)
|
108
119
|
"""The sequence of actions to be executed, can be action classes or instances."""
|
109
120
|
|
110
|
-
task_input_key: str = Field(default=
|
121
|
+
task_input_key: str = Field(default=INPUT_KEY)
|
111
122
|
"""Key used to store the input task in the context dictionary."""
|
112
123
|
|
113
|
-
task_output_key: str = Field(default=
|
124
|
+
task_output_key: str = Field(default=OUTPUT_KEY)
|
114
125
|
"""Key used to extract the final result from the context dictionary."""
|
115
126
|
|
116
127
|
extra_init_context: Dict[str, Any] = Field(default_factory=dict, frozen=True)
|
@@ -157,19 +168,22 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
157
168
|
# Process each action in sequence
|
158
169
|
for step in self._instances:
|
159
170
|
current_action = step.name
|
160
|
-
logger.info(f"Executing step
|
171
|
+
logger.info(f"Executing step >> {current_action}")
|
161
172
|
|
162
173
|
# Get current context and execute action
|
163
174
|
context = await self._context.get()
|
164
175
|
act_task = create_task(step.act(context))
|
165
176
|
# Handle task cancellation
|
166
177
|
if task.is_cancelled():
|
178
|
+
logger.warning(f"Task cancelled by task: {task.name}")
|
167
179
|
act_task.cancel(f"Cancelled by task: {task.name}")
|
168
180
|
break
|
169
181
|
|
170
182
|
# Update context with modified values
|
171
183
|
modified_ctx = await act_task
|
172
184
|
logger.success(f"Step execution finished: {current_action}")
|
185
|
+
if step.output_key:
|
186
|
+
logger.success(f"Setting output to `{step.output_key}`")
|
173
187
|
await self._context.put(modified_ctx)
|
174
188
|
|
175
189
|
logger.success(f"Workflow execution finished: {self.name}")
|
@@ -180,7 +194,7 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
180
194
|
|
181
195
|
if self.task_output_key not in final_ctx:
|
182
196
|
logger.warning(
|
183
|
-
f"Task output key: {self.task_output_key} not found in the context, None will be returned. "
|
197
|
+
f"Task output key: `{self.task_output_key}` not found in the context, None will be returned. "
|
184
198
|
f"You can check if `Action.output_key` is set the same as `WorkFlow.task_output_key`."
|
185
199
|
)
|
186
200
|
|
@@ -219,7 +233,7 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
219
233
|
self.provide_tools_to(self._instances)
|
220
234
|
return self
|
221
235
|
|
222
|
-
def update_init_context(self, **kwargs) -> Self:
|
236
|
+
def update_init_context(self, /, **kwargs) -> Self:
|
223
237
|
"""Update the initial context with additional key-value pairs.
|
224
238
|
|
225
239
|
Args:
|
@@ -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
|
@@ -0,0 +1 @@
|
|
1
|
+
"""A module contains extra models for fabricatio."""
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"""Module containing the JudgeMent class for holding judgment results."""
|
2
|
+
|
3
|
+
from typing import List
|
4
|
+
|
5
|
+
from fabricatio.models.generic import Display, ProposedAble
|
6
|
+
|
7
|
+
|
8
|
+
class JudgeMent(ProposedAble, Display):
|
9
|
+
"""Represents a judgment result containing supporting/denying evidence and final verdict.
|
10
|
+
|
11
|
+
The class stores both affirmative and denies evidence, truth and reasons lists along with the final boolean judgment.
|
12
|
+
"""
|
13
|
+
|
14
|
+
issue_to_judge: str
|
15
|
+
"""The issue to be judged"""
|
16
|
+
|
17
|
+
deny_evidence: List[str]
|
18
|
+
"""List of clues supporting the denial."""
|
19
|
+
|
20
|
+
affirm_evidence: List[str]
|
21
|
+
"""List of clues supporting the affirmation."""
|
22
|
+
|
23
|
+
final_judgement: bool
|
24
|
+
"""The final judgment made according to all extracted clues."""
|
25
|
+
|
26
|
+
def __bool__(self) -> bool:
|
27
|
+
"""Return the final judgment value.
|
28
|
+
|
29
|
+
Returns:
|
30
|
+
bool: The stored final_judgement value indicating the judgment result.
|
31
|
+
"""
|
32
|
+
return self.final_judgement
|