fabricatio 0.2.8.dev2__cp312-cp312-win_amd64.whl → 0.2.8.dev3__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/_rust.cp312-win_amd64.pyd +0 -0
- fabricatio/_rust.pyi +1 -1
- fabricatio/actions/article.py +72 -56
- fabricatio/actions/article_rag.py +4 -5
- fabricatio/actions/output.py +4 -3
- fabricatio/actions/rag.py +3 -3
- fabricatio/capabilities/check.py +97 -0
- fabricatio/capabilities/correct.py +7 -6
- fabricatio/capabilities/propose.py +20 -4
- fabricatio/capabilities/rag.py +3 -2
- fabricatio/capabilities/rating.py +7 -10
- fabricatio/capabilities/review.py +18 -187
- fabricatio/capabilities/task.py +8 -9
- fabricatio/config.py +2 -0
- fabricatio/models/action.py +6 -2
- fabricatio/models/extra/advanced_judge.py +7 -7
- fabricatio/models/extra/article_base.py +45 -8
- fabricatio/models/extra/article_essence.py +40 -209
- fabricatio/models/extra/article_main.py +1 -1
- fabricatio/models/extra/problem.py +120 -0
- fabricatio/models/extra/rule.py +23 -0
- fabricatio/models/generic.py +28 -33
- fabricatio/models/role.py +4 -1
- fabricatio/models/usages.py +8 -6
- fabricatio/models/utils.py +0 -46
- fabricatio/utils.py +54 -0
- {fabricatio-0.2.8.dev2.data → fabricatio-0.2.8.dev3.data}/scripts/tdown.exe +0 -0
- {fabricatio-0.2.8.dev2.dist-info → fabricatio-0.2.8.dev3.dist-info}/METADATA +2 -1
- fabricatio-0.2.8.dev3.dist-info/RECORD +53 -0
- fabricatio-0.2.8.dev2.dist-info/RECORD +0 -49
- {fabricatio-0.2.8.dev2.dist-info → fabricatio-0.2.8.dev3.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.8.dev2.dist-info → fabricatio-0.2.8.dev3.dist-info}/licenses/LICENSE +0 -0
@@ -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,
|
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.
|
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.
|
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]) ->
|
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
|
-
|
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(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[
|
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(Rating, 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(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
|
-
|
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(Rating, 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,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
|
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(
|
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
@@ -238,6 +238,8 @@ class TemplateConfig(BaseModel):
|
|
238
238
|
as_prompt_template: str = Field(default="as_prompt")
|
239
239
|
"""The name of the as prompt template which will be used to convert a string to a prompt."""
|
240
240
|
|
241
|
+
check_string_template: str = Field(default="check_string")
|
242
|
+
"""The name of the check string template which will be used to check a string."""
|
241
243
|
|
242
244
|
class MagikaConfig(BaseModel):
|
243
245
|
"""Magika configuration class."""
|
fabricatio/models/action.py
CHANGED
@@ -18,7 +18,7 @@ from fabricatio.models.usages import ToolBoxUsage
|
|
18
18
|
from pydantic import Field, PrivateAttr
|
19
19
|
|
20
20
|
|
21
|
-
class Action(HandleTask, ProposeTask, Correct):
|
21
|
+
class Action(WithBriefing, HandleTask, ProposeTask, Correct):
|
22
22
|
"""Class that represents an action to be executed in a workflow.
|
23
23
|
|
24
24
|
Actions are the atomic units of work in a workflow. Each action performs
|
@@ -97,6 +97,8 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
97
97
|
A workflow manages the execution of multiple actions in sequence, passing
|
98
98
|
a shared context between them and handling task lifecycle events.
|
99
99
|
"""
|
100
|
+
description:str =""
|
101
|
+
"""The description of the workflow, which describes the workflow's purpose and requirements."""
|
100
102
|
|
101
103
|
_context: Queue[Dict[str, Any]] = PrivateAttr(default_factory=lambda: Queue(maxsize=1))
|
102
104
|
"""Queue for storing the workflow execution context."""
|
@@ -104,7 +106,9 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
104
106
|
_instances: Tuple[Action, ...] = PrivateAttr(default_factory=tuple)
|
105
107
|
"""Instantiated action objects to be executed in this workflow."""
|
106
108
|
|
107
|
-
steps: Tuple[Union[Type[Action], Action], ...] = Field(
|
109
|
+
steps: Tuple[Union[Type[Action], Action], ...] = Field(
|
110
|
+
frozen=True,
|
111
|
+
)
|
108
112
|
"""The sequence of actions to be executed, can be action classes or instances."""
|
109
113
|
|
110
114
|
task_input_key: str = Field(default="task_input")
|
@@ -2,23 +2,23 @@
|
|
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
|
+
deny_evidence: List[str]
|
14
|
+
"""List of clues supporting the denial."""
|
13
15
|
|
14
16
|
affirm_evidence: List[str]
|
15
|
-
"""List of
|
17
|
+
"""List of clues supporting the affirmation."""
|
16
18
|
|
17
|
-
deny_evidence: List[str]
|
18
|
-
"""List of evidence supporting the denial."""
|
19
19
|
|
20
20
|
final_judgement: bool
|
21
|
-
"""The final judgment made according to all extracted
|
21
|
+
"""The final judgment made according to all extracted clues."""
|
22
22
|
|
23
23
|
def __bool__(self) -> bool:
|
24
24
|
"""Return the final judgment value.
|
@@ -2,9 +2,8 @@
|
|
2
2
|
|
3
3
|
from abc import ABC, abstractmethod
|
4
4
|
from enum import StrEnum
|
5
|
-
from functools import cache
|
6
5
|
from itertools import chain
|
7
|
-
from typing import Generator, List, Optional, Self, Tuple
|
6
|
+
from typing import Generator, List, Optional, Self, Tuple, overload
|
8
7
|
|
9
8
|
from fabricatio.models.generic import (
|
10
9
|
AsPrompt,
|
@@ -30,7 +29,6 @@ class ReferringType(StrEnum):
|
|
30
29
|
type RefKey = Tuple[str, Optional[str], Optional[str]]
|
31
30
|
|
32
31
|
|
33
|
-
@cache
|
34
32
|
class ArticleRef(CensoredAble, Display, ProposedUpdateAble):
|
35
33
|
"""Reference to a specific chapter, section or subsection within the article. You SHALL not refer to an article component that is external and not present within our own article.
|
36
34
|
|
@@ -127,13 +125,13 @@ class Patch[T](ProposedUpdateAble, Display):
|
|
127
125
|
|
128
126
|
tweaked: List[T]
|
129
127
|
"""Tweaked content list"""
|
128
|
+
|
130
129
|
def update_from_inner(self, other: Self) -> Self:
|
131
130
|
"""Updates the current instance with the attributes of another instance."""
|
132
131
|
self.tweaked.clear()
|
133
132
|
self.tweaked.extend(other.tweaked)
|
134
133
|
return self
|
135
134
|
|
136
|
-
|
137
135
|
@classmethod
|
138
136
|
def default(cls) -> Self:
|
139
137
|
"""Defaults to empty list."""
|
@@ -144,8 +142,6 @@ class ArticleRefPatch(Patch[ArticleRef]):
|
|
144
142
|
"""Patch for article refs."""
|
145
143
|
|
146
144
|
|
147
|
-
|
148
|
-
|
149
145
|
class ArticleOutlineBase(
|
150
146
|
ArticleMetaData,
|
151
147
|
ResolveUpdateConflict,
|
@@ -340,6 +336,34 @@ class ArticleBase[T: ChapterBase](FinalizedDumpAble, AsPrompt, ABC):
|
|
340
336
|
yield sec
|
341
337
|
yield from sec.subsections
|
342
338
|
|
339
|
+
def iter_support_on(self, rev: bool = False) -> Generator[ArticleRef, None, None]:
|
340
|
+
"""Iterates over all references that the article components support.
|
341
|
+
|
342
|
+
Args:
|
343
|
+
rev (bool): If True, iterate in reverse order.
|
344
|
+
|
345
|
+
Yields:
|
346
|
+
ArticleRef: Each reference that the article components support.
|
347
|
+
"""
|
348
|
+
if rev:
|
349
|
+
yield from chain(*[a.support_to for a in self.iter_dfs_rev()])
|
350
|
+
return
|
351
|
+
yield from chain(*[a.support_to for a in self.iter_dfs()])
|
352
|
+
|
353
|
+
def iter_depend_on(self, rev: bool = False) -> Generator[ArticleRef, None, None]:
|
354
|
+
"""Iterates over all references that the article components depend on.
|
355
|
+
|
356
|
+
Args:
|
357
|
+
rev (bool): If True, iterate in reverse order.
|
358
|
+
|
359
|
+
Yields:
|
360
|
+
ArticleRef: Each reference that the article components depend on.
|
361
|
+
"""
|
362
|
+
if rev:
|
363
|
+
yield from chain(*[a.depend_on for a in self.iter_dfs_rev()])
|
364
|
+
return
|
365
|
+
yield from chain(*[a.depend_on for a in self.iter_dfs()])
|
366
|
+
|
343
367
|
def iter_sections(self) -> Generator[Tuple[ChapterBase, SectionBase], None, None]:
|
344
368
|
"""Iterates through all sections in the article.
|
345
369
|
|
@@ -369,7 +393,13 @@ class ArticleBase[T: ChapterBase](FinalizedDumpAble, AsPrompt, ABC):
|
|
369
393
|
return component, summary
|
370
394
|
return None
|
371
395
|
|
372
|
-
|
396
|
+
@overload
|
397
|
+
def find_illegal_ref(self, gather_identical: bool) -> Optional[Tuple[ArticleRef | List[ArticleRef], str]]: ...
|
398
|
+
|
399
|
+
@overload
|
400
|
+
def find_illegal_ref(self) -> Optional[Tuple[ArticleRef, str]]: ...
|
401
|
+
|
402
|
+
def find_illegal_ref(self, gather_identical: bool = False) -> Optional[Tuple[ArticleRef | List[ArticleRef], str]]:
|
373
403
|
"""Finds the first illegal component in the outline.
|
374
404
|
|
375
405
|
Returns:
|
@@ -380,8 +410,15 @@ class ArticleBase[T: ChapterBase](FinalizedDumpAble, AsPrompt, ABC):
|
|
380
410
|
for ref in chain(component.depend_on, component.support_to):
|
381
411
|
if not ref.deref(self):
|
382
412
|
summary += f"Invalid internal reference in `{component.__class__.__name__}` titled `{component.title}`, because the referred {ref.referring_type} is not exists within the article, see the original obj dump: {ref.model_dump()}\n"
|
383
|
-
if summary:
|
413
|
+
if summary and not gather_identical:
|
384
414
|
return ref, summary
|
415
|
+
if summary and gather_identical:
|
416
|
+
return [
|
417
|
+
identical_ref
|
418
|
+
for identical_ref in chain(self.iter_depend_on(), self.iter_support_on())
|
419
|
+
if identical_ref == ref
|
420
|
+
], summary
|
421
|
+
|
385
422
|
return None
|
386
423
|
|
387
424
|
def finalized_dump(self) -> str:
|