fabricatio 0.2.6.dev2__cp312-cp312-win_amd64.whl → 0.2.7__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 +7 -24
- fabricatio/_rust.cp312-win_amd64.pyd +0 -0
- fabricatio/_rust.pyi +22 -0
- fabricatio/actions/article.py +168 -19
- fabricatio/actions/article_rag.py +35 -0
- fabricatio/actions/output.py +21 -6
- fabricatio/actions/rag.py +51 -3
- fabricatio/capabilities/correct.py +36 -4
- fabricatio/capabilities/rag.py +67 -16
- fabricatio/capabilities/rating.py +15 -6
- fabricatio/capabilities/review.py +7 -4
- fabricatio/capabilities/task.py +5 -5
- fabricatio/config.py +29 -21
- fabricatio/decorators.py +32 -0
- fabricatio/models/action.py +117 -43
- fabricatio/models/extra/article_base.py +378 -0
- fabricatio/models/extra/article_essence.py +226 -0
- fabricatio/models/extra/article_main.py +196 -0
- fabricatio/models/extra/article_outline.py +32 -0
- fabricatio/models/extra/article_proposal.py +35 -0
- fabricatio/models/generic.py +164 -14
- fabricatio/models/kwargs_types.py +40 -10
- fabricatio/models/role.py +30 -6
- fabricatio/models/tool.py +6 -2
- fabricatio/models/usages.py +94 -47
- fabricatio/models/utils.py +29 -2
- fabricatio/parser.py +2 -0
- fabricatio/workflows/articles.py +12 -1
- fabricatio-0.2.7.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.7.dist-info/METADATA +181 -0
- fabricatio-0.2.7.dist-info/RECORD +47 -0
- {fabricatio-0.2.6.dev2.dist-info → fabricatio-0.2.7.dist-info}/WHEEL +1 -1
- fabricatio/models/extra.py +0 -171
- fabricatio-0.2.6.dev2.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.6.dev2.dist-info/METADATA +0 -432
- fabricatio-0.2.6.dev2.dist-info/RECORD +0 -42
- {fabricatio-0.2.6.dev2.dist-info → fabricatio-0.2.7.dist-info}/licenses/LICENSE +0 -0
fabricatio/__init__.py
CHANGED
@@ -2,59 +2,42 @@
|
|
2
2
|
|
3
3
|
from importlib.util import find_spec
|
4
4
|
|
5
|
+
from fabricatio import actions, toolboxes, workflows
|
5
6
|
from fabricatio._rust import BibManager
|
6
7
|
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
7
|
-
from fabricatio.actions.article import ExtractArticleEssence, GenerateArticleProposal, GenerateOutline
|
8
|
-
from fabricatio.actions.output import DumpFinalizedOutput
|
9
8
|
from fabricatio.core import env
|
10
|
-
from fabricatio.fs import MAGIKA, safe_json_read, safe_text_read
|
11
9
|
from fabricatio.journal import logger
|
10
|
+
from fabricatio.models import extra
|
12
11
|
from fabricatio.models.action import Action, WorkFlow
|
13
12
|
from fabricatio.models.events import Event
|
14
|
-
from fabricatio.models.extra import ArticleEssence
|
15
13
|
from fabricatio.models.role import Role
|
16
14
|
from fabricatio.models.task import Task
|
17
15
|
from fabricatio.models.tool import ToolBox
|
18
|
-
from fabricatio.models.utils import Message, Messages
|
19
16
|
from fabricatio.parser import Capture, GenericCapture, JsonCapture, PythonCapture
|
20
|
-
from fabricatio.toolboxes import arithmetic_toolbox, basic_toolboxes, fs_toolbox
|
21
|
-
from fabricatio.workflows.articles import WriteOutlineWorkFlow
|
22
17
|
|
23
18
|
__all__ = [
|
24
|
-
"MAGIKA",
|
25
19
|
"TEMPLATE_MANAGER",
|
26
20
|
"Action",
|
27
|
-
"ArticleEssence",
|
28
21
|
"BibManager",
|
29
22
|
"Capture",
|
30
|
-
"DumpFinalizedOutput",
|
31
23
|
"Event",
|
32
|
-
"ExtractArticleEssence",
|
33
|
-
"GenerateArticleProposal",
|
34
|
-
"GenerateOutline",
|
35
24
|
"GenericCapture",
|
36
25
|
"JsonCapture",
|
37
|
-
"Message",
|
38
|
-
"Messages",
|
39
26
|
"PythonCapture",
|
40
27
|
"Role",
|
41
28
|
"Task",
|
42
29
|
"ToolBox",
|
43
30
|
"WorkFlow",
|
44
|
-
"
|
45
|
-
"arithmetic_toolbox",
|
46
|
-
"basic_toolboxes",
|
31
|
+
"actions",
|
47
32
|
"env",
|
48
|
-
"
|
33
|
+
"extra",
|
49
34
|
"logger",
|
50
|
-
"
|
51
|
-
"
|
35
|
+
"toolboxes",
|
36
|
+
"workflows",
|
52
37
|
]
|
53
38
|
|
54
39
|
|
55
40
|
if find_spec("pymilvus"):
|
56
|
-
from fabricatio.actions.rag import InjectToDB
|
57
41
|
from fabricatio.capabilities.rag import RAG
|
58
|
-
from fabricatio.workflows.rag import StoreArticle
|
59
42
|
|
60
|
-
__all__ += ["RAG"
|
43
|
+
__all__ += ["RAG"]
|
Binary file
|
fabricatio/_rust.pyi
CHANGED
@@ -9,6 +9,7 @@ class TemplateManager:
|
|
9
9
|
|
10
10
|
See: https://crates.io/crates/handlebars
|
11
11
|
"""
|
12
|
+
|
12
13
|
def __init__(
|
13
14
|
self, template_dirs: List[Path], suffix: Optional[str] = None, active_loading: Optional[bool] = None
|
14
15
|
) -> None:
|
@@ -54,6 +55,17 @@ class TemplateManager:
|
|
54
55
|
RuntimeError: If template rendering fails
|
55
56
|
"""
|
56
57
|
|
58
|
+
def render_template_raw(self, template: str, data: Dict[str, Any]) -> str:
|
59
|
+
"""Render a template with context data.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
template: The template string
|
63
|
+
data: Context dictionary to provide variables to the template
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
Rendered template content as string
|
67
|
+
"""
|
68
|
+
|
57
69
|
def blake3_hash(content: bytes) -> str:
|
58
70
|
"""Calculate the BLAKE3 cryptographic hash of data.
|
59
71
|
|
@@ -100,3 +112,13 @@ class BibManager:
|
|
100
112
|
Uses nucleo_matcher for high-quality fuzzy text searching
|
101
113
|
See: https://crates.io/crates/nucleo-matcher
|
102
114
|
"""
|
115
|
+
|
116
|
+
def list_titles(self, is_verbatim: Optional[bool] = False) -> List[str]:
|
117
|
+
"""List all titles in the bibliography.
|
118
|
+
|
119
|
+
Args:
|
120
|
+
is_verbatim: Whether to return verbatim titles (without formatting)
|
121
|
+
|
122
|
+
Returns:
|
123
|
+
List of all titles in the bibliography
|
124
|
+
"""
|
fabricatio/actions/article.py
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
"""Actions for transmitting tasks to targets."""
|
2
2
|
|
3
|
-
from os import PathLike
|
4
3
|
from pathlib import Path
|
5
|
-
from typing import Callable, List, Optional
|
4
|
+
from typing import Any, Callable, List, Optional
|
6
5
|
|
7
6
|
from fabricatio.fs import safe_text_read
|
8
7
|
from fabricatio.journal import logger
|
9
8
|
from fabricatio.models.action import Action
|
10
|
-
from fabricatio.models.extra import ArticleEssence
|
9
|
+
from fabricatio.models.extra.article_essence import ArticleEssence
|
10
|
+
from fabricatio.models.extra.article_main import Article
|
11
|
+
from fabricatio.models.extra.article_outline import ArticleOutline
|
12
|
+
from fabricatio.models.extra.article_proposal import ArticleProposal
|
11
13
|
from fabricatio.models.task import Task
|
14
|
+
from fabricatio.models.utils import ok
|
12
15
|
|
13
16
|
|
14
17
|
class ExtractArticleEssence(Action):
|
@@ -22,10 +25,10 @@ class ExtractArticleEssence(Action):
|
|
22
25
|
output_key: str = "article_essence"
|
23
26
|
"""The key of the output data."""
|
24
27
|
|
25
|
-
async def _execute
|
28
|
+
async def _execute(
|
26
29
|
self,
|
27
30
|
task_input: Task,
|
28
|
-
reader: Callable[[
|
31
|
+
reader: Callable[[str], str] = lambda p: Path(p).read_text(encoding="utf-8"),
|
29
32
|
**_,
|
30
33
|
) -> Optional[List[ArticleEssence]]:
|
31
34
|
if not task_input.dependencies:
|
@@ -49,21 +52,108 @@ class GenerateArticleProposal(Action):
|
|
49
52
|
|
50
53
|
async def _execute(
|
51
54
|
self,
|
52
|
-
task_input: Task,
|
55
|
+
task_input: Optional[Task] = None,
|
56
|
+
article_briefing: Optional[str] = None,
|
57
|
+
article_briefing_path: Optional[str] = None,
|
53
58
|
**_,
|
54
59
|
) -> Optional[ArticleProposal]:
|
55
|
-
|
56
|
-
|
60
|
+
if article_briefing is None and article_briefing_path is None and task_input is None:
|
61
|
+
logger.error("Task not approved, since all inputs are None.")
|
62
|
+
return None
|
63
|
+
|
64
|
+
return ok(
|
65
|
+
await self.propose(
|
66
|
+
ArticleProposal,
|
67
|
+
briefing := (
|
68
|
+
article_briefing
|
69
|
+
or safe_text_read(
|
70
|
+
ok(
|
71
|
+
article_briefing_path
|
72
|
+
or await self.awhich_pathstr(
|
73
|
+
f"{ok(task_input).briefing}\nExtract the path of file which contains the article briefing."
|
74
|
+
),
|
75
|
+
"Could not find the path of file to read.",
|
76
|
+
)
|
77
|
+
)
|
78
|
+
),
|
79
|
+
**self.prepend_sys_msg(),
|
80
|
+
),
|
81
|
+
"Could not generate the proposal.",
|
82
|
+
).update_ref(briefing)
|
83
|
+
|
84
|
+
|
85
|
+
class GenerateOutline(Action):
|
86
|
+
"""Generate the article based on the outline."""
|
87
|
+
|
88
|
+
output_key: str = "article_outline"
|
89
|
+
"""The key of the output data."""
|
90
|
+
|
91
|
+
async def _execute(
|
92
|
+
self,
|
93
|
+
article_proposal: ArticleProposal,
|
94
|
+
**_,
|
95
|
+
) -> Optional[ArticleOutline]:
|
96
|
+
out = ok(
|
97
|
+
await self.propose(
|
98
|
+
ArticleOutline,
|
99
|
+
article_proposal.as_prompt(),
|
100
|
+
**self.prepend_sys_msg(),
|
101
|
+
),
|
102
|
+
"Could not generate the outline.",
|
57
103
|
)
|
58
104
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
105
|
+
introspect_manual = ok(
|
106
|
+
await self.draft_rating_manual(
|
107
|
+
topic=(
|
108
|
+
intro_topic
|
109
|
+
:= "Fix the error in the article outline, make sure there is no more error in the article outline."
|
110
|
+
),
|
111
|
+
),
|
112
|
+
"Could not generate the rating manual.",
|
63
113
|
)
|
64
114
|
|
115
|
+
while pack := out.find_introspected():
|
116
|
+
component, err = ok(pack)
|
117
|
+
logger.warning(f"Found introspected error: {err}")
|
118
|
+
corrected = ok(
|
119
|
+
await self.correct_obj(
|
120
|
+
component,
|
121
|
+
reference=f"# Original Article Outline\n{out.display()}\n# Error Need to be fixed\n{err}",
|
122
|
+
topic=intro_topic,
|
123
|
+
rating_manual=introspect_manual,
|
124
|
+
supervisor_check=False,
|
125
|
+
),
|
126
|
+
"Could not correct the component.",
|
127
|
+
)
|
128
|
+
component.update_from(corrected)
|
129
|
+
|
130
|
+
ref_manual = ok(
|
131
|
+
await self.draft_rating_manual(
|
132
|
+
topic=(
|
133
|
+
ref_topic
|
134
|
+
:= "Fix the internal referring error, make sure there is no more `ArticleRef` pointing to a non-existing article component."
|
135
|
+
),
|
136
|
+
),
|
137
|
+
"Could not generate the rating manual.",
|
138
|
+
)
|
65
139
|
|
66
|
-
|
140
|
+
while pack := out.find_illegal_ref():
|
141
|
+
component, err = ok(pack)
|
142
|
+
logger.warning(f"Found illegal referring error: {err}")
|
143
|
+
corrected_metadata = ok(
|
144
|
+
await self.correct_obj(
|
145
|
+
component.metadata,
|
146
|
+
reference=f"# Original Article Outline\n{out.display()}\n# Error Need to be fixed\n{err}\n\n# Create a new metadata to handle the error.",
|
147
|
+
topic=ref_topic,
|
148
|
+
rating_manual=ref_manual,
|
149
|
+
supervisor_check=False,
|
150
|
+
)
|
151
|
+
)
|
152
|
+
component.update_metadata(corrected_metadata)
|
153
|
+
return out.update_ref(article_proposal)
|
154
|
+
|
155
|
+
|
156
|
+
class GenerateArticle(Action):
|
67
157
|
"""Generate the article based on the outline."""
|
68
158
|
|
69
159
|
output_key: str = "article"
|
@@ -71,11 +161,70 @@ class GenerateOutline(Action):
|
|
71
161
|
|
72
162
|
async def _execute(
|
73
163
|
self,
|
74
|
-
|
164
|
+
article_outline: ArticleOutline,
|
75
165
|
**_,
|
76
|
-
) -> Optional[
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
166
|
+
) -> Optional[Article]:
|
167
|
+
article: Article = Article.from_outline(ok(article_outline, "Article outline not specified.")).update_ref(
|
168
|
+
article_outline
|
169
|
+
)
|
170
|
+
|
171
|
+
write_para_manual = ok(
|
172
|
+
await self.draft_rating_manual(w_topic := "write the following paragraph in the subsection.")
|
81
173
|
)
|
174
|
+
|
175
|
+
for *_, subsec in article.iter_subsections():
|
176
|
+
corrected_subsec = await self.correct_obj(
|
177
|
+
subsec,
|
178
|
+
reference=f"# Original Article Outline\n{article_outline.display()}\n# Error Need to be fixed\n{subsec.introspect()}",
|
179
|
+
topic=w_topic,
|
180
|
+
rating_manual=write_para_manual,
|
181
|
+
supervisor_check=False,
|
182
|
+
)
|
183
|
+
subsec.paragraphs.clear()
|
184
|
+
subsec.paragraphs.extend(corrected_subsec.paragraphs)
|
185
|
+
|
186
|
+
logger.success(f"Finished: {article.display()}")
|
187
|
+
logger.success(f"Dump: {article.finalized_dump()}")
|
188
|
+
return article
|
189
|
+
|
190
|
+
|
191
|
+
class CorrectProposal(Action):
|
192
|
+
"""Correct the proposal of the article."""
|
193
|
+
|
194
|
+
output_key: str = "corrected_proposal"
|
195
|
+
|
196
|
+
async def _execute(self, article_proposal: ArticleProposal, **_) -> Any:
|
197
|
+
return (await self.censor_obj(article_proposal, reference=article_proposal.referenced)).update_ref(
|
198
|
+
article_proposal
|
199
|
+
)
|
200
|
+
|
201
|
+
|
202
|
+
class CorrectOutline(Action):
|
203
|
+
"""Correct the outline of the article."""
|
204
|
+
|
205
|
+
output_key: str = "corrected_outline"
|
206
|
+
"""The key of the output data."""
|
207
|
+
|
208
|
+
async def _execute(
|
209
|
+
self,
|
210
|
+
article_outline: ArticleOutline,
|
211
|
+
**_,
|
212
|
+
) -> ArticleOutline:
|
213
|
+
return (await self.censor_obj(article_outline, reference=article_outline.referenced.as_prompt())).update_ref(
|
214
|
+
article_outline
|
215
|
+
)
|
216
|
+
|
217
|
+
|
218
|
+
class CorrectArticle(Action):
|
219
|
+
"""Correct the article based on the outline."""
|
220
|
+
|
221
|
+
output_key: str = "corrected_article"
|
222
|
+
"""The key of the output data."""
|
223
|
+
|
224
|
+
async def _execute(
|
225
|
+
self,
|
226
|
+
article: Article,
|
227
|
+
article_outline: ArticleOutline,
|
228
|
+
**_,
|
229
|
+
) -> Article:
|
230
|
+
return await self.censor_obj(article, reference=article_outline.referenced.as_prompt())
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"""A module for writing articles using RAG (Retrieval-Augmented Generation) capabilities."""
|
2
|
+
|
3
|
+
from typing import Optional
|
4
|
+
|
5
|
+
from fabricatio.capabilities.rag import RAG
|
6
|
+
from fabricatio.journal import logger
|
7
|
+
from fabricatio.models.action import Action
|
8
|
+
from fabricatio.models.extra.article_main import Article
|
9
|
+
from fabricatio.models.extra.article_outline import ArticleOutline
|
10
|
+
|
11
|
+
|
12
|
+
class GenerateArticleRAG(Action, RAG):
|
13
|
+
"""Write an article based on the provided outline."""
|
14
|
+
|
15
|
+
output_key: str = "article"
|
16
|
+
|
17
|
+
async def _execute(self, article_outline: ArticleOutline, **cxt) -> Optional[Article]:
|
18
|
+
"""Write an article based on the provided outline."""
|
19
|
+
logger.info(f"Writing an article based on the outline:\n{article_outline.title}")
|
20
|
+
refined_q = await self.arefined_query(article_outline.display())
|
21
|
+
return await self.propose(
|
22
|
+
Article,
|
23
|
+
article_outline.display(),
|
24
|
+
**self.prepend_sys_msg(f"{await self.aretrieve_compact(refined_q)}\n{self.briefing}"),
|
25
|
+
)
|
26
|
+
|
27
|
+
|
28
|
+
class WriteArticleFineGrind(Action, RAG):
|
29
|
+
"""Fine-grind an article based on the provided outline."""
|
30
|
+
|
31
|
+
output_key: str = "article"
|
32
|
+
|
33
|
+
async def _execute(self, article_outline: ArticleOutline, **cxt) -> Optional[Article]:
|
34
|
+
"""Fine-grind an article based on the provided outline."""
|
35
|
+
logger.info(f"Fine-grinding an article based on the outline:\n{article_outline.title}")
|
fabricatio/actions/output.py
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
"""Dump the finalized output to a file."""
|
2
2
|
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Optional
|
5
|
+
|
3
6
|
from fabricatio.models.action import Action
|
4
7
|
from fabricatio.models.generic import FinalizedDumpAble
|
5
8
|
from fabricatio.models.task import Task
|
9
|
+
from fabricatio.models.utils import ok
|
6
10
|
|
7
11
|
|
8
12
|
class DumpFinalizedOutput(Action):
|
@@ -10,10 +14,21 @@ class DumpFinalizedOutput(Action):
|
|
10
14
|
|
11
15
|
output_key: str = "dump_path"
|
12
16
|
|
13
|
-
async def _execute(
|
14
|
-
|
15
|
-
|
17
|
+
async def _execute(
|
18
|
+
self,
|
19
|
+
to_dump: FinalizedDumpAble,
|
20
|
+
task_input: Optional[Task] = None,
|
21
|
+
dump_path: Optional[str | Path] = None,
|
22
|
+
**_,
|
23
|
+
) -> str:
|
24
|
+
dump_path = Path(
|
25
|
+
dump_path
|
26
|
+
or ok(
|
27
|
+
await self.awhich_pathstr(
|
28
|
+
f"{ok(task_input, 'Neither `task_input` and `dump_path` is provided.').briefing}\n\nExtract a single path of the file, to which I will dump the data."
|
29
|
+
),
|
30
|
+
"Could not find the path of file to dump the data.",
|
31
|
+
)
|
16
32
|
)
|
17
|
-
|
18
|
-
|
19
|
-
return dump_path
|
33
|
+
ok(to_dump, "Could not dump the data since the path is not specified.").finalized_dump_to(dump_path)
|
34
|
+
return dump_path.as_posix()
|
fabricatio/actions/rag.py
CHANGED
@@ -3,8 +3,11 @@
|
|
3
3
|
from typing import List, Optional
|
4
4
|
|
5
5
|
from fabricatio.capabilities.rag import RAG
|
6
|
+
from fabricatio.journal import logger
|
6
7
|
from fabricatio.models.action import Action
|
7
8
|
from fabricatio.models.generic import PrepareVectorization
|
9
|
+
from fabricatio.models.task import Task
|
10
|
+
from questionary import text
|
8
11
|
|
9
12
|
|
10
13
|
class InjectToDB(Action, RAG):
|
@@ -13,13 +16,58 @@ class InjectToDB(Action, RAG):
|
|
13
16
|
output_key: str = "collection_name"
|
14
17
|
|
15
18
|
async def _execute[T: PrepareVectorization](
|
16
|
-
self, to_inject: T | List[T], collection_name:
|
19
|
+
self, to_inject: Optional[T] | List[Optional[T]], collection_name: str = "my_collection",override_inject:bool=False, **_
|
17
20
|
) -> Optional[str]:
|
18
21
|
if not isinstance(to_inject, list):
|
19
22
|
to_inject = [to_inject]
|
20
|
-
|
23
|
+
logger.info(f"Injecting {len(to_inject)} items into the collection '{collection_name}'")
|
24
|
+
if override_inject:
|
25
|
+
self.check_client().client.drop_collection(collection_name)
|
21
26
|
await self.view(collection_name, create=True).consume_string(
|
22
|
-
[
|
27
|
+
[
|
28
|
+
t.prepare_vectorization(self.embedding_max_sequence_length)
|
29
|
+
for t in to_inject
|
30
|
+
if isinstance(t, PrepareVectorization)
|
31
|
+
],
|
23
32
|
)
|
24
33
|
|
25
34
|
return collection_name
|
35
|
+
|
36
|
+
|
37
|
+
class RAGTalk(Action, RAG):
|
38
|
+
"""RAG-enabled conversational action that processes user questions based on a given task.
|
39
|
+
|
40
|
+
This action establishes an interactive conversation loop where it retrieves context-relevant
|
41
|
+
information to answer user queries according to the assigned task briefing.
|
42
|
+
|
43
|
+
Notes:
|
44
|
+
task_input: Task briefing that guides how to respond to user questions
|
45
|
+
collection_name: Name of the vector collection to use for retrieval (default: "my_collection")
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
Number of conversation turns completed before termination
|
49
|
+
"""
|
50
|
+
|
51
|
+
output_key: str = "task_output"
|
52
|
+
|
53
|
+
async def _execute(self, task_input: Task[str], **kwargs) -> int:
|
54
|
+
collection_name = kwargs.get("collection_name", "my_collection")
|
55
|
+
counter = 0
|
56
|
+
|
57
|
+
self.view(collection_name, create=True)
|
58
|
+
|
59
|
+
try:
|
60
|
+
while True:
|
61
|
+
user_say = await text("User: ").ask_async()
|
62
|
+
if user_say is None:
|
63
|
+
break
|
64
|
+
gpt_say = await self.aask_retrieved(
|
65
|
+
user_say,
|
66
|
+
user_say,
|
67
|
+
extra_system_message=f"You have to answer to user obeying task assigned to you:\n{task_input.briefing}",
|
68
|
+
)
|
69
|
+
print(f"GPT: {gpt_say}") # noqa: T201
|
70
|
+
counter += 1
|
71
|
+
except KeyboardInterrupt:
|
72
|
+
logger.info(f"executed talk action {counter} times")
|
73
|
+
return counter
|
@@ -10,9 +10,11 @@ from typing import Optional, Unpack, cast
|
|
10
10
|
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
11
11
|
from fabricatio.capabilities.review import Review, ReviewResult
|
12
12
|
from fabricatio.config import configs
|
13
|
-
from fabricatio.models.generic import Display, ProposedAble, WithBriefing
|
14
|
-
from fabricatio.models.kwargs_types import CorrectKwargs, ReviewKwargs
|
13
|
+
from fabricatio.models.generic import CensoredAble, Display, ProposedAble, WithBriefing
|
14
|
+
from fabricatio.models.kwargs_types import CensoredCorrectKwargs, CorrectKwargs, ReviewKwargs
|
15
15
|
from fabricatio.models.task import Task
|
16
|
+
from questionary import confirm, text
|
17
|
+
from rich import print as rprint
|
16
18
|
|
17
19
|
|
18
20
|
class Correct(Review):
|
@@ -55,7 +57,7 @@ class Correct(Review):
|
|
55
57
|
if supervisor_check:
|
56
58
|
await review_res.supervisor_check()
|
57
59
|
if "default" in kwargs:
|
58
|
-
cast(ReviewKwargs[None], kwargs)["default"] = None
|
60
|
+
cast("ReviewKwargs[None]", kwargs)["default"] = None
|
59
61
|
return await self.propose(
|
60
62
|
obj.__class__,
|
61
63
|
TEMPLATE_MANAGER.render_template(
|
@@ -89,7 +91,7 @@ class Correct(Review):
|
|
89
91
|
await review_res.supervisor_check()
|
90
92
|
|
91
93
|
if "default" in kwargs:
|
92
|
-
cast(ReviewKwargs[None], kwargs)["default"] = None
|
94
|
+
cast("ReviewKwargs[None]", kwargs)["default"] = None
|
93
95
|
return await self.ageneric_string(
|
94
96
|
TEMPLATE_MANAGER.render_template(
|
95
97
|
configs.templates.correct_template, {"content": input_text, "review": review_res.display()}
|
@@ -113,3 +115,33 @@ class Correct(Review):
|
|
113
115
|
Optional[Task[T]]: The corrected task, or None if correction fails.
|
114
116
|
"""
|
115
117
|
return await self.correct_obj(task, **kwargs)
|
118
|
+
|
119
|
+
async def censor_obj[M: CensoredAble](
|
120
|
+
self, obj: M, **kwargs: Unpack[CensoredCorrectKwargs[ReviewResult[str]]]
|
121
|
+
) -> M:
|
122
|
+
"""Censor and correct an object based on defined criteria and templates.
|
123
|
+
|
124
|
+
Args:
|
125
|
+
obj (M): The object to be reviewed and corrected.
|
126
|
+
**kwargs (Unpack[CensoredCorrectKwargs]): Additional keyword
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
M: The censored and corrected object.
|
130
|
+
"""
|
131
|
+
last_modified_obj = obj
|
132
|
+
modified_obj = None
|
133
|
+
rprint(obj.finalized_dump())
|
134
|
+
while await confirm("Begin to correct obj above with human censorship?").ask_async():
|
135
|
+
while (topic := await text("What is the topic of the obj reviewing?").ask_async()) is not None and topic:
|
136
|
+
...
|
137
|
+
if (
|
138
|
+
modified_obj := await self.correct_obj(
|
139
|
+
last_modified_obj,
|
140
|
+
topic=topic,
|
141
|
+
**kwargs,
|
142
|
+
)
|
143
|
+
) is None:
|
144
|
+
break
|
145
|
+
last_modified_obj = modified_obj
|
146
|
+
rprint(last_modified_obj.finalized_dump())
|
147
|
+
return modified_obj or last_modified_obj
|