fabricatio 0.2.13.dev2__cp312-cp312-manylinux_2_34_x86_64.whl → 0.3.13__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.
Files changed (41) hide show
  1. fabricatio/__init__.py +3 -3
  2. fabricatio/actions/article.py +32 -34
  3. fabricatio/actions/article_rag.py +89 -69
  4. fabricatio/actions/output.py +22 -21
  5. fabricatio/actions/rag.py +4 -3
  6. fabricatio/capabilities/check.py +29 -30
  7. fabricatio/capabilities/correct.py +23 -23
  8. fabricatio/capabilities/extract.py +36 -32
  9. fabricatio/capabilities/rag.py +34 -35
  10. fabricatio/capabilities/rating.py +77 -72
  11. fabricatio/capabilities/review.py +12 -11
  12. fabricatio/capabilities/task.py +4 -5
  13. fabricatio/core.py +22 -24
  14. fabricatio/decorators.py +10 -10
  15. fabricatio/fs/__init__.py +1 -2
  16. fabricatio/journal.py +2 -9
  17. fabricatio/models/action.py +2 -1
  18. fabricatio/models/extra/aricle_rag.py +10 -9
  19. fabricatio/models/extra/article_base.py +30 -6
  20. fabricatio/models/extra/article_main.py +11 -10
  21. fabricatio/models/extra/article_outline.py +5 -36
  22. fabricatio/models/generic.py +31 -59
  23. fabricatio/models/role.py +5 -3
  24. fabricatio/models/task.py +9 -9
  25. fabricatio/models/tool.py +5 -4
  26. fabricatio/models/usages.py +170 -161
  27. fabricatio/parser.py +2 -2
  28. fabricatio/rust.cpython-312-x86_64-linux-gnu.so +0 -0
  29. fabricatio/rust.pyi +496 -14
  30. fabricatio-0.3.13.data/scripts/tdown +0 -0
  31. {fabricatio-0.2.13.dev2.data → fabricatio-0.3.13.data}/scripts/ttm +0 -0
  32. {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/METADATA +1 -3
  33. fabricatio-0.3.13.dist-info/RECORD +63 -0
  34. fabricatio/config.py +0 -430
  35. fabricatio/constants.py +0 -20
  36. fabricatio/models/events.py +0 -120
  37. fabricatio/rust_instances.py +0 -10
  38. fabricatio-0.2.13.dev2.data/scripts/tdown +0 -0
  39. fabricatio-0.2.13.dev2.dist-info/RECORD +0 -67
  40. {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/WHEEL +0 -0
  41. {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/licenses/LICENSE +0 -0
fabricatio/__init__.py CHANGED
@@ -1,19 +1,19 @@
1
1
  """Fabricatio is a Python library for building llm app using event-based agent structure."""
2
2
 
3
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, BibManager, Event
4
+
3
5
  from fabricatio import actions, capabilities, toolboxes, workflows
4
6
  from fabricatio.core import env
5
7
  from fabricatio.journal import logger
6
8
  from fabricatio.models import extra
7
9
  from fabricatio.models.action import Action, WorkFlow
8
- from fabricatio.models.events import Event
9
10
  from fabricatio.models.role import Role
10
11
  from fabricatio.models.task import Task
11
12
  from fabricatio.models.tool import ToolBox
12
13
  from fabricatio.parser import Capture, GenericCapture, JsonCapture, PythonCapture
13
- from fabricatio.rust import BibManager
14
- from fabricatio.rust_instances import TEMPLATE_MANAGER
15
14
 
16
15
  __all__ = [
16
+ "CONFIG",
17
17
  "TEMPLATE_MANAGER",
18
18
  "Action",
19
19
  "BibManager",
@@ -4,15 +4,14 @@ 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
7
8
  from more_itertools import filter_map
8
9
  from pydantic import Field
9
10
  from rich import print as r_print
10
11
 
11
- from fabricatio import TEMPLATE_MANAGER
12
12
  from fabricatio.capabilities.censor import Censor
13
13
  from fabricatio.capabilities.extract import Extract
14
14
  from fabricatio.capabilities.propose import Propose
15
- from fabricatio.config import configs
16
15
  from fabricatio.fs import dump_text, safe_text_read
17
16
  from fabricatio.journal import logger
18
17
  from fabricatio.models.action import Action
@@ -24,7 +23,6 @@ from fabricatio.models.extra.rule import RuleSet
24
23
  from fabricatio.models.kwargs_types import ValidateKwargs
25
24
  from fabricatio.models.task import Task
26
25
  from fabricatio.models.usages import LLMUsage
27
- from fabricatio.rust import BibManager, detect_language
28
26
  from fabricatio.utils import ok, wrapp_in_block
29
27
 
30
28
 
@@ -40,10 +38,10 @@ class ExtractArticleEssence(Action, Propose):
40
38
  """The key of the output data."""
41
39
 
42
40
  async def _execute(
43
- self,
44
- task_input: Task,
45
- reader: Callable[[str], Optional[str]] = lambda p: Path(p).read_text(encoding="utf-8"),
46
- **_,
41
+ self,
42
+ task_input: Task,
43
+ reader: Callable[[str], Optional[str]] = lambda p: Path(p).read_text(encoding="utf-8"),
44
+ **_,
47
45
  ) -> List[ArticleEssence]:
48
46
  if not task_input.dependencies:
49
47
  logger.info(err := "Task not approved, since no dependencies are provided.")
@@ -56,11 +54,11 @@ class ExtractArticleEssence(Action, Propose):
56
54
  out = []
57
55
 
58
56
  for ess in await self.propose(
59
- ArticleEssence,
60
- [
61
- 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)}`"
62
- for c in contents
63
- ],
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
+ ],
64
62
  ):
65
63
  if ess is None:
66
64
  logger.warning("Could not extract article essence")
@@ -77,10 +75,10 @@ class FixArticleEssence(Action):
77
75
  """The key of the output data."""
78
76
 
79
77
  async def _execute(
80
- self,
81
- bib_mgr: BibManager,
82
- article_essence: List[ArticleEssence],
83
- **_,
78
+ self,
79
+ bib_mgr: BibManager,
80
+ article_essence: List[ArticleEssence],
81
+ **_,
84
82
  ) -> List[ArticleEssence]:
85
83
  out = []
86
84
  count = 0
@@ -107,11 +105,11 @@ class GenerateArticleProposal(Action, Propose):
107
105
  """The key of the output data."""
108
106
 
109
107
  async def _execute(
110
- self,
111
- task_input: Optional[Task] = None,
112
- article_briefing: Optional[str] = None,
113
- article_briefing_path: Optional[str] = None,
114
- **_,
108
+ self,
109
+ task_input: Optional[Task] = None,
110
+ article_briefing: Optional[str] = None,
111
+ article_briefing_path: Optional[str] = None,
112
+ **_,
115
113
  ) -> Optional[ArticleProposal]:
116
114
  if article_briefing is None and article_briefing_path is None and task_input is None:
117
115
  logger.error("Task not approved, since all inputs are None.")
@@ -150,10 +148,10 @@ class GenerateInitialOutline(Action, Extract):
150
148
  """The kwargs to extract the outline."""
151
149
 
152
150
  async def _execute(
153
- self,
154
- article_proposal: ArticleProposal,
155
- supervisor: Optional[bool] = None,
156
- **_,
151
+ self,
152
+ article_proposal: ArticleProposal,
153
+ supervisor: Optional[bool] = None,
154
+ **_,
157
155
  ) -> Optional[ArticleOutline]:
158
156
  req = (
159
157
  f"Design each chapter of a proper and academic and ready for release manner.\n"
@@ -208,10 +206,10 @@ class FixIntrospectedErrors(Action, Censor):
208
206
  """The maximum number of errors to fix."""
209
207
 
210
208
  async def _execute(
211
- self,
212
- article_outline: ArticleOutline,
213
- intro_fix_ruleset: Optional[RuleSet] = None,
214
- **_,
209
+ self,
210
+ article_outline: ArticleOutline,
211
+ intro_fix_ruleset: Optional[RuleSet] = None,
212
+ **_,
215
213
  ) -> Optional[ArticleOutline]:
216
214
  counter = 0
217
215
  origin = article_outline
@@ -243,10 +241,10 @@ class GenerateArticle(Action, Censor):
243
241
  ruleset: Optional[RuleSet] = None
244
242
 
245
243
  async def _execute(
246
- self,
247
- article_outline: ArticleOutline,
248
- article_gen_ruleset: Optional[RuleSet] = None,
249
- **_,
244
+ self,
245
+ article_outline: ArticleOutline,
246
+ article_gen_ruleset: Optional[RuleSet] = None,
247
+ **_,
250
248
  ) -> Optional[Article]:
251
249
  article: Article = Article.from_outline(ok(article_outline, "Article outline not specified.")).update_ref(
252
250
  article_outline
@@ -296,7 +294,7 @@ class WriteChapterSummary(Action, LLMUsage):
296
294
  for raw in (
297
295
  await self.aask(
298
296
  TEMPLATE_MANAGER.render_template(
299
- configs.templates.chap_summary_template,
297
+ CONFIG.templates.chap_summary_template,
300
298
  [
301
299
  {
302
300
  "chapter": a.to_typst_code(),
@@ -4,9 +4,16 @@ 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
+ )
7
15
  from pydantic import Field, PositiveInt
8
16
 
9
- from fabricatio import BibManager
10
17
  from fabricatio.capabilities.advanced_rag import AdvancedRAG
11
18
  from fabricatio.capabilities.censor import Censor
12
19
  from fabricatio.capabilities.extract import Extract
@@ -20,7 +27,6 @@ from fabricatio.models.extra.article_main import Article, ArticleChapter, Articl
20
27
  from fabricatio.models.extra.article_outline import ArticleOutline
21
28
  from fabricatio.models.extra.rule import RuleSet
22
29
  from fabricatio.models.kwargs_types import ChooseKwargs, LLMKwargs
23
- from fabricatio.rust import convert_to_block_formula, convert_to_inline_formula
24
30
  from fabricatio.utils import ok
25
31
 
26
32
  TYPST_CITE_USAGE = (
@@ -28,8 +34,10 @@ TYPST_CITE_USAGE = (
28
34
  "Legal citing syntax examples(seperated by |): [[1]]|[[1,2]]|[[1-3]]|[[12,13-15]]|[[1-3,5-7]]\n"
29
35
  "Illegal citing syntax examples(seperated by |): [[1],[2],[3]]|[[1],[1-2]]\n"
30
36
  "You SHALL not cite a single reference more than once!"
31
- "Those reference mark shall not be omitted during the extraction\n"
32
37
  "It's recommended to cite multiple references that supports your conclusion at a time.\n"
38
+ )
39
+
40
+ TYPST_MATH_USAGE = (
33
41
  "Wrap inline expression with '\\(' and '\\)',like '\\(>5m\\)' '\\(89%\\)', and wrap block equation with '\\[' and '\\]'.\n"
34
42
  "In addition to that, you can add a label outside the block equation which can be used as a cross reference identifier, the label is a string wrapped in `<` and `>` like `<energy-release-rate-equation>`.Note that the label string should be a summarizing title for the equation being labeled and should never be written within the formula block.\n"
35
43
  "you can refer to that label by using the syntax with prefix of `@eqt:`, which indicate that this notation is citing a label from the equations. For example ' @eqt:energy-release-rate-equation ' DO remember that the notation shall have both suffixed and prefixed space char which enable the compiler to distinguish the notation from the plaintext."
@@ -44,7 +52,7 @@ TYPST_CITE_USAGE = (
44
52
  )
45
53
 
46
54
 
47
- class WriteArticleContentRAG(Action, RAG, Extract):
55
+ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
48
56
  """Write an article based on the provided outline."""
49
57
 
50
58
  ctx_override: ClassVar[bool] = True
@@ -56,22 +64,25 @@ class WriteArticleContentRAG(Action, RAG, Extract):
56
64
  """The threshold of relevance"""
57
65
  extractor_model: LLMKwargs
58
66
  """The model to use for extracting the content from the retrieved references."""
59
- query_model: LLMKwargs
67
+ query_model: ChooseKwargs
60
68
  """The model to use for querying the database"""
61
69
  supervisor: bool = False
62
70
  """Whether to use supervisor mode"""
63
71
  result_per_query: PositiveInt = 4
64
72
  """The number of results to be returned per query."""
65
- req: str = TYPST_CITE_USAGE
73
+ cite_req: str = TYPST_CITE_USAGE
74
+ """The req of the write article content."""
75
+
76
+ math_req: str = TYPST_MATH_USAGE
66
77
  """The req of the write article content."""
67
78
  tei_endpoint: Optional[str] = None
68
79
 
69
80
  async def _execute(
70
- self,
71
- article_outline: ArticleOutline,
72
- collection_name: Optional[str] = None,
73
- supervisor: Optional[bool] = None,
74
- **cxt,
81
+ self,
82
+ article_outline: ArticleOutline,
83
+ collection_name: Optional[str] = None,
84
+ supervisor: Optional[bool] = None,
85
+ **cxt,
75
86
  ) -> Article:
76
87
  article = Article.from_outline(article_outline).update_ref(article_outline)
77
88
  self.target_collection = collection_name or self.safe_target_collection
@@ -92,12 +103,12 @@ class WriteArticleContentRAG(Action, RAG, Extract):
92
103
  "questionary", "`questionary` is required for supervisor mode, please install it by `fabricatio[qa]`"
93
104
  )
94
105
  async def _supervisor_inner(
95
- self,
96
- article: Article,
97
- article_outline: ArticleOutline,
98
- chap: ArticleChapter,
99
- sec: ArticleSection,
100
- subsec: ArticleSubsection,
106
+ self,
107
+ article: Article,
108
+ article_outline: ArticleOutline,
109
+ chap: ArticleChapter,
110
+ sec: ArticleSection,
111
+ subsec: ArticleSubsection,
101
112
  ) -> ArticleSubsection:
102
113
  from questionary import confirm, text
103
114
  from rich import print as r_print
@@ -105,29 +116,33 @@ class WriteArticleContentRAG(Action, RAG, Extract):
105
116
  cm = CitationManager()
106
117
  await self.search_database(article, article_outline, chap, sec, subsec, cm)
107
118
 
108
- raw = await self.write_raw(article, article_outline, chap, sec, subsec, cm)
109
- r_print(raw)
119
+ raw_paras = await self.write_raw(article, article_outline, chap, sec, subsec, cm)
120
+ r_print(raw_paras)
110
121
 
111
122
  while not await confirm("Accept this version and continue?").ask_async():
112
123
  if inst := await text("Search for more refs for additional spec.").ask_async():
113
124
  await self.search_database(article, article_outline, chap, sec, subsec, cm, extra_instruction=inst)
114
125
 
115
126
  if instruction := await text("Enter the instructions to improve").ask_async():
116
- raw = await self.write_raw(article, article_outline, chap, sec, subsec, cm, instruction)
117
- if edt := await text("Edit", default=raw).ask_async():
118
- raw = edt
127
+ raw_paras = await self.write_raw(article, article_outline, chap, sec, subsec, cm, instruction)
128
+ if edt := await text("Edit", default=raw_paras).ask_async():
129
+ raw_paras = edt
130
+
131
+ raw_paras = fix_misplaced_labels(raw_paras)
132
+ raw_paras = convert_all_inline_tex(raw_paras)
133
+ raw_paras = convert_all_block_tex(raw_paras)
119
134
 
120
- r_print(raw)
135
+ r_print(raw_paras)
121
136
 
122
- return await self.extract_new_subsec(subsec, raw, cm)
137
+ return await self.extract_new_subsec(subsec, raw_paras, cm)
123
138
 
124
139
  async def _inner(
125
- self,
126
- article: Article,
127
- article_outline: ArticleOutline,
128
- chap: ArticleChapter,
129
- sec: ArticleSection,
130
- subsec: ArticleSubsection,
140
+ self,
141
+ article: Article,
142
+ article_outline: ArticleOutline,
143
+ chap: ArticleChapter,
144
+ sec: ArticleSection,
145
+ subsec: ArticleSubsection,
131
146
  ) -> ArticleSubsection:
132
147
  cm = CitationManager()
133
148
 
@@ -137,10 +152,14 @@ class WriteArticleContentRAG(Action, RAG, Extract):
137
152
 
138
153
  raw_paras = "\n".join(p for p in raw_paras.splitlines() if p and not p.endswith("**") and not p.startswith("#"))
139
154
 
155
+ raw_paras = fix_misplaced_labels(raw_paras)
156
+ raw_paras = convert_all_inline_tex(raw_paras)
157
+ raw_paras = convert_all_block_tex(raw_paras)
158
+
140
159
  return await self.extract_new_subsec(subsec, raw_paras, cm)
141
160
 
142
161
  async def extract_new_subsec(
143
- self, subsec: ArticleSubsection, raw_paras: str, cm: CitationManager
162
+ self, subsec: ArticleSubsection, raw_paras: str, cm: CitationManager
144
163
  ) -> ArticleSubsection:
145
164
  """Extract the new subsec."""
146
165
  new_subsec = ok(
@@ -148,12 +167,13 @@ class WriteArticleContentRAG(Action, RAG, Extract):
148
167
  ArticleSubsection,
149
168
  raw_paras,
150
169
  f"Above is the subsection titled `{subsec.title}`.\n"
151
- f"I need you to extract the content to update my subsection obj provided below.\n{self.req}"
152
- f"{subsec.display()}\n",
170
+ f"I need you to extract the content to construct a new `{ArticleSubsection.__class__.__name__}`,"
171
+ f"Do not attempt to change the original content, your job is ONLY content extraction",
153
172
  **self.extractor_model,
154
173
  ),
155
174
  "Failed to propose new subsection.",
156
175
  )
176
+
157
177
  for p in new_subsec.paragraphs:
158
178
  p.content = cm.apply(p.content)
159
179
  p.description = cm.apply(p.description)
@@ -162,14 +182,14 @@ class WriteArticleContentRAG(Action, RAG, Extract):
162
182
  return subsec
163
183
 
164
184
  async def write_raw(
165
- self,
166
- article: Article,
167
- article_outline: ArticleOutline,
168
- chap: ArticleChapter,
169
- sec: ArticleSection,
170
- subsec: ArticleSubsection,
171
- cm: CitationManager,
172
- extra_instruction: str = "",
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 = "",
173
193
  ) -> str:
174
194
  """Write the raw paragraphs of the subsec."""
175
195
  return await self.aask(
@@ -177,7 +197,7 @@ class WriteArticleContentRAG(Action, RAG, Extract):
177
197
  f"{article_outline.finalized_dump()}\n\nAbove is my article outline, I m writing graduate thesis titled `{article.title}`. "
178
198
  f"More specifically, i m witting the Chapter `{chap.title}` >> Section `{sec.title}` >> Subsection `{subsec.title}`.\n"
179
199
  f"Please help me write the paragraphs of the subsec mentioned above, which is `{subsec.title}`.\n"
180
- f"{self.req}\n"
200
+ f"{self.cite_req}\n{self.math_req}\n"
181
201
  f"You SHALL use `{article.language}` as writing language.\n{extra_instruction}\n"
182
202
  f"Do not use numbered list to display the outcome, you should regard you are writing the main text of the thesis.\n"
183
203
  f"You should not copy others' works from the references directly on to my thesis, we can only harness the conclusion they have drawn.\n"
@@ -185,14 +205,14 @@ class WriteArticleContentRAG(Action, RAG, Extract):
185
205
  )
186
206
 
187
207
  async def search_database(
188
- self,
189
- article: Article,
190
- article_outline: ArticleOutline,
191
- chap: ArticleChapter,
192
- sec: ArticleSection,
193
- subsec: ArticleSubsection,
194
- cm: CitationManager,
195
- extra_instruction: str = "",
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 = "",
196
216
  ) -> None:
197
217
  """Search database for related references."""
198
218
  search_req = (
@@ -206,11 +226,11 @@ class WriteArticleContentRAG(Action, RAG, Extract):
206
226
  await self.clued_search(
207
227
  search_req,
208
228
  cm,
209
- refinery_kwargs=self.ref_q_model,
229
+ refinery_kwargs=self.query_model,
210
230
  expand_multiplier=self.search_increment_multiplier,
211
231
  base_accepted=self.ref_limit,
212
- result_per_query=self.ref_per_q,
213
- similarity_threshold=self.similarity_threshold,
232
+ result_per_query=self.result_per_query,
233
+ similarity_threshold=self.threshold,
214
234
  tei_endpoint=self.tei_endpoint,
215
235
  )
216
236
 
@@ -301,12 +321,12 @@ class TweakArticleRAG(Action, RAG, Censor):
301
321
  """The limit of references to be retrieved"""
302
322
 
303
323
  async def _execute(
304
- self,
305
- article: Article,
306
- collection_name: str = "article_essence",
307
- twk_rag_ruleset: Optional[RuleSet] = None,
308
- parallel: bool = False,
309
- **cxt,
324
+ self,
325
+ article: Article,
326
+ collection_name: str = "article_essence",
327
+ twk_rag_ruleset: Optional[RuleSet] = None,
328
+ parallel: bool = False,
329
+ **cxt,
310
330
  ) -> Article:
311
331
  """Write an article based on the provided outline.
312
332
 
@@ -361,10 +381,10 @@ class TweakArticleRAG(Action, RAG, Censor):
361
381
  subsec,
362
382
  ruleset=ruleset,
363
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"
364
- f"You can use Reference above to rewrite the `{subsec.__class__.__name__}`.\n"
365
- f"You should Always use `{subsec.language}` as written language, "
366
- f"which is the original language of the `{subsec.title}`. "
367
- f"since rewrite a `{subsec.__class__.__name__}` in a different language is usually a bad choice",
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",
368
388
  )
369
389
 
370
390
 
@@ -379,12 +399,12 @@ class ChunkArticle(Action):
379
399
  """The maximum overlapping rate between chunks."""
380
400
 
381
401
  async def _execute(
382
- self,
383
- article_path: str | Path,
384
- bib_manager: BibManager,
385
- max_chunk_size: Optional[int] = None,
386
- max_overlapping_rate: Optional[float] = None,
387
- **_,
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
+ **_,
388
408
  ) -> List[ArticleChunk]:
389
409
  return ArticleChunk.from_file(
390
410
  article_path,
@@ -3,7 +3,8 @@
3
3
  from pathlib import Path
4
4
  from typing import Any, Iterable, List, Mapping, Optional, Type
5
5
 
6
- from fabricatio import TEMPLATE_MANAGER
6
+ from fabricatio.rust import TEMPLATE_MANAGER
7
+
7
8
  from fabricatio.fs import dump_text
8
9
  from fabricatio.journal import logger
9
10
  from fabricatio.models.action import Action
@@ -20,11 +21,11 @@ class DumpFinalizedOutput(Action, LLMUsage):
20
21
  dump_path: Optional[str] = None
21
22
 
22
23
  async def _execute(
23
- self,
24
- to_dump: FinalizedDumpAble,
25
- task_input: Optional[Task] = None,
26
- dump_path: Optional[str | Path] = None,
27
- **_,
24
+ self,
25
+ to_dump: FinalizedDumpAble,
26
+ task_input: Optional[Task] = None,
27
+ dump_path: Optional[str | Path] = None,
28
+ **_,
28
29
  ) -> str:
29
30
  dump_path = Path(
30
31
  dump_path
@@ -51,11 +52,11 @@ class RenderedDump(Action, LLMUsage):
51
52
  """The template name to render the data."""
52
53
 
53
54
  async def _execute(
54
- self,
55
- to_dump: FinalizedDumpAble,
56
- task_input: Optional[Task] = None,
57
- dump_path: Optional[str | Path] = None,
58
- **_,
55
+ self,
56
+ to_dump: FinalizedDumpAble,
57
+ task_input: Optional[Task] = None,
58
+ dump_path: Optional[str | Path] = None,
59
+ **_,
59
60
  ) -> str:
60
61
  dump_path = Path(
61
62
  dump_path
@@ -90,10 +91,10 @@ class PersistentAll(Action, LLMUsage):
90
91
  """Whether to remove the existing dir before dumping."""
91
92
 
92
93
  async def _execute(
93
- self,
94
- task_input: Optional[Task] = None,
95
- persist_dir: Optional[str | Path] = None,
96
- **cxt,
94
+ self,
95
+ task_input: Optional[Task] = None,
96
+ persist_dir: Optional[str | Path] = None,
97
+ **cxt,
97
98
  ) -> int:
98
99
  persist_dir = Path(
99
100
  persist_dir
@@ -123,7 +124,7 @@ class PersistentAll(Action, LLMUsage):
123
124
  v.persist(final_dir)
124
125
  count += 1
125
126
  if isinstance(v, Iterable) and any(
126
- persistent_ables := (pers for pers in v if isinstance(pers, PersistentAble))
127
+ persistent_ables := (pers for pers in v if isinstance(pers, PersistentAble))
127
128
  ):
128
129
  logger.info(f"Persisting collection {k} to {final_dir}")
129
130
  final_dir.mkdir(parents=True, exist_ok=True)
@@ -173,11 +174,11 @@ class RetrieveFromLatest[T: PersistentAble](RetrieveFromPersistent[T], FromMappi
173
174
 
174
175
  @classmethod
175
176
  def from_mapping(
176
- cls,
177
- mapping: Mapping[str, str | Path],
178
- *,
179
- retrieve_cls: Type[T],
180
- **kwargs,
177
+ cls,
178
+ mapping: Mapping[str, str | Path],
179
+ *,
180
+ retrieve_cls: Type[T],
181
+ **kwargs,
181
182
  ) -> List["RetrieveFromLatest[T]"]:
182
183
  """Create a list of `RetrieveFromLatest` from the mapping."""
183
184
  return [
fabricatio/actions/rag.py CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  from typing import List, Optional
4
4
 
5
+ from fabricatio.rust import CONFIG
6
+
5
7
  from fabricatio.capabilities.rag import RAG
6
- from fabricatio.config import configs
7
8
  from fabricatio.journal import logger
8
9
  from fabricatio.models.action import Action
9
10
  from fabricatio.models.extra.rag import MilvusClassicModel, MilvusDataBase
@@ -39,9 +40,9 @@ class InjectToDB(Action, RAG):
39
40
  schema=seq[0].as_milvus_schema(
40
41
  ok(
41
42
  self.milvus_dimensions
42
- or configs.rag.milvus_dimensions
43
+ or CONFIG.rag.milvus_dimensions
43
44
  or self.embedding_dimensions
44
- or configs.embedding.dimensions
45
+ or CONFIG.embedding.dimensions
45
46
  ),
46
47
  ),
47
48
  index_params=IndexParams(