fabricatio 0.3.14.dev1__cp312-cp312-manylinux_2_34_x86_64.whl → 0.3.14.dev3__cp312-cp312-manylinux_2_34_x86_64.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 +5 -6
- fabricatio/actions/article.py +31 -31
- fabricatio/actions/article_rag.py +58 -58
- fabricatio/actions/output.py +58 -24
- fabricatio/actions/rag.py +2 -3
- fabricatio/capabilities/advanced_judge.py +4 -7
- fabricatio/capabilities/advanced_rag.py +2 -1
- fabricatio/capabilities/censor.py +5 -4
- fabricatio/capabilities/check.py +27 -27
- fabricatio/capabilities/correct.py +22 -22
- fabricatio/capabilities/extract.py +33 -33
- fabricatio/capabilities/persist.py +103 -0
- fabricatio/capabilities/propose.py +2 -2
- fabricatio/capabilities/rag.py +37 -37
- fabricatio/capabilities/rating.py +66 -70
- fabricatio/capabilities/review.py +12 -11
- fabricatio/capabilities/task.py +19 -18
- fabricatio/decorators.py +9 -9
- fabricatio/{core.py → emitter.py} +17 -19
- fabricatio/journal.py +2 -1
- fabricatio/models/action.py +9 -11
- fabricatio/models/extra/aricle_rag.py +15 -12
- fabricatio/models/extra/article_base.py +4 -5
- fabricatio/models/extra/article_essence.py +2 -1
- fabricatio/models/extra/article_main.py +5 -4
- fabricatio/models/extra/article_outline.py +2 -1
- fabricatio/models/extra/article_proposal.py +1 -1
- fabricatio/models/extra/rag.py +2 -2
- fabricatio/models/extra/rule.py +2 -1
- fabricatio/models/generic.py +48 -131
- fabricatio/models/kwargs_types.py +1 -9
- fabricatio/models/role.py +14 -13
- fabricatio/models/task.py +3 -4
- fabricatio/models/tool.py +5 -6
- fabricatio/models/usages.py +137 -147
- fabricatio/parser.py +59 -99
- fabricatio/rust.cpython-312-x86_64-linux-gnu.so +0 -0
- fabricatio/rust.pyi +39 -59
- fabricatio/utils.py +6 -170
- fabricatio-0.3.14.dev3.data/scripts/tdown +0 -0
- {fabricatio-0.3.14.dev1.data → fabricatio-0.3.14.dev3.data}/scripts/ttm +0 -0
- {fabricatio-0.3.14.dev1.dist-info → fabricatio-0.3.14.dev3.dist-info}/METADATA +3 -7
- fabricatio-0.3.14.dev3.dist-info/RECORD +64 -0
- fabricatio-0.3.14.dev1.data/scripts/tdown +0 -0
- fabricatio-0.3.14.dev1.dist-info/RECORD +0 -63
- {fabricatio-0.3.14.dev1.dist-info → fabricatio-0.3.14.dev3.dist-info}/WHEEL +0 -0
- {fabricatio-0.3.14.dev1.dist-info → fabricatio-0.3.14.dev3.dist-info}/licenses/LICENSE +0 -0
fabricatio/__init__.py
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
"""Fabricatio is a Python library for building llm app using event-based agent structure."""
|
2
2
|
|
3
|
-
from fabricatio
|
4
|
-
|
5
|
-
from fabricatio import actions, capabilities, parser, toolboxes, workflows
|
3
|
+
from fabricatio import actions, capabilities, fs, models, parser, toolboxes, utils, workflows
|
6
4
|
from fabricatio.journal import logger
|
7
|
-
from fabricatio.models import extra
|
8
5
|
from fabricatio.models.action import Action, WorkFlow
|
9
6
|
from fabricatio.models.role import Role
|
10
7
|
from fabricatio.models.task import Task
|
11
8
|
from fabricatio.models.tool import ToolBox
|
9
|
+
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, Event
|
12
10
|
|
13
11
|
__all__ = [
|
14
12
|
"CONFIG",
|
15
13
|
"TEMPLATE_MANAGER",
|
16
14
|
"Action",
|
17
|
-
"BibManager",
|
18
15
|
"Event",
|
19
16
|
"Role",
|
20
17
|
"Task",
|
@@ -22,9 +19,11 @@ __all__ = [
|
|
22
19
|
"WorkFlow",
|
23
20
|
"actions",
|
24
21
|
"capabilities",
|
25
|
-
"
|
22
|
+
"fs",
|
26
23
|
"logger",
|
24
|
+
"models",
|
27
25
|
"parser",
|
28
26
|
"toolboxes",
|
27
|
+
"utils",
|
29
28
|
"workflows",
|
30
29
|
]
|
fabricatio/actions/article.py
CHANGED
@@ -4,7 +4,6 @@ from asyncio import gather
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import Callable, List, Optional
|
6
6
|
|
7
|
-
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, BibManager, detect_language
|
8
7
|
from more_itertools import filter_map
|
9
8
|
from pydantic import Field
|
10
9
|
from rich import print as r_print
|
@@ -23,6 +22,7 @@ from fabricatio.models.extra.rule import RuleSet
|
|
23
22
|
from fabricatio.models.kwargs_types import ValidateKwargs
|
24
23
|
from fabricatio.models.task import Task
|
25
24
|
from fabricatio.models.usages import LLMUsage
|
25
|
+
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, BibManager, detect_language
|
26
26
|
from fabricatio.utils import ok, wrapp_in_block
|
27
27
|
|
28
28
|
|
@@ -38,10 +38,10 @@ class ExtractArticleEssence(Action, Propose):
|
|
38
38
|
"""The key of the output data."""
|
39
39
|
|
40
40
|
async def _execute(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
self,
|
42
|
+
task_input: Task,
|
43
|
+
reader: Callable[[str], Optional[str]] = lambda p: Path(p).read_text(encoding="utf-8"),
|
44
|
+
**_,
|
45
45
|
) -> List[ArticleEssence]:
|
46
46
|
if not task_input.dependencies:
|
47
47
|
logger.info(err := "Task not approved, since no dependencies are provided.")
|
@@ -54,11 +54,11 @@ class ExtractArticleEssence(Action, Propose):
|
|
54
54
|
out = []
|
55
55
|
|
56
56
|
for ess in await self.propose(
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
ArticleEssence,
|
58
|
+
[
|
59
|
+
f"{c}\n\n\nBased the provided academic article above, you need to extract the essence from it.\n\nWrite the value string using `{detect_language(c)}`"
|
60
|
+
for c in contents
|
61
|
+
],
|
62
62
|
):
|
63
63
|
if ess is None:
|
64
64
|
logger.warning("Could not extract article essence")
|
@@ -75,10 +75,10 @@ class FixArticleEssence(Action):
|
|
75
75
|
"""The key of the output data."""
|
76
76
|
|
77
77
|
async def _execute(
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
self,
|
79
|
+
bib_mgr: BibManager,
|
80
|
+
article_essence: List[ArticleEssence],
|
81
|
+
**_,
|
82
82
|
) -> List[ArticleEssence]:
|
83
83
|
out = []
|
84
84
|
count = 0
|
@@ -105,11 +105,11 @@ class GenerateArticleProposal(Action, Propose):
|
|
105
105
|
"""The key of the output data."""
|
106
106
|
|
107
107
|
async def _execute(
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
self,
|
109
|
+
task_input: Optional[Task] = None,
|
110
|
+
article_briefing: Optional[str] = None,
|
111
|
+
article_briefing_path: Optional[str] = None,
|
112
|
+
**_,
|
113
113
|
) -> Optional[ArticleProposal]:
|
114
114
|
if article_briefing is None and article_briefing_path is None and task_input is None:
|
115
115
|
logger.error("Task not approved, since all inputs are None.")
|
@@ -148,10 +148,10 @@ class GenerateInitialOutline(Action, Extract):
|
|
148
148
|
"""The kwargs to extract the outline."""
|
149
149
|
|
150
150
|
async def _execute(
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
151
|
+
self,
|
152
|
+
article_proposal: ArticleProposal,
|
153
|
+
supervisor: Optional[bool] = None,
|
154
|
+
**_,
|
155
155
|
) -> Optional[ArticleOutline]:
|
156
156
|
req = (
|
157
157
|
f"Design each chapter of a proper and academic and ready for release manner.\n"
|
@@ -206,10 +206,10 @@ class FixIntrospectedErrors(Action, Censor):
|
|
206
206
|
"""The maximum number of errors to fix."""
|
207
207
|
|
208
208
|
async def _execute(
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
209
|
+
self,
|
210
|
+
article_outline: ArticleOutline,
|
211
|
+
intro_fix_ruleset: Optional[RuleSet] = None,
|
212
|
+
**_,
|
213
213
|
) -> Optional[ArticleOutline]:
|
214
214
|
counter = 0
|
215
215
|
origin = article_outline
|
@@ -241,10 +241,10 @@ class GenerateArticle(Action, Censor):
|
|
241
241
|
ruleset: Optional[RuleSet] = None
|
242
242
|
|
243
243
|
async def _execute(
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
244
|
+
self,
|
245
|
+
article_outline: ArticleOutline,
|
246
|
+
article_gen_ruleset: Optional[RuleSet] = None,
|
247
|
+
**_,
|
248
248
|
) -> Optional[Article]:
|
249
249
|
article: Article = Article.from_outline(ok(article_outline, "Article outline not specified.")).update_ref(
|
250
250
|
article_outline
|
@@ -4,14 +4,6 @@ from asyncio import gather
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import ClassVar, List, Optional
|
6
6
|
|
7
|
-
from fabricatio.rust import (
|
8
|
-
BibManager,
|
9
|
-
convert_all_block_tex,
|
10
|
-
convert_all_inline_tex,
|
11
|
-
convert_to_block_formula,
|
12
|
-
convert_to_inline_formula,
|
13
|
-
fix_misplaced_labels,
|
14
|
-
)
|
15
7
|
from pydantic import Field, PositiveInt
|
16
8
|
|
17
9
|
from fabricatio.capabilities.advanced_rag import AdvancedRAG
|
@@ -27,6 +19,14 @@ from fabricatio.models.extra.article_main import Article, ArticleChapter, Articl
|
|
27
19
|
from fabricatio.models.extra.article_outline import ArticleOutline
|
28
20
|
from fabricatio.models.extra.rule import RuleSet
|
29
21
|
from fabricatio.models.kwargs_types import ChooseKwargs, LLMKwargs
|
22
|
+
from fabricatio.rust import (
|
23
|
+
BibManager,
|
24
|
+
convert_all_block_tex,
|
25
|
+
convert_all_inline_tex,
|
26
|
+
convert_to_block_formula,
|
27
|
+
convert_to_inline_formula,
|
28
|
+
fix_misplaced_labels,
|
29
|
+
)
|
30
30
|
from fabricatio.utils import ok
|
31
31
|
|
32
32
|
TYPST_CITE_USAGE = (
|
@@ -78,11 +78,11 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
78
78
|
tei_endpoint: Optional[str] = None
|
79
79
|
|
80
80
|
async def _execute(
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
self,
|
82
|
+
article_outline: ArticleOutline,
|
83
|
+
collection_name: Optional[str] = None,
|
84
|
+
supervisor: Optional[bool] = None,
|
85
|
+
**cxt,
|
86
86
|
) -> Article:
|
87
87
|
article = Article.from_outline(article_outline).update_ref(article_outline)
|
88
88
|
self.target_collection = collection_name or self.safe_target_collection
|
@@ -103,12 +103,12 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
103
103
|
"questionary", "`questionary` is required for supervisor mode, please install it by `fabricatio[qa]`"
|
104
104
|
)
|
105
105
|
async def _supervisor_inner(
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
self,
|
107
|
+
article: Article,
|
108
|
+
article_outline: ArticleOutline,
|
109
|
+
chap: ArticleChapter,
|
110
|
+
sec: ArticleSection,
|
111
|
+
subsec: ArticleSubsection,
|
112
112
|
) -> ArticleSubsection:
|
113
113
|
from questionary import confirm, text
|
114
114
|
from rich import print as r_print
|
@@ -137,12 +137,12 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
137
137
|
return await self.extract_new_subsec(subsec, raw_paras, cm)
|
138
138
|
|
139
139
|
async def _inner(
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
140
|
+
self,
|
141
|
+
article: Article,
|
142
|
+
article_outline: ArticleOutline,
|
143
|
+
chap: ArticleChapter,
|
144
|
+
sec: ArticleSection,
|
145
|
+
subsec: ArticleSubsection,
|
146
146
|
) -> ArticleSubsection:
|
147
147
|
cm = CitationManager()
|
148
148
|
|
@@ -159,7 +159,7 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
159
159
|
return await self.extract_new_subsec(subsec, raw_paras, cm)
|
160
160
|
|
161
161
|
async def extract_new_subsec(
|
162
|
-
|
162
|
+
self, subsec: ArticleSubsection, raw_paras: str, cm: CitationManager
|
163
163
|
) -> ArticleSubsection:
|
164
164
|
"""Extract the new subsec."""
|
165
165
|
new_subsec = ok(
|
@@ -182,14 +182,14 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
182
182
|
return subsec
|
183
183
|
|
184
184
|
async def write_raw(
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
185
|
+
self,
|
186
|
+
article: Article,
|
187
|
+
article_outline: ArticleOutline,
|
188
|
+
chap: ArticleChapter,
|
189
|
+
sec: ArticleSection,
|
190
|
+
subsec: ArticleSubsection,
|
191
|
+
cm: CitationManager,
|
192
|
+
extra_instruction: str = "",
|
193
193
|
) -> str:
|
194
194
|
"""Write the raw paragraphs of the subsec."""
|
195
195
|
return await self.aask(
|
@@ -205,14 +205,14 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
205
205
|
)
|
206
206
|
|
207
207
|
async def search_database(
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
208
|
+
self,
|
209
|
+
article: Article,
|
210
|
+
article_outline: ArticleOutline,
|
211
|
+
chap: ArticleChapter,
|
212
|
+
sec: ArticleSection,
|
213
|
+
subsec: ArticleSubsection,
|
214
|
+
cm: CitationManager,
|
215
|
+
extra_instruction: str = "",
|
216
216
|
) -> None:
|
217
217
|
"""Search database for related references."""
|
218
218
|
search_req = (
|
@@ -321,12 +321,12 @@ class TweakArticleRAG(Action, RAG, Censor):
|
|
321
321
|
"""The limit of references to be retrieved"""
|
322
322
|
|
323
323
|
async def _execute(
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
324
|
+
self,
|
325
|
+
article: Article,
|
326
|
+
collection_name: str = "article_essence",
|
327
|
+
twk_rag_ruleset: Optional[RuleSet] = None,
|
328
|
+
parallel: bool = False,
|
329
|
+
**cxt,
|
330
330
|
) -> Article:
|
331
331
|
"""Write an article based on the provided outline.
|
332
332
|
|
@@ -381,10 +381,10 @@ class TweakArticleRAG(Action, RAG, Censor):
|
|
381
381
|
subsec,
|
382
382
|
ruleset=ruleset,
|
383
383
|
reference=f"{'\n\n'.join(d.display() for d in await self.aretrieve(refind_q, document_model=ArticleEssence, max_accepted=self.ref_limit))}\n\n"
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
384
|
+
f"You can use Reference above to rewrite the `{subsec.__class__.__name__}`.\n"
|
385
|
+
f"You should Always use `{subsec.language}` as written language, "
|
386
|
+
f"which is the original language of the `{subsec.title}`. "
|
387
|
+
f"since rewrite a `{subsec.__class__.__name__}` in a different language is usually a bad choice",
|
388
388
|
)
|
389
389
|
|
390
390
|
|
@@ -399,12 +399,12 @@ class ChunkArticle(Action):
|
|
399
399
|
"""The maximum overlapping rate between chunks."""
|
400
400
|
|
401
401
|
async def _execute(
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
402
|
+
self,
|
403
|
+
article_path: str | Path,
|
404
|
+
bib_manager: BibManager,
|
405
|
+
max_chunk_size: Optional[int] = None,
|
406
|
+
max_overlapping_rate: Optional[float] = None,
|
407
|
+
**_,
|
408
408
|
) -> List[ArticleChunk]:
|
409
409
|
return ArticleChunk.from_file(
|
410
410
|
article_path,
|
fabricatio/actions/output.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
"""Dump the finalized output to a file."""
|
2
2
|
|
3
3
|
from pathlib import Path
|
4
|
-
from typing import Any, Iterable, List, Mapping, Optional, Type
|
5
|
-
|
6
|
-
from fabricatio.rust import TEMPLATE_MANAGER
|
4
|
+
from typing import Any, Iterable, List, Mapping, Optional, Self, Sequence, Type
|
7
5
|
|
6
|
+
from fabricatio.capabilities.persist import PersistentAble
|
8
7
|
from fabricatio.fs import dump_text
|
9
8
|
from fabricatio.journal import logger
|
10
9
|
from fabricatio.models.action import Action
|
11
|
-
from fabricatio.models.generic import FinalizedDumpAble, FromMapping,
|
10
|
+
from fabricatio.models.generic import FinalizedDumpAble, FromMapping, FromSequence
|
12
11
|
from fabricatio.models.task import Task
|
13
12
|
from fabricatio.models.usages import LLMUsage
|
13
|
+
from fabricatio.rust import TEMPLATE_MANAGER
|
14
14
|
from fabricatio.utils import ok
|
15
15
|
|
16
16
|
|
@@ -21,11 +21,11 @@ class DumpFinalizedOutput(Action, LLMUsage):
|
|
21
21
|
dump_path: Optional[str] = None
|
22
22
|
|
23
23
|
async def _execute(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
self,
|
25
|
+
to_dump: FinalizedDumpAble,
|
26
|
+
task_input: Optional[Task] = None,
|
27
|
+
dump_path: Optional[str | Path] = None,
|
28
|
+
**_,
|
29
29
|
) -> str:
|
30
30
|
dump_path = Path(
|
31
31
|
dump_path
|
@@ -52,11 +52,11 @@ class RenderedDump(Action, LLMUsage):
|
|
52
52
|
"""The template name to render the data."""
|
53
53
|
|
54
54
|
async def _execute(
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
self,
|
56
|
+
to_dump: FinalizedDumpAble,
|
57
|
+
task_input: Optional[Task] = None,
|
58
|
+
dump_path: Optional[str | Path] = None,
|
59
|
+
**_,
|
60
60
|
) -> str:
|
61
61
|
dump_path = Path(
|
62
62
|
dump_path
|
@@ -91,10 +91,10 @@ class PersistentAll(Action, LLMUsage):
|
|
91
91
|
"""Whether to remove the existing dir before dumping."""
|
92
92
|
|
93
93
|
async def _execute(
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
self,
|
95
|
+
task_input: Optional[Task] = None,
|
96
|
+
persist_dir: Optional[str | Path] = None,
|
97
|
+
**cxt,
|
98
98
|
) -> int:
|
99
99
|
persist_dir = Path(
|
100
100
|
persist_dir
|
@@ -124,7 +124,7 @@ class PersistentAll(Action, LLMUsage):
|
|
124
124
|
v.persist(final_dir)
|
125
125
|
count += 1
|
126
126
|
if isinstance(v, Iterable) and any(
|
127
|
-
|
127
|
+
persistent_ables := (pers for pers in v if isinstance(pers, PersistentAble))
|
128
128
|
):
|
129
129
|
logger.info(f"Persisting collection {k} to {final_dir}")
|
130
130
|
final_dir.mkdir(parents=True, exist_ok=True)
|
@@ -174,11 +174,11 @@ class RetrieveFromLatest[T: PersistentAble](RetrieveFromPersistent[T], FromMappi
|
|
174
174
|
|
175
175
|
@classmethod
|
176
176
|
def from_mapping(
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
177
|
+
cls,
|
178
|
+
mapping: Mapping[str, str | Path],
|
179
|
+
*,
|
180
|
+
retrieve_cls: Type[T],
|
181
|
+
**kwargs,
|
182
182
|
) -> List["RetrieveFromLatest[T]"]:
|
183
183
|
"""Create a list of `RetrieveFromLatest` from the mapping."""
|
184
184
|
return [
|
@@ -212,3 +212,37 @@ class GatherAsList(Action):
|
|
212
212
|
result = [cxt[k] for k in cxt if k.startswith(self.gather_prefix)]
|
213
213
|
logger.debug(f"Gathered {len(result)} items with prefix {self.gather_prefix}")
|
214
214
|
return result
|
215
|
+
|
216
|
+
|
217
|
+
class Forward(Action, FromMapping, FromSequence):
|
218
|
+
"""Forward the object from the context to the output."""
|
219
|
+
|
220
|
+
output_key: str = "forwarded"
|
221
|
+
"""Gather the objects from the context as a list."""
|
222
|
+
original: str
|
223
|
+
|
224
|
+
async def _execute(self, *_: Any, **cxt) -> Any:
|
225
|
+
source = cxt.get(self.original)
|
226
|
+
if source is None:
|
227
|
+
logger.warning(f"Original object {self.original} not found in the context")
|
228
|
+
return source
|
229
|
+
|
230
|
+
@classmethod
|
231
|
+
def from_sequence(cls, sequence: Sequence[str], *, original: str, **kwargs: Any) -> List[Self]:
|
232
|
+
"""Create a list of `Forward` from the sequence."""
|
233
|
+
return [cls(original=original, output_key=o, **kwargs) for o in sequence]
|
234
|
+
|
235
|
+
@classmethod
|
236
|
+
def from_mapping(cls, mapping: Mapping[str, str | Sequence[str]], **kwargs: Any) -> List[Self]:
|
237
|
+
"""Create a list of `Forward` from the mapping."""
|
238
|
+
actions = []
|
239
|
+
for original_key, output_val in mapping.items():
|
240
|
+
if isinstance(output_val, str):
|
241
|
+
actions.append(cls(original=original_key, output_key=output_val, **kwargs))
|
242
|
+
elif isinstance(output_val, Sequence):
|
243
|
+
actions.extend(cls(original=original_key, output_key=output_key, **kwargs) for output_key in output_val)
|
244
|
+
else:
|
245
|
+
logger.warning(
|
246
|
+
f"Invalid type for output key value in mapping: {type(output_val)} for original key {original_key}. Expected str or Sequence[str]."
|
247
|
+
)
|
248
|
+
return actions
|
fabricatio/actions/rag.py
CHANGED
@@ -2,13 +2,12 @@
|
|
2
2
|
|
3
3
|
from typing import List, Optional
|
4
4
|
|
5
|
-
from fabricatio.rust import CONFIG
|
6
|
-
|
7
5
|
from fabricatio.capabilities.rag import RAG
|
8
6
|
from fabricatio.journal import logger
|
9
7
|
from fabricatio.models.action import Action
|
10
8
|
from fabricatio.models.extra.rag import MilvusClassicModel, MilvusDataBase
|
11
9
|
from fabricatio.models.task import Task
|
10
|
+
from fabricatio.rust import CONFIG
|
12
11
|
from fabricatio.utils import ok
|
13
12
|
|
14
13
|
|
@@ -20,7 +19,7 @@ class InjectToDB(Action, RAG):
|
|
20
19
|
"""The name of the collection to inject data into."""
|
21
20
|
|
22
21
|
async def _execute[T: MilvusDataBase](
|
23
|
-
|
22
|
+
self, to_inject: Optional[T] | List[Optional[T]], override_inject: bool = False, **_
|
24
23
|
) -> Optional[str]:
|
25
24
|
from pymilvus.milvus_client import IndexParams
|
26
25
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
"""The Capabilities module for advanced judging."""
|
2
2
|
|
3
|
+
from abc import ABC
|
3
4
|
from typing import Optional, Unpack
|
4
5
|
|
5
6
|
from fabricatio.capabilities.propose import Propose
|
@@ -7,17 +8,13 @@ from fabricatio.models.extra.advanced_judge import JudgeMent
|
|
7
8
|
from fabricatio.models.kwargs_types import ValidateKwargs
|
8
9
|
|
9
10
|
|
10
|
-
class AdvancedJudge(Propose):
|
11
|
+
class AdvancedJudge(Propose, ABC):
|
11
12
|
"""A class that judges the evidence and makes a final decision."""
|
13
|
+
|
12
14
|
async def evidently_judge(
|
13
15
|
self,
|
14
16
|
prompt: str,
|
15
17
|
**kwargs: Unpack[ValidateKwargs[JudgeMent]],
|
16
18
|
) -> Optional[JudgeMent]:
|
17
19
|
"""Judge the evidence and make a final decision."""
|
18
|
-
return await self.propose(
|
19
|
-
JudgeMent,
|
20
|
-
prompt,
|
21
|
-
**kwargs
|
22
|
-
)
|
23
|
-
|
20
|
+
return await self.propose(JudgeMent, prompt, **kwargs)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
"""Advanced RAG (Retrieval Augmented Generation) model."""
|
2
2
|
|
3
|
+
from abc import ABC
|
3
4
|
from typing import Optional, Unpack
|
4
5
|
|
5
6
|
from fabricatio.capabilities.rag import RAG
|
@@ -10,7 +11,7 @@ from fabricatio.models.kwargs_types import ChooseKwargs
|
|
10
11
|
from fabricatio.utils import fallback_kwargs
|
11
12
|
|
12
13
|
|
13
|
-
class AdvancedRAG(RAG):
|
14
|
+
class AdvancedRAG(RAG, ABC):
|
14
15
|
"""A class representing the Advanced RAG (Retrieval Augmented Generation) model."""
|
15
16
|
|
16
17
|
async def clued_search(
|
@@ -4,6 +4,7 @@ This module includes the Censor class which inherits from both Correct and Check
|
|
4
4
|
It provides methods to censor objects and strings by first checking them against a ruleset and then correcting them if necessary.
|
5
5
|
"""
|
6
6
|
|
7
|
+
from abc import ABC
|
7
8
|
from typing import Optional, Unpack
|
8
9
|
|
9
10
|
from fabricatio.capabilities.check import Check
|
@@ -16,7 +17,7 @@ from fabricatio.models.kwargs_types import ReferencedKwargs
|
|
16
17
|
from fabricatio.utils import override_kwargs
|
17
18
|
|
18
19
|
|
19
|
-
class Censor(Correct, Check):
|
20
|
+
class Censor(Correct, Check, ABC):
|
20
21
|
"""Class to censor objects and strings based on provided rulesets.
|
21
22
|
|
22
23
|
Inherits from both Correct and Check classes.
|
@@ -46,7 +47,7 @@ class Censor(Correct, Check):
|
|
46
47
|
if not imp:
|
47
48
|
logger.info(f"No improvement found for `{obj.__class__.__name__}`.")
|
48
49
|
return obj
|
49
|
-
logger.info(f
|
50
|
+
logger.info(f"Generated {len(imp)} improvement(s) for `{obj.__class__.__name__}")
|
50
51
|
return await self.correct_obj(obj, Improvement.gather(*imp), **kwargs)
|
51
52
|
|
52
53
|
async def censor_string(
|
@@ -72,7 +73,7 @@ class Censor(Correct, Check):
|
|
72
73
|
if not imp:
|
73
74
|
logger.info("No improvement found for string.")
|
74
75
|
return input_text
|
75
|
-
logger.info(f
|
76
|
+
logger.info(f"Generated {len(imp)} improvement(s) for string.")
|
76
77
|
return await self.correct_string(input_text, Improvement.gather(*imp), **kwargs)
|
77
78
|
|
78
79
|
async def censor_obj_inplace[M: ProposedUpdateAble](
|
@@ -100,5 +101,5 @@ class Censor(Correct, Check):
|
|
100
101
|
if not imp:
|
101
102
|
logger.info(f"No improvement found for `{obj.__class__.__name__}`.")
|
102
103
|
return obj
|
103
|
-
logger.info(f
|
104
|
+
logger.info(f"Generated {len(imp)} improvement(s) for `{obj.__class__.__name__}")
|
104
105
|
return await self.correct_obj_inplace(obj, improvement=Improvement.gather(*imp), **kwargs)
|