fabricatio 0.3.14.dev6__cp312-cp312-manylinux_2_34_x86_64.whl → 0.3.15.dev4__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/actions/article.py +115 -19
- fabricatio/actions/article_rag.py +52 -52
- fabricatio/decorators.py +2 -0
- fabricatio/models/extra/aricle_rag.py +4 -5
- fabricatio/models/extra/article_base.py +98 -34
- fabricatio/models/extra/article_main.py +11 -6
- fabricatio/models/generic.py +1 -1
- fabricatio/models/role.py +24 -20
- fabricatio/rust.cpython-312-x86_64-linux-gnu.so +0 -0
- fabricatio/rust.pyi +20 -61
- fabricatio-0.3.15.dev4.data/scripts/tdown +0 -0
- fabricatio-0.3.15.dev4.data/scripts/ttm +0 -0
- {fabricatio-0.3.14.dev6.dist-info → fabricatio-0.3.15.dev4.dist-info}/METADATA +2 -1
- {fabricatio-0.3.14.dev6.dist-info → fabricatio-0.3.15.dev4.dist-info}/RECORD +16 -16
- {fabricatio-0.3.14.dev6.dist-info → fabricatio-0.3.15.dev4.dist-info}/WHEEL +1 -1
- fabricatio-0.3.14.dev6.data/scripts/tdown +0 -0
- fabricatio-0.3.14.dev6.data/scripts/ttm +0 -0
- {fabricatio-0.3.14.dev6.dist-info → fabricatio-0.3.15.dev4.dist-info}/licenses/LICENSE +0 -0
fabricatio/actions/article.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from asyncio import gather
|
4
4
|
from pathlib import Path
|
5
|
-
from typing import Callable, List, Optional
|
5
|
+
from typing import Callable, ClassVar, List, Optional
|
6
6
|
|
7
7
|
from more_itertools import filter_map
|
8
8
|
from pydantic import Field
|
@@ -15,14 +15,14 @@ from fabricatio.fs import dump_text, safe_text_read
|
|
15
15
|
from fabricatio.journal import logger
|
16
16
|
from fabricatio.models.action import Action
|
17
17
|
from fabricatio.models.extra.article_essence import ArticleEssence
|
18
|
-
from fabricatio.models.extra.article_main import Article
|
18
|
+
from fabricatio.models.extra.article_main import Article, ArticleChapter, ArticleSubsection
|
19
19
|
from fabricatio.models.extra.article_outline import ArticleOutline
|
20
20
|
from fabricatio.models.extra.article_proposal import ArticleProposal
|
21
21
|
from fabricatio.models.extra.rule import RuleSet
|
22
22
|
from fabricatio.models.kwargs_types import ValidateKwargs
|
23
23
|
from fabricatio.models.task import Task
|
24
24
|
from fabricatio.models.usages import LLMUsage
|
25
|
-
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, BibManager, detect_language
|
25
|
+
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, BibManager, detect_language, word_count
|
26
26
|
from fabricatio.utils import ok, wrapp_in_block
|
27
27
|
|
28
28
|
|
@@ -277,43 +277,139 @@ class LoadArticle(Action):
|
|
277
277
|
class WriteChapterSummary(Action, LLMUsage):
|
278
278
|
"""Write the chapter summary."""
|
279
279
|
|
280
|
-
|
280
|
+
ctx_override: ClassVar[bool] = True
|
281
281
|
|
282
282
|
paragraph_count: int = 1
|
283
|
+
"""The number of paragraphs to generate in the chapter summary."""
|
283
284
|
|
284
|
-
summary_word_count: int =
|
285
|
-
|
285
|
+
summary_word_count: int = 120
|
286
|
+
"""The number of words to use in each chapter summary."""
|
287
|
+
output_key: str = "summarized_article"
|
288
|
+
"""The key under which the summarized article will be stored in the output."""
|
286
289
|
summary_title: str = "Chapter Summary"
|
287
|
-
|
290
|
+
"""The title to be used for the generated chapter summary section."""
|
291
|
+
|
292
|
+
skip_chapters: List[str] = Field(default_factory=list)
|
293
|
+
"""A list of chapter titles to skip during summary generation."""
|
294
|
+
|
295
|
+
async def _execute(self, article_path: Path, **cxt) -> Article:
|
296
|
+
article = Article.from_article_file(article_path, article_path.stem)
|
297
|
+
|
298
|
+
chaps = [c for c in article.chapters if c.title not in self.skip_chapters]
|
299
|
+
|
300
|
+
retained_chapters = []
|
301
|
+
# Count chapters before filtering based on section presence,
|
302
|
+
# chaps at this point has already been filtered by self.skip_chapters
|
303
|
+
initial_chaps_for_summary_step_count = len(chaps)
|
304
|
+
|
305
|
+
for chapter_candidate in chaps:
|
306
|
+
if chapter_candidate.sections: # Check if the sections list is non-empty
|
307
|
+
retained_chapters.append(chapter_candidate)
|
308
|
+
else:
|
309
|
+
# Log c warning for each chapter skipped due to lack of sections
|
310
|
+
logger.warning(
|
311
|
+
f"Chapter '{chapter_candidate.title}' has no sections and will be skipped for summary generation."
|
312
|
+
)
|
313
|
+
|
314
|
+
chaps = retained_chapters # Update chaps to only include chapters with sections
|
288
315
|
|
289
|
-
|
290
|
-
|
316
|
+
# If chaps is now empty, but there were chapters to consider at the start of this step,
|
317
|
+
# log c specific warning.
|
318
|
+
if not chaps and initial_chaps_for_summary_step_count > 0:
|
319
|
+
raise ValueError("No chapters with sections were found. Please check your input data.")
|
291
320
|
|
321
|
+
# This line was part of the original selection.
|
322
|
+
# It will now log the titles of the chapters that are actually being processed (those with sections).
|
323
|
+
# If 'chaps' is empty, this will result in logger.info(""), which is acceptable.
|
324
|
+
logger.info(";".join(a.title for a in chaps))
|
292
325
|
ret = [
|
293
|
-
|
326
|
+
ArticleSubsection.from_typst_code(self.summary_title, raw)
|
294
327
|
for raw in (
|
295
328
|
await self.aask(
|
296
329
|
TEMPLATE_MANAGER.render_template(
|
297
330
|
CONFIG.templates.chap_summary_template,
|
298
331
|
[
|
299
332
|
{
|
300
|
-
"chapter":
|
301
|
-
"title":
|
302
|
-
"language":
|
333
|
+
"chapter": c.to_typst_code(),
|
334
|
+
"title": c.title,
|
335
|
+
"language": c.language,
|
303
336
|
"summary_word_count": self.summary_word_count,
|
304
337
|
"paragraph_count": self.paragraph_count,
|
305
338
|
}
|
306
|
-
for
|
339
|
+
for c in chaps
|
307
340
|
],
|
308
341
|
)
|
309
342
|
)
|
310
343
|
)
|
311
344
|
]
|
312
345
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
346
|
+
for c, n in zip(chaps, ret, strict=True):
|
347
|
+
c: ArticleChapter
|
348
|
+
n: ArticleSubsection
|
349
|
+
if c.sections[-1].title == self.summary_title:
|
350
|
+
logger.debug(f"Removing old summary `{self.summary_title}` at {c.title}")
|
351
|
+
c.sections.pop()
|
352
|
+
|
353
|
+
c.sections[-1].subsections.append(n)
|
354
|
+
|
355
|
+
article.update_article_file(article_path)
|
356
|
+
|
357
|
+
dump_text(
|
358
|
+
article_path, safe_text_read(article_path).replace(f"=== {self.summary_title}", f"== {self.summary_title}")
|
359
|
+
)
|
360
|
+
return article
|
361
|
+
|
362
|
+
|
363
|
+
class WriteResearchContentSummary(Action, LLMUsage):
|
364
|
+
"""Write the research content summary."""
|
365
|
+
|
366
|
+
ctx_override: ClassVar[bool] = True
|
367
|
+
summary_word_count: int = 160
|
368
|
+
"""The number of words to use in the research content summary."""
|
369
|
+
|
370
|
+
output_key: str = "summarized_article"
|
371
|
+
"""The key under which the summarized article will be stored in the output."""
|
372
|
+
|
373
|
+
summary_title: str = "Research Content"
|
374
|
+
"""The title to be used for the generated research content summary section."""
|
375
|
+
|
376
|
+
paragraph_count: int = 1
|
377
|
+
"""The number of paragraphs to generate in the research content summary."""
|
378
|
+
|
379
|
+
async def _execute(self, article_path: Path, **cxt) -> Article:
|
380
|
+
article = Article.from_article_file(article_path, article_path.stem)
|
381
|
+
if not article.chapters:
|
382
|
+
raise ValueError("No chapters found in the article.")
|
383
|
+
chap_1 = article.chapters[0]
|
384
|
+
if not chap_1.sections:
|
385
|
+
raise ValueError("No sections found in the first chapter of the article.")
|
386
|
+
|
387
|
+
outline = article.extrac_outline()
|
388
|
+
suma: str = await self.aask(
|
389
|
+
TEMPLATE_MANAGER.render_template(
|
390
|
+
CONFIG.templates.research_content_summary_template,
|
391
|
+
{
|
392
|
+
"title": outline.title,
|
393
|
+
"outline": outline.to_typst_code(),
|
394
|
+
"language": detect_language(self.summary_title),
|
395
|
+
"summary_word_count": self.summary_word_count,
|
396
|
+
"paragraph_count": self.paragraph_count,
|
397
|
+
},
|
317
398
|
)
|
399
|
+
)
|
400
|
+
logger.success(
|
401
|
+
f"{self.summary_title}|Wordcount: {word_count(suma)}|Expected: {self.summary_word_count}\n{suma}"
|
402
|
+
)
|
403
|
+
|
404
|
+
if chap_1.sections[-1].title == self.summary_title:
|
405
|
+
# remove old
|
406
|
+
logger.debug(f"Removing old summary `{self.summary_title}`")
|
407
|
+
chap_1.sections.pop()
|
318
408
|
|
319
|
-
|
409
|
+
chap_1.sections[-1].subsections.append(ArticleSubsection.from_typst_code(self.summary_title, suma))
|
410
|
+
|
411
|
+
article.update_article_file(article_path)
|
412
|
+
dump_text(
|
413
|
+
article_path, safe_text_read(article_path).replace(f"=== {self.summary_title}", f"== {self.summary_title}")
|
414
|
+
)
|
415
|
+
return article
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"""A module for writing articles using RAG (Retrieval-Augmented Generation) capabilities."""
|
2
2
|
|
3
3
|
from asyncio import gather
|
4
|
-
|
5
4
|
from pathlib import Path
|
6
|
-
from pydantic import Field, PositiveInt
|
7
5
|
from typing import ClassVar, List, Optional
|
8
6
|
|
7
|
+
from pydantic import Field, PositiveInt
|
8
|
+
|
9
9
|
from fabricatio.capabilities.advanced_rag import AdvancedRAG
|
10
10
|
from fabricatio.capabilities.censor import Censor
|
11
11
|
from fabricatio.capabilities.extract import Extract
|
@@ -75,11 +75,11 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
75
75
|
tei_endpoint: Optional[str] = None
|
76
76
|
|
77
77
|
async def _execute(
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
self,
|
79
|
+
article_outline: ArticleOutline,
|
80
|
+
collection_name: Optional[str] = None,
|
81
|
+
supervisor: Optional[bool] = None,
|
82
|
+
**cxt,
|
83
83
|
) -> Article:
|
84
84
|
article = Article.from_outline(article_outline).update_ref(article_outline)
|
85
85
|
self.target_collection = collection_name or self.safe_target_collection
|
@@ -100,12 +100,12 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
100
100
|
"questionary", "`questionary` is required for supervisor mode, please install it by `fabricatio[qa]`"
|
101
101
|
)
|
102
102
|
async def _supervisor_inner(
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
103
|
+
self,
|
104
|
+
article: Article,
|
105
|
+
article_outline: ArticleOutline,
|
106
|
+
chap: ArticleChapter,
|
107
|
+
sec: ArticleSection,
|
108
|
+
subsec: ArticleSubsection,
|
109
109
|
) -> ArticleSubsection:
|
110
110
|
from questionary import confirm, text
|
111
111
|
from rich import print as r_print
|
@@ -133,12 +133,12 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
133
133
|
return await self.extract_new_subsec(subsec, raw_paras, cm)
|
134
134
|
|
135
135
|
async def _inner(
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
136
|
+
self,
|
137
|
+
article: Article,
|
138
|
+
article_outline: ArticleOutline,
|
139
|
+
chap: ArticleChapter,
|
140
|
+
sec: ArticleSection,
|
141
|
+
subsec: ArticleSubsection,
|
142
142
|
) -> ArticleSubsection:
|
143
143
|
cm = CitationManager()
|
144
144
|
|
@@ -154,7 +154,7 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
154
154
|
return await self.extract_new_subsec(subsec, raw_paras, cm)
|
155
155
|
|
156
156
|
async def extract_new_subsec(
|
157
|
-
|
157
|
+
self, subsec: ArticleSubsection, raw_paras: str, cm: CitationManager
|
158
158
|
) -> ArticleSubsection:
|
159
159
|
"""Extract the new subsec."""
|
160
160
|
new_subsec = ok(
|
@@ -177,14 +177,14 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
177
177
|
return subsec
|
178
178
|
|
179
179
|
async def write_raw(
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
180
|
+
self,
|
181
|
+
article: Article,
|
182
|
+
article_outline: ArticleOutline,
|
183
|
+
chap: ArticleChapter,
|
184
|
+
sec: ArticleSection,
|
185
|
+
subsec: ArticleSubsection,
|
186
|
+
cm: CitationManager,
|
187
|
+
extra_instruction: str = "",
|
188
188
|
) -> str:
|
189
189
|
"""Write the raw paragraphs of the subsec."""
|
190
190
|
return await self.aask(
|
@@ -200,14 +200,14 @@ class WriteArticleContentRAG(Action, Extract, AdvancedRAG):
|
|
200
200
|
)
|
201
201
|
|
202
202
|
async def search_database(
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
203
|
+
self,
|
204
|
+
article: Article,
|
205
|
+
article_outline: ArticleOutline,
|
206
|
+
chap: ArticleChapter,
|
207
|
+
sec: ArticleSection,
|
208
|
+
subsec: ArticleSubsection,
|
209
|
+
cm: CitationManager,
|
210
|
+
extra_instruction: str = "",
|
211
211
|
) -> None:
|
212
212
|
"""Search database for related references."""
|
213
213
|
search_req = (
|
@@ -312,12 +312,12 @@ class TweakArticleRAG(Action, RAG, Censor):
|
|
312
312
|
"""The limit of references to be retrieved"""
|
313
313
|
|
314
314
|
async def _execute(
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
315
|
+
self,
|
316
|
+
article: Article,
|
317
|
+
collection_name: str = "article_essence",
|
318
|
+
twk_rag_ruleset: Optional[RuleSet] = None,
|
319
|
+
parallel: bool = False,
|
320
|
+
**cxt,
|
321
321
|
) -> Article:
|
322
322
|
"""Write an article based on the provided outline.
|
323
323
|
|
@@ -372,10 +372,10 @@ class TweakArticleRAG(Action, RAG, Censor):
|
|
372
372
|
subsec,
|
373
373
|
ruleset=ruleset,
|
374
374
|
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"
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
375
|
+
f"You can use Reference above to rewrite the `{subsec.__class__.__name__}`.\n"
|
376
|
+
f"You should Always use `{subsec.language}` as written language, "
|
377
|
+
f"which is the original language of the `{subsec.title}`. "
|
378
|
+
f"since rewrite a `{subsec.__class__.__name__}` in a different language is usually a bad choice",
|
379
379
|
)
|
380
380
|
|
381
381
|
|
@@ -390,12 +390,12 @@ class ChunkArticle(Action):
|
|
390
390
|
"""The maximum overlapping rate between chunks."""
|
391
391
|
|
392
392
|
async def _execute(
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
393
|
+
self,
|
394
|
+
article_path: str | Path,
|
395
|
+
bib_manager: BibManager,
|
396
|
+
max_chunk_size: Optional[int] = None,
|
397
|
+
max_overlapping_rate: Optional[float] = None,
|
398
|
+
**_,
|
399
399
|
) -> List[ArticleChunk]:
|
400
400
|
return ArticleChunk.from_file(
|
401
401
|
article_path,
|
fabricatio/decorators.py
CHANGED
@@ -235,6 +235,7 @@ def logging_exec_time[**P, R](
|
|
235
235
|
@wraps(func)
|
236
236
|
async def _async_wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
237
237
|
start_time = time()
|
238
|
+
logger.debug(f"Starting execution of {func.__name__}")
|
238
239
|
result = await func(*args, **kwargs)
|
239
240
|
logger.debug(f"Execution time of `{func.__name__}`: {time() - start_time:.2f} s")
|
240
241
|
return result
|
@@ -244,6 +245,7 @@ def logging_exec_time[**P, R](
|
|
244
245
|
@wraps(func)
|
245
246
|
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
246
247
|
start_time = time()
|
248
|
+
logger.debug(f"Starting execution of {func.__name__}")
|
247
249
|
result = func(*args, **kwargs)
|
248
250
|
logger.debug(f"Execution time of {func.__name__}: {(time() - start_time) * 1000:.2f} ms")
|
249
251
|
return result
|
@@ -1,13 +1,9 @@
|
|
1
1
|
"""A Module containing the article rag models."""
|
2
2
|
|
3
|
-
from itertools import groupby
|
4
|
-
|
5
3
|
import re
|
6
4
|
from dataclasses import dataclass, field
|
7
|
-
from
|
8
|
-
from more_itertools.recipes import flatten, unique
|
5
|
+
from itertools import groupby
|
9
6
|
from pathlib import Path
|
10
|
-
from pydantic import Field
|
11
7
|
from typing import ClassVar, Dict, List, Optional, Self, Unpack
|
12
8
|
|
13
9
|
from fabricatio.fs import safe_text_read
|
@@ -17,6 +13,9 @@ from fabricatio.models.generic import AsPrompt
|
|
17
13
|
from fabricatio.models.kwargs_types import ChunkKwargs
|
18
14
|
from fabricatio.rust import BibManager, blake3_hash, split_into_chunks
|
19
15
|
from fabricatio.utils import ok, wrapp_in_block
|
16
|
+
from more_itertools.more import first
|
17
|
+
from more_itertools.recipes import flatten, unique
|
18
|
+
from pydantic import Field
|
20
19
|
|
21
20
|
|
22
21
|
class ArticleChunk(MilvusDataBase):
|
@@ -3,7 +3,6 @@
|
|
3
3
|
from abc import ABC
|
4
4
|
from enum import StrEnum
|
5
5
|
from pathlib import Path
|
6
|
-
from pydantic import Field
|
7
6
|
from typing import ClassVar, Generator, List, Optional, Self, Tuple, Type
|
8
7
|
|
9
8
|
from fabricatio.capabilities.persist import PersistentAble
|
@@ -22,8 +21,17 @@ from fabricatio.models.generic import (
|
|
22
21
|
Titled,
|
23
22
|
WordCount,
|
24
23
|
)
|
25
|
-
from fabricatio.rust import
|
24
|
+
from fabricatio.rust import (
|
25
|
+
detect_language,
|
26
|
+
extract_body,
|
27
|
+
replace_thesis_body,
|
28
|
+
split_out_metadata,
|
29
|
+
strip_comment,
|
30
|
+
to_metadata,
|
31
|
+
word_count,
|
32
|
+
)
|
26
33
|
from fabricatio.utils import fallback_kwargs, ok
|
34
|
+
from pydantic import Field
|
27
35
|
|
28
36
|
ARTICLE_WRAPPER = "// =-=-=-=-=-=-=-=-=-="
|
29
37
|
|
@@ -52,10 +60,31 @@ class ArticleMetaData(SketchedAble, Described, WordCount, Titled, Language):
|
|
52
60
|
aims: List[str]
|
53
61
|
"""List of writing aims of the research component in academic style."""
|
54
62
|
|
63
|
+
_unstructured_body: str = ""
|
64
|
+
"""Store the source of the unknown information."""
|
65
|
+
|
55
66
|
@property
|
56
67
|
def typst_metadata_comment(self) -> str:
|
57
68
|
"""Generates a comment for the metadata of the article component."""
|
58
|
-
|
69
|
+
data = self.model_dump(
|
70
|
+
include={"description", "aims", "expected_word_count"},
|
71
|
+
by_alias=True,
|
72
|
+
)
|
73
|
+
return to_metadata({k: v for k, v in data.items() if v})
|
74
|
+
|
75
|
+
@property
|
76
|
+
def unstructured_body(self) -> str:
|
77
|
+
"""Returns the unstructured body of the article component."""
|
78
|
+
return self._unstructured_body
|
79
|
+
|
80
|
+
def update_unstructured_body[S: "ArticleMetaData"](self: S, body: str) -> S:
|
81
|
+
"""Update the unstructured body of the article component."""
|
82
|
+
self._unstructured_body = body
|
83
|
+
return self
|
84
|
+
|
85
|
+
@property
|
86
|
+
def language(self) -> str:
|
87
|
+
return detect_language(self.title)
|
59
88
|
|
60
89
|
|
61
90
|
class FromTypstCode(ArticleMetaData):
|
@@ -67,13 +96,8 @@ class FromTypstCode(ArticleMetaData):
|
|
67
96
|
data, body = split_out_metadata(body)
|
68
97
|
|
69
98
|
return cls(
|
70
|
-
heading=title,
|
71
|
-
**fallback_kwargs(
|
72
|
-
data or {},
|
73
|
-
elaboration="",
|
74
|
-
expected_word_count=word_count(body),
|
75
|
-
aims=[],
|
76
|
-
),
|
99
|
+
heading=title.strip(),
|
100
|
+
**fallback_kwargs(data or {}, elaboration="", expected_word_count=word_count(body), aims=[]),
|
77
101
|
**kwargs,
|
78
102
|
)
|
79
103
|
|
@@ -83,7 +107,7 @@ class ToTypstCode(ArticleMetaData):
|
|
83
107
|
|
84
108
|
def to_typst_code(self) -> str:
|
85
109
|
"""Converts the component into a Typst code snippet for rendering."""
|
86
|
-
return f"{self.title}\n{self.typst_metadata_comment}\n"
|
110
|
+
return f"{self.title}\n{self.typst_metadata_comment}\n\n{self._unstructured_body}"
|
87
111
|
|
88
112
|
|
89
113
|
class ArticleOutlineBase(
|
@@ -151,12 +175,16 @@ class SectionBase[T: SubSectionBase](ArticleOutlineBase):
|
|
151
175
|
@classmethod
|
152
176
|
def from_typst_code(cls, title: str, body: str, **kwargs) -> Self:
|
153
177
|
"""Creates an Article object from the given Typst code."""
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
178
|
+
raw = extract_sections(body, level=3, section_char="=")
|
179
|
+
|
180
|
+
return (
|
181
|
+
super()
|
182
|
+
.from_typst_code(
|
183
|
+
title,
|
184
|
+
body,
|
185
|
+
subsections=[cls.child_type.from_typst_code(*pack) for pack in raw],
|
186
|
+
)
|
187
|
+
.update_unstructured_body("" if raw else strip_comment(body))
|
160
188
|
)
|
161
189
|
|
162
190
|
def resolve_update_conflict(self, other: Self) -> str:
|
@@ -191,6 +219,11 @@ class SectionBase[T: SubSectionBase](ArticleOutlineBase):
|
|
191
219
|
return f"Section `{self.title}` contains no subsections, expected at least one, but got 0, you can add one or more as needed."
|
192
220
|
return ""
|
193
221
|
|
222
|
+
@property
|
223
|
+
def exact_word_count(self) -> int:
|
224
|
+
"""Returns the exact word count of the article section outline."""
|
225
|
+
return sum(a.exact_word_count for a in self.subsections)
|
226
|
+
|
194
227
|
|
195
228
|
class ChapterBase[T: SectionBase](ArticleOutlineBase):
|
196
229
|
"""Base class for article chapters."""
|
@@ -206,12 +239,16 @@ class ChapterBase[T: SectionBase](ArticleOutlineBase):
|
|
206
239
|
@classmethod
|
207
240
|
def from_typst_code(cls, title: str, body: str, **kwargs) -> Self:
|
208
241
|
"""Creates an Article object from the given Typst code."""
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
242
|
+
raw_sec = extract_sections(body, level=2, section_char="=")
|
243
|
+
|
244
|
+
return (
|
245
|
+
super()
|
246
|
+
.from_typst_code(
|
247
|
+
title,
|
248
|
+
body,
|
249
|
+
sections=[cls.child_type.from_typst_code(*pack) for pack in raw_sec],
|
250
|
+
)
|
251
|
+
.update_unstructured_body("" if raw_sec else strip_comment(body))
|
215
252
|
)
|
216
253
|
|
217
254
|
def resolve_update_conflict(self, other: Self) -> str:
|
@@ -243,6 +280,15 @@ class ChapterBase[T: SectionBase](ArticleOutlineBase):
|
|
243
280
|
return f"Chapter `{self.title}` contains no sections, expected at least one, but got 0, you can add one or more as needed."
|
244
281
|
return ""
|
245
282
|
|
283
|
+
@property
|
284
|
+
def exact_word_count(self) -> int:
|
285
|
+
"""Calculates the total word count across all sections in the chapter.
|
286
|
+
|
287
|
+
Returns:
|
288
|
+
int: The cumulative word count of all sections.
|
289
|
+
"""
|
290
|
+
return sum(a.exact_word_count for a in self.sections)
|
291
|
+
|
246
292
|
|
247
293
|
class ArticleBase[T: ChapterBase](FinalizedDumpAble, AsPrompt, FromTypstCode, ToTypstCode, ABC):
|
248
294
|
"""Base class for article outlines."""
|
@@ -263,19 +309,37 @@ class ArticleBase[T: ChapterBase](FinalizedDumpAble, AsPrompt, FromTypstCode, To
|
|
263
309
|
|
264
310
|
child_type: ClassVar[Type[ChapterBase]]
|
265
311
|
|
312
|
+
@property
|
313
|
+
def language(self) -> str:
|
314
|
+
if self.title:
|
315
|
+
return super().language
|
316
|
+
return self.chapters[0].language
|
317
|
+
|
318
|
+
@property
|
319
|
+
def exact_word_count(self) -> int:
|
320
|
+
"""Calculates the total word count across all chapters in the article.
|
321
|
+
|
322
|
+
Returns:
|
323
|
+
int: The cumulative word count of all chapters.
|
324
|
+
"""
|
325
|
+
return sum(ch.exact_word_count for ch in self.chapters)
|
326
|
+
|
266
327
|
@classmethod
|
267
328
|
def from_typst_code(cls, title: str, body: str, **kwargs) -> Self:
|
268
329
|
"""Generates an article from the given Typst code."""
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
330
|
+
raw = extract_sections(body, level=1, section_char="=")
|
331
|
+
return (
|
332
|
+
super()
|
333
|
+
.from_typst_code(
|
334
|
+
title,
|
335
|
+
body,
|
336
|
+
chapters=[cls.child_type.from_typst_code(*pack) for pack in raw],
|
337
|
+
)
|
338
|
+
.update_unstructured_body("" if raw else strip_comment(body))
|
275
339
|
)
|
276
340
|
|
277
341
|
def iter_dfs_rev(
|
278
|
-
|
342
|
+
self,
|
279
343
|
) -> Generator[ArticleOutlineBase, None, None]:
|
280
344
|
"""Performs a depth-first search (DFS) through the article structure in reverse order.
|
281
345
|
|
@@ -350,7 +414,7 @@ class ArticleBase[T: ChapterBase](FinalizedDumpAble, AsPrompt, FromTypstCode, To
|
|
350
414
|
|
351
415
|
def to_typst_code(self) -> str:
|
352
416
|
"""Generates the Typst code representation of the article."""
|
353
|
-
return f"// #{super().to_typst_code()}\n
|
417
|
+
return f"// #Title: {super().to_typst_code()}\n" + "\n\n".join(a.to_typst_code() for a in self.chapters)
|
354
418
|
|
355
419
|
def finalized_dump(self) -> str:
|
356
420
|
"""Generates standardized hierarchical markup for academic publishing systems.
|
@@ -401,11 +465,11 @@ class ArticleBase[T: ChapterBase](FinalizedDumpAble, AsPrompt, FromTypstCode, To
|
|
401
465
|
"""Set all chap, sec, subsec have same word count sum up to be `self.expected_word_count`."""
|
402
466
|
return self.avg_chap_wordcount().avg_sec_wordcount().avg_subsec_wordcount()
|
403
467
|
|
404
|
-
def update_article_file(self, file: str | Path) ->
|
468
|
+
def update_article_file[S: "ArticleBase"](self: S, file: str | Path) -> S:
|
405
469
|
"""Update the article file."""
|
406
470
|
file = Path(file)
|
407
471
|
string = safe_text_read(file)
|
408
|
-
if updated := replace_thesis_body(string, ARTICLE_WRAPPER, self.to_typst_code()):
|
472
|
+
if updated := replace_thesis_body(string, ARTICLE_WRAPPER, f"\n\n{self.to_typst_code()}\n\n"):
|
409
473
|
dump_text(file, updated)
|
410
474
|
logger.success(f"Successfully updated {file.as_posix()}.")
|
411
475
|
else:
|
@@ -413,7 +477,7 @@ class ArticleBase[T: ChapterBase](FinalizedDumpAble, AsPrompt, FromTypstCode, To
|
|
413
477
|
return self
|
414
478
|
|
415
479
|
@classmethod
|
416
|
-
def from_article_file[S: "ArticleBase"](cls: Type[S], file: str | Path, title: str) -> S:
|
480
|
+
def from_article_file[S: "ArticleBase"](cls: Type[S], file: str | Path, title: str = "") -> S:
|
417
481
|
"""Load article from file."""
|
418
482
|
file = Path(file)
|
419
483
|
string = safe_text_read(file)
|
@@ -1,6 +1,5 @@
|
|
1
1
|
"""ArticleBase and ArticleSubsection classes for managing hierarchical document components."""
|
2
2
|
|
3
|
-
from pydantic import Field, NonNegativeInt
|
4
3
|
from typing import ClassVar, Dict, Generator, List, Self, Tuple, Type, override
|
5
4
|
|
6
5
|
from fabricatio.capabilities.persist import PersistentAble
|
@@ -25,6 +24,7 @@ from fabricatio.rust import (
|
|
25
24
|
split_out_metadata,
|
26
25
|
word_count,
|
27
26
|
)
|
27
|
+
from pydantic import Field, NonNegativeInt
|
28
28
|
|
29
29
|
PARAGRAPH_SEP = "// - - -"
|
30
30
|
|
@@ -52,7 +52,7 @@ class Paragraph(SketchedAble, WordCount, Described):
|
|
52
52
|
return cls(elaboration="", aims=[], expected_word_count=word_count(content), content=content.strip())
|
53
53
|
|
54
54
|
@property
|
55
|
-
def
|
55
|
+
def exact_word_count(self) -> int:
|
56
56
|
"""Calculates the exact word count of the content."""
|
57
57
|
return word_count(self.content)
|
58
58
|
|
@@ -70,6 +70,11 @@ class ArticleSubsection(SubSectionBase):
|
|
70
70
|
_max_word_count_deviation: float = 0.3
|
71
71
|
"""Maximum allowed deviation from the expected word count, as a percentage."""
|
72
72
|
|
73
|
+
@property
|
74
|
+
def exact_word_count(self) -> int:
|
75
|
+
"""Calculates the exact word count of all paragraphs in the subsection."""
|
76
|
+
return sum(a.exact_word_count for a in self.paragraphs)
|
77
|
+
|
73
78
|
@property
|
74
79
|
def word_count(self) -> int:
|
75
80
|
"""Calculates the total word count of all paragraphs in the subsection."""
|
@@ -81,8 +86,8 @@ class ArticleSubsection(SubSectionBase):
|
|
81
86
|
if len(self.paragraphs) == 0:
|
82
87
|
summary += f"`{self.__class__.__name__}` titled `{self.title}` have no paragraphs, You should add some!\n"
|
83
88
|
if (
|
84
|
-
|
85
|
-
|
89
|
+
abs((wc := self.word_count) - self.expected_word_count) / self.expected_word_count
|
90
|
+
> self._max_word_count_deviation
|
86
91
|
):
|
87
92
|
summary += f"`{self.__class__.__name__}` titled `{self.title}` have {wc} words, expected {self.expected_word_count} words!"
|
88
93
|
|
@@ -273,9 +278,9 @@ class Article(
|
|
273
278
|
err = []
|
274
279
|
for chap, sec, subsec in self.iter_subsections():
|
275
280
|
for i, p in enumerate(subsec.paragraphs):
|
276
|
-
if p.
|
281
|
+
if p.exact_word_count <= threshold:
|
277
282
|
err.append(
|
278
|
-
f"{chap.title}->{sec.title}->{subsec.title}-> Paragraph [{i}] is too short, {p.
|
283
|
+
f"{chap.title}->{sec.title}->{subsec.title}-> Paragraph [{i}] is too short, {p.exact_word_count} words."
|
279
284
|
)
|
280
285
|
|
281
286
|
return "\n".join(err)
|
fabricatio/models/generic.py
CHANGED
@@ -114,7 +114,7 @@ class WordCount(Base, ABC):
|
|
114
114
|
@property
|
115
115
|
def exact_word_count(self) -> int:
|
116
116
|
"""Get the exact word count of this research component."""
|
117
|
-
raise NotImplementedError(f"`
|
117
|
+
raise NotImplementedError(f"`exact_word_count` is not implemented for {self.__class__.__name__}")
|
118
118
|
|
119
119
|
|
120
120
|
class FromMapping:
|
fabricatio/models/role.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"""Module that contains the Role class for managing workflows and their event registrations."""
|
2
2
|
|
3
3
|
from functools import partial
|
4
|
-
from typing import Any, Dict, Self
|
4
|
+
from typing import Any, Callable, Dict, Self, Type
|
5
5
|
|
6
6
|
from fabricatio.emitter import env
|
7
7
|
from fabricatio.journal import logger
|
@@ -68,28 +68,32 @@ class Role(WithBriefing):
|
|
68
68
|
workflow.inject_personality(self.briefing)
|
69
69
|
return self
|
70
70
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
71
|
+
def _propagate_config(
|
72
|
+
self,
|
73
|
+
workflow: WorkFlow,
|
74
|
+
has_capability: Callable[[Type], bool],
|
75
|
+
config_method_name: str,
|
76
|
+
capability_description: str,
|
77
|
+
) -> None:
|
78
|
+
"""Propagates configuration to workflow and its actions if they have a given capability."""
|
79
|
+
if not has_capability(self.__class__):
|
74
80
|
return
|
75
81
|
|
76
|
-
|
77
|
-
if
|
78
|
-
|
79
|
-
|
82
|
+
config_source_for_actions = self
|
83
|
+
if has_capability(workflow.__class__):
|
84
|
+
logger.debug(
|
85
|
+
f"Configuring {capability_description} inherited from `{self.name}` for workflow: `{workflow.name}`"
|
86
|
+
)
|
87
|
+
getattr(workflow, config_method_name)(self)
|
88
|
+
config_source_for_actions = workflow
|
80
89
|
|
81
|
-
for action in (
|
82
|
-
action
|
90
|
+
for action in (act for act in workflow.iter_actions() if has_capability(act.__class__)):
|
91
|
+
getattr(action, config_method_name)(config_source_for_actions)
|
92
|
+
|
93
|
+
def _configure_scoped_config(self, workflow: WorkFlow) -> None:
|
94
|
+
"""Configure scoped configuration for workflow and its actions."""
|
95
|
+
self._propagate_config(workflow, is_scoped_config, "fallback_to", "scoped config")
|
83
96
|
|
84
97
|
def _configure_toolbox_usage(self, workflow: WorkFlow) -> None:
|
85
98
|
"""Configure toolbox usage for workflow and its actions."""
|
86
|
-
|
87
|
-
return
|
88
|
-
|
89
|
-
supply_target = self
|
90
|
-
if is_toolbox_usage(workflow):
|
91
|
-
workflow.supply_tools_from(self)
|
92
|
-
supply_target = workflow
|
93
|
-
|
94
|
-
for action in (a for a in workflow.iter_actions() if is_toolbox_usage(a)):
|
95
|
-
action.supply_tools_from(supply_target)
|
99
|
+
self._propagate_config(workflow, is_toolbox_usage, "supply_tools_from", "toolbox usage")
|
Binary file
|
fabricatio/rust.pyi
CHANGED
@@ -12,9 +12,10 @@ Key Features:
|
|
12
12
|
"""
|
13
13
|
|
14
14
|
from enum import StrEnum
|
15
|
-
from
|
15
|
+
from pathlib import Path
|
16
16
|
from typing import Any, Dict, List, Literal, Optional, Self, Tuple, Union, overload
|
17
17
|
|
18
|
+
from pydantic import JsonValue
|
18
19
|
|
19
20
|
class TemplateManager:
|
20
21
|
"""Template rendering engine using Handlebars templates.
|
@@ -47,10 +48,8 @@ class TemplateManager:
|
|
47
48
|
|
48
49
|
@overload
|
49
50
|
def render_template(self, name: str, data: Dict[str, Any]) -> str: ...
|
50
|
-
|
51
51
|
@overload
|
52
52
|
def render_template(self, name: str, data: List[Dict[str, Any]]) -> List[str]: ...
|
53
|
-
|
54
53
|
def render_template(self, name: str, data: Dict[str, Any] | List[Dict[str, Any]]) -> str | List[str]:
|
55
54
|
"""Render a template with context data.
|
56
55
|
|
@@ -67,10 +66,8 @@ class TemplateManager:
|
|
67
66
|
|
68
67
|
@overload
|
69
68
|
def render_template_raw(self, template: str, data: Dict[str, Any]) -> str: ...
|
70
|
-
|
71
69
|
@overload
|
72
70
|
def render_template_raw(self, template: str, data: List[Dict[str, Any]]) -> List[str]: ...
|
73
|
-
|
74
71
|
def render_template_raw(self, template: str, data: Dict[str, Any] | List[Dict[str, Any]]) -> str | List[str]:
|
75
72
|
"""Render a template with context data.
|
76
73
|
|
@@ -82,7 +79,6 @@ class TemplateManager:
|
|
82
79
|
Rendered template content as string or list of strings
|
83
80
|
"""
|
84
81
|
|
85
|
-
|
86
82
|
class BibManager:
|
87
83
|
"""BibTeX bibliography manager for parsing and querying citation data."""
|
88
84
|
|
@@ -191,7 +187,6 @@ class BibManager:
|
|
191
187
|
Field value if found, None otherwise
|
192
188
|
"""
|
193
189
|
|
194
|
-
|
195
190
|
def blake3_hash(content: bytes) -> str:
|
196
191
|
"""Calculate the BLAKE3 cryptographic hash of data.
|
197
192
|
|
@@ -202,11 +197,9 @@ def blake3_hash(content: bytes) -> str:
|
|
202
197
|
Hex-encoded BLAKE3 hash string
|
203
198
|
"""
|
204
199
|
|
205
|
-
|
206
200
|
def detect_language(string: str) -> str:
|
207
201
|
"""Detect the language of a given string."""
|
208
202
|
|
209
|
-
|
210
203
|
def split_word_bounds(string: str) -> List[str]:
|
211
204
|
"""Split the string into words based on word boundaries.
|
212
205
|
|
@@ -217,7 +210,6 @@ def split_word_bounds(string: str) -> List[str]:
|
|
217
210
|
A list of words extracted from the string.
|
218
211
|
"""
|
219
212
|
|
220
|
-
|
221
213
|
def split_sentence_bounds(string: str) -> List[str]:
|
222
214
|
"""Split the string into sentences based on sentence boundaries.
|
223
215
|
|
@@ -228,7 +220,6 @@ def split_sentence_bounds(string: str) -> List[str]:
|
|
228
220
|
A list of sentences extracted from the string.
|
229
221
|
"""
|
230
222
|
|
231
|
-
|
232
223
|
def split_into_chunks(string: str, max_chunk_size: int, max_overlapping_rate: float = 0.3) -> List[str]:
|
233
224
|
"""Split the string into chunks of a specified size.
|
234
225
|
|
@@ -241,7 +232,6 @@ def split_into_chunks(string: str, max_chunk_size: int, max_overlapping_rate: fl
|
|
241
232
|
A list of chunks extracted from the string.
|
242
233
|
"""
|
243
234
|
|
244
|
-
|
245
235
|
def word_count(string: str) -> int:
|
246
236
|
"""Count the number of words in the string.
|
247
237
|
|
@@ -252,67 +242,51 @@ def word_count(string: str) -> int:
|
|
252
242
|
The number of words in the string.
|
253
243
|
"""
|
254
244
|
|
255
|
-
|
256
245
|
def is_chinese(string: str) -> bool:
|
257
246
|
"""Check if the given string is in Chinese."""
|
258
247
|
|
259
|
-
|
260
248
|
def is_english(string: str) -> bool:
|
261
249
|
"""Check if the given string is in English."""
|
262
250
|
|
263
|
-
|
264
251
|
def is_japanese(string: str) -> bool:
|
265
252
|
"""Check if the given string is in Japanese."""
|
266
253
|
|
267
|
-
|
268
254
|
def is_korean(string: str) -> bool:
|
269
255
|
"""Check if the given string is in Korean."""
|
270
256
|
|
271
|
-
|
272
257
|
def is_arabic(string: str) -> bool:
|
273
258
|
"""Check if the given string is in Arabic."""
|
274
259
|
|
275
|
-
|
276
260
|
def is_russian(string: str) -> bool:
|
277
261
|
"""Check if the given string is in Russian."""
|
278
262
|
|
279
|
-
|
280
263
|
def is_german(string: str) -> bool:
|
281
264
|
"""Check if the given string is in German."""
|
282
265
|
|
283
|
-
|
284
266
|
def is_french(string: str) -> bool:
|
285
267
|
"""Check if the given string is in French."""
|
286
268
|
|
287
|
-
|
288
269
|
def is_hindi(string: str) -> bool:
|
289
270
|
"""Check if the given string is in Hindi."""
|
290
271
|
|
291
|
-
|
292
272
|
def is_italian(string: str) -> bool:
|
293
273
|
"""Check if the given string is in Italian."""
|
294
274
|
|
295
|
-
|
296
275
|
def is_dutch(string: str) -> bool:
|
297
276
|
"""Check if the given string is in Dutch."""
|
298
277
|
|
299
|
-
|
300
278
|
def is_portuguese(string: str) -> bool:
|
301
279
|
"""Check if the given string is in Portuguese."""
|
302
280
|
|
303
|
-
|
304
281
|
def is_swedish(string: str) -> bool:
|
305
282
|
"""Check if the given string is in Swedish."""
|
306
283
|
|
307
|
-
|
308
284
|
def is_turkish(string: str) -> bool:
|
309
285
|
"""Check if the given string is in Turkish."""
|
310
286
|
|
311
|
-
|
312
287
|
def is_vietnamese(string: str) -> bool:
|
313
288
|
"""Check if the given string is in Vietnamese."""
|
314
289
|
|
315
|
-
|
316
290
|
def tex_to_typst(string: str) -> str:
|
317
291
|
"""Convert TeX to Typst.
|
318
292
|
|
@@ -323,7 +297,6 @@ def tex_to_typst(string: str) -> str:
|
|
323
297
|
The converted Typst string.
|
324
298
|
"""
|
325
299
|
|
326
|
-
|
327
300
|
def convert_all_tex_math(string: str) -> str:
|
328
301
|
r"""Unified function to convert all supported TeX math expressions in a string to Typst format.
|
329
302
|
|
@@ -336,7 +309,6 @@ def convert_all_tex_math(string: str) -> str:
|
|
336
309
|
The string with TeX math expressions converted to Typst format.
|
337
310
|
"""
|
338
311
|
|
339
|
-
|
340
312
|
def fix_misplaced_labels(string: str) -> str:
|
341
313
|
"""A func to fix labels in a string.
|
342
314
|
|
@@ -347,7 +319,6 @@ def fix_misplaced_labels(string: str) -> str:
|
|
347
319
|
The fixed string with labels properly placed.
|
348
320
|
"""
|
349
321
|
|
350
|
-
|
351
322
|
def comment(string: str) -> str:
|
352
323
|
r"""Add comment to the string.
|
353
324
|
|
@@ -358,7 +329,6 @@ def comment(string: str) -> str:
|
|
358
329
|
The string with each line prefixed by '// '.
|
359
330
|
"""
|
360
331
|
|
361
|
-
|
362
332
|
def uncomment(string: str) -> str:
|
363
333
|
"""Remove comment from the string.
|
364
334
|
|
@@ -369,6 +339,15 @@ def uncomment(string: str) -> str:
|
|
369
339
|
The string with comments (lines starting with '// ' or '//') removed.
|
370
340
|
"""
|
371
341
|
|
342
|
+
def strip_comment(string: str) -> str:
|
343
|
+
"""Remove leading and trailing comment lines from a multi-line string.
|
344
|
+
|
345
|
+
Args:
|
346
|
+
string: Input string that may have comment lines at start and/or end
|
347
|
+
|
348
|
+
Returns:
|
349
|
+
str: A new string with leading and trailing comment lines removed
|
350
|
+
"""
|
372
351
|
|
373
352
|
def split_out_metadata(string: str) -> Tuple[Optional[JsonValue], str]:
|
374
353
|
"""Split out metadata from a string.
|
@@ -380,7 +359,6 @@ def split_out_metadata(string: str) -> Tuple[Optional[JsonValue], str]:
|
|
380
359
|
A tuple containing the metadata as a Python object (if parseable) and the remaining string.
|
381
360
|
"""
|
382
361
|
|
383
|
-
|
384
362
|
def to_metadata(data: JsonValue) -> str:
|
385
363
|
"""Convert a Python object to a YAML string.
|
386
364
|
|
@@ -391,7 +369,6 @@ def to_metadata(data: JsonValue) -> str:
|
|
391
369
|
The YAML string representation of the input data.
|
392
370
|
"""
|
393
371
|
|
394
|
-
|
395
372
|
def replace_thesis_body(string: str, wrapper: str, new_body: str) -> Optional[str]:
|
396
373
|
"""Replace content between wrapper strings.
|
397
374
|
|
@@ -405,7 +382,6 @@ def replace_thesis_body(string: str, wrapper: str, new_body: str) -> Optional[st
|
|
405
382
|
|
406
383
|
"""
|
407
384
|
|
408
|
-
|
409
385
|
def extract_body(string: str, wrapper: str) -> Optional[str]:
|
410
386
|
"""Extract the content between two occurrences of a wrapper string.
|
411
387
|
|
@@ -417,7 +393,6 @@ def extract_body(string: str, wrapper: str) -> Optional[str]:
|
|
417
393
|
The content between the first two occurrences of the wrapper string if found, otherwise None.
|
418
394
|
"""
|
419
395
|
|
420
|
-
|
421
396
|
class LLMConfig:
|
422
397
|
"""LLM configuration structure.
|
423
398
|
|
@@ -469,7 +444,6 @@ class LLMConfig:
|
|
469
444
|
frequency_penalty: Optional[float]
|
470
445
|
"""Penalizes new tokens based on their frequency in text so far (-2.0-2.0)."""
|
471
446
|
|
472
|
-
|
473
447
|
class EmbeddingConfig:
|
474
448
|
"""Embedding configuration structure."""
|
475
449
|
|
@@ -494,7 +468,6 @@ class EmbeddingConfig:
|
|
494
468
|
api_key: Optional[SecretStr]
|
495
469
|
"""The API key."""
|
496
470
|
|
497
|
-
|
498
471
|
class RagConfig:
|
499
472
|
"""RAG (Retrieval Augmented Generation) configuration structure."""
|
500
473
|
|
@@ -510,18 +483,16 @@ class RagConfig:
|
|
510
483
|
milvus_dimensions: Optional[int]
|
511
484
|
"""The dimensions for Milvus vectors."""
|
512
485
|
|
513
|
-
|
514
486
|
class DebugConfig:
|
515
487
|
"""Debug configuration structure."""
|
516
488
|
|
517
489
|
log_level: Optional[str]
|
518
490
|
"""The logging level to use."""
|
519
491
|
|
520
|
-
|
521
492
|
class TemplateManagerConfig:
|
522
493
|
"""Template manager configuration structure."""
|
523
494
|
|
524
|
-
template_dir: List[
|
495
|
+
template_dir: List[Path]
|
525
496
|
"""The directories containing the templates."""
|
526
497
|
|
527
498
|
active_loading: Optional[bool]
|
@@ -530,10 +501,12 @@ class TemplateManagerConfig:
|
|
530
501
|
template_suffix: Optional[str]
|
531
502
|
"""The suffix of the templates."""
|
532
503
|
|
533
|
-
|
534
504
|
class TemplateConfig:
|
535
505
|
"""Template configuration structure."""
|
536
506
|
|
507
|
+
research_content_summary_template: str
|
508
|
+
"""The name of the research content summary template which will be used to generate a summary of research content."""
|
509
|
+
|
537
510
|
create_json_obj_template: str
|
538
511
|
"""The name of the create json object template which will be used to create a json object."""
|
539
512
|
|
@@ -615,7 +588,6 @@ class TemplateConfig:
|
|
615
588
|
chap_summary_template: str
|
616
589
|
"""The name of the chap summary template which will be used to generate a chapter summary."""
|
617
590
|
|
618
|
-
|
619
591
|
class RoutingConfig:
|
620
592
|
"""Routing configuration structure for controlling request dispatching behavior."""
|
621
593
|
|
@@ -631,7 +603,6 @@ class RoutingConfig:
|
|
631
603
|
cooldown_time: Optional[int]
|
632
604
|
"""Time to cooldown a deployment after failure in seconds."""
|
633
605
|
|
634
|
-
|
635
606
|
class GeneralConfig:
|
636
607
|
"""General configuration structure for application-wide settings."""
|
637
608
|
|
@@ -641,7 +612,6 @@ class GeneralConfig:
|
|
641
612
|
use_json_repair: bool
|
642
613
|
"""Whether to automatically repair malformed JSON."""
|
643
614
|
|
644
|
-
|
645
615
|
class ToolBoxConfig:
|
646
616
|
"""Configuration for toolbox functionality."""
|
647
617
|
|
@@ -651,7 +621,6 @@ class ToolBoxConfig:
|
|
651
621
|
data_module_name: str
|
652
622
|
"""The name of the module containing the data."""
|
653
623
|
|
654
|
-
|
655
624
|
class PymitterConfig:
|
656
625
|
"""Pymitter configuration structure for controlling event emission and listener behavior."""
|
657
626
|
|
@@ -664,7 +633,6 @@ class PymitterConfig:
|
|
664
633
|
max_listeners: int
|
665
634
|
"""The maximum number of listeners per event. -1 means unlimited."""
|
666
635
|
|
667
|
-
|
668
636
|
class Config:
|
669
637
|
"""Configuration structure containing all system components."""
|
670
638
|
|
@@ -698,22 +666,17 @@ class Config:
|
|
698
666
|
pymitter: PymitterConfig
|
699
667
|
"""Pymitter configuration."""
|
700
668
|
|
701
|
-
|
702
669
|
CONFIG: Config
|
703
670
|
|
704
|
-
|
705
671
|
class SecretStr:
|
706
672
|
"""A string that should not be exposed."""
|
707
673
|
|
708
674
|
def __init__(self, source: str) -> None: ...
|
709
|
-
|
710
675
|
def get_secret_value(self) -> str:
|
711
676
|
"""Expose the secret string."""
|
712
677
|
|
713
|
-
|
714
678
|
TEMPLATE_MANAGER: TemplateManager
|
715
679
|
|
716
|
-
|
717
680
|
class Event:
|
718
681
|
"""Event class that represents a hierarchical event with segments.
|
719
682
|
|
@@ -825,12 +788,9 @@ class Event:
|
|
825
788
|
"""
|
826
789
|
|
827
790
|
def __hash__(self) -> int: ...
|
828
|
-
|
829
791
|
def __eq__(self, other: object) -> bool: ...
|
830
|
-
|
831
792
|
def __ne__(self, other: object) -> bool: ...
|
832
793
|
|
833
|
-
|
834
794
|
class TaskStatus(StrEnum, str):
|
835
795
|
"""Enumeration of possible task statuses."""
|
836
796
|
|
@@ -849,7 +809,6 @@ class TaskStatus(StrEnum, str):
|
|
849
809
|
Cancelled: TaskStatus
|
850
810
|
"""Task has been cancelled."""
|
851
811
|
|
852
|
-
|
853
812
|
class TEIClient:
|
854
813
|
"""Client for TEI reranking service.
|
855
814
|
|
@@ -865,11 +824,11 @@ class TEIClient:
|
|
865
824
|
"""
|
866
825
|
|
867
826
|
async def arerank(
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
827
|
+
self,
|
828
|
+
query: str,
|
829
|
+
texts: List[str],
|
830
|
+
truncate: bool = False,
|
831
|
+
truncation_direction: Literal["Left", "Right"] = "Left",
|
873
832
|
) -> List[Tuple[int, float]]:
|
874
833
|
"""Rerank texts based on relevance to query.
|
875
834
|
|
Binary file
|
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fabricatio
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.15.dev4
|
4
4
|
Classifier: License :: OSI Approved :: MIT License
|
5
5
|
Classifier: Programming Language :: Rust
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -185,4 +185,5 @@ Special thanks to the contributors and maintainers of:
|
|
185
185
|
- [PyO3](https://github.com/PyO3/pyo3)
|
186
186
|
- [Maturin](https://github.com/PyO3/maturin)
|
187
187
|
- [Handlebars.rs](https://github.com/sunng87/handlebars-rust)
|
188
|
+
- [LiteLLM](https://github.com/BerriAI/litellm)
|
188
189
|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
fabricatio-0.3.
|
2
|
-
fabricatio-0.3.
|
3
|
-
fabricatio-0.3.
|
4
|
-
fabricatio-0.3.
|
5
|
-
fabricatio-0.3.
|
1
|
+
fabricatio-0.3.15.dev4.data/scripts/tdown,sha256=S4-bCA83LTAzlPRotjdov8G7PVE2yni31GBoqC2K5y0,4721520
|
2
|
+
fabricatio-0.3.15.dev4.data/scripts/ttm,sha256=QmFgMD6YmVvAqx5r6p6Hqsq4rHbP66i76sLp7LyBhUs,3919496
|
3
|
+
fabricatio-0.3.15.dev4.dist-info/METADATA,sha256=aRlHe_3Yf0BsK_1U598VD4IIWs-0l6F85axA-RsD-LU,5017
|
4
|
+
fabricatio-0.3.15.dev4.dist-info/WHEEL,sha256=gzt-5vue_7eKPs3lJK5QXBaD3_YckFhZq_AMbrvy1E4,108
|
5
|
+
fabricatio-0.3.15.dev4.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
|
6
6
|
fabricatio/__init__.py,sha256=pSLe6QL4zQGaZXfhF9KW4fa1D8chqCQm_7yInCP6Kt8,732
|
7
7
|
fabricatio/actions/__init__.py,sha256=ZMa1LeM5BNeqp-J-D32W-f5bD53-kdXGyt0zuueJofM,47
|
8
|
-
fabricatio/actions/article.py,sha256=
|
9
|
-
fabricatio/actions/article_rag.py,sha256=
|
8
|
+
fabricatio/actions/article.py,sha256=DtArcKFQM1jp4f3OKPng9ciqY7TmNIUjrjCaZO3OCg8,16695
|
9
|
+
fabricatio/actions/article_rag.py,sha256=2lQogjV_1iZkbYI4C9kGGpQH9TBeIDaQCkyi7ueqFus,17582
|
10
10
|
fabricatio/actions/fs.py,sha256=nlTmk-tYDW158nz_fzlsNfuYJwj7j4BHn_MFY5hxdqs,934
|
11
11
|
fabricatio/actions/output.py,sha256=3VRwDcvimBPrf4ypxbhJd_ScJ_JYiC0ucr6vGOqs9Fc,9687
|
12
12
|
fabricatio/actions/rag.py,sha256=GuRU6VJzIxo3V8dvGWNQ0uQbu6nF0g_qgVuC8NPRx2Y,3487
|
@@ -24,7 +24,7 @@ fabricatio/capabilities/rag.py,sha256=VSk4BKN8Clwi28-8bz-roqHRln9vu6mGnozr6snaPe
|
|
24
24
|
fabricatio/capabilities/rating.py,sha256=FSIh3h0E7G1OkBKAkY83VA4w0G6OZ2bXq27b40WRsL8,17411
|
25
25
|
fabricatio/capabilities/review.py,sha256=rxA_qdnJc8ehytL5EnlKo9QJ99stnF-n6YaBFRYLe5I,4947
|
26
26
|
fabricatio/capabilities/task.py,sha256=Ah14-xLUzXCMRydAemHoo85QDB-cLlXJslmaTCRsfms,4288
|
27
|
-
fabricatio/decorators.py,sha256=
|
27
|
+
fabricatio/decorators.py,sha256=t3fc9SRdpy8ksQclWzm9jLMv87Ls0o4wAVhN3kMUJ_Y,8841
|
28
28
|
fabricatio/emitter.py,sha256=QpMvs8dTy1zs5iDORFKzA615S3Lb1tm6AQxYBemQGcc,6164
|
29
29
|
fabricatio/fs/__init__.py,sha256=NQ_BnAwJ0iScY34QpCBH1dCq8vO5Zi4fh6VyEzrBIb8,678
|
30
30
|
fabricatio/fs/curd.py,sha256=x7Je9V1ydv-BdZTjlLc3syZ6380gkOhpfrfnhXstisg,4624
|
@@ -34,26 +34,26 @@ fabricatio/models/action.py,sha256=O8BLh8fRNqde_3PC7OFHBjLTdLRPvy5mtalMqQFaZXs,9
|
|
34
34
|
fabricatio/models/adv_kwargs_types.py,sha256=nmj1D0GVosZxKcdiw-B5vJB04Whr5zh30ZBJntSZUpY,2034
|
35
35
|
fabricatio/models/extra/__init__.py,sha256=0R9eZsCNu6OV-Xtf15H7FrqhfHTFBFf3fBrcd7ChsJ0,53
|
36
36
|
fabricatio/models/extra/advanced_judge.py,sha256=CKPP4Lseb_Ey8Y7i2V9HJfB-mZgCknFdqq7Zo41o6s4,1060
|
37
|
-
fabricatio/models/extra/aricle_rag.py,sha256=
|
38
|
-
fabricatio/models/extra/article_base.py,sha256=
|
37
|
+
fabricatio/models/extra/aricle_rag.py,sha256=KaryVIaMZRV6vpUYwkHDe09tgOihVWGPb1mGs1GXKSw,11723
|
38
|
+
fabricatio/models/extra/article_base.py,sha256=j_3Xug4n73mL-RB5nYN5HUMgMQG7aoeIcRHiQaRY4fk,18329
|
39
39
|
fabricatio/models/extra/article_essence.py,sha256=lAkfGj4Jqiy3dSmtloVVr2krej76TV1Ky-2Fr6pNE_Q,2692
|
40
|
-
fabricatio/models/extra/article_main.py,sha256=
|
40
|
+
fabricatio/models/extra/article_main.py,sha256=WOH5KTFhtrmdgmTLt3-ojBz_OAKkQERh_ODmGcpWwdk,11021
|
41
41
|
fabricatio/models/extra/article_outline.py,sha256=71mgx66KRiXBtdYId4WNkAYp9tJ7OhUqmQyOEe7IRxI,1627
|
42
42
|
fabricatio/models/extra/article_proposal.py,sha256=7OgcsS9ujjSi_06Z1ln4SCDQgrS4xPGrtgc2dv8EzGo,1857
|
43
43
|
fabricatio/models/extra/patches.py,sha256=_ghmnlvTZQq7UJyaH77mTZE9abjvxRJ2mgWHUbezUls,977
|
44
44
|
fabricatio/models/extra/problem.py,sha256=1Sd8hsThQK6pXMXhErRhP1ft58z4PvqeB8AV8VcXiaI,7051
|
45
45
|
fabricatio/models/extra/rag.py,sha256=fwyEXOECQNe8LPUKGAxEcp9vp7o5356rna-TzGpkvnE,3869
|
46
46
|
fabricatio/models/extra/rule.py,sha256=TYtA_aSgunw8wRS3BfdNqBZbbdeS-VXLbVCJhz85Suk,2617
|
47
|
-
fabricatio/models/generic.py,sha256=
|
47
|
+
fabricatio/models/generic.py,sha256=nVQhjlxKcSdIffMAwDRDFwzbw4TA82_hXrjuFafb6eQ,27058
|
48
48
|
fabricatio/models/kwargs_types.py,sha256=VrzAJaOSlQ-xN5NIIi3k4KpIY0c9beuxcuUnF-mkEEk,3282
|
49
|
-
fabricatio/models/role.py,sha256=
|
49
|
+
fabricatio/models/role.py,sha256=KxiP_hsIP85QtJhOQL_UH0lKul87hqRcd49IdWr05qQ,4154
|
50
50
|
fabricatio/models/task.py,sha256=CdR1Zbf-lZN0jODj9iriTn1X2DxLxjXlvZgy3kEd6lI,10723
|
51
51
|
fabricatio/models/tool.py,sha256=jYdN6FWEz6pE-vEh3H78VHDPpSttUQE79nfXOD4FE6U,12091
|
52
52
|
fabricatio/models/usages.py,sha256=bpM-a9i-WpSOh-XL3LiYTa3AxQUd_ckn44lh-uuKM6M,32250
|
53
53
|
fabricatio/parser.py,sha256=3vT5u5SGpzDH4WLJdMwK5CP8RqO4g1MyQUYpiDKDoEo,4528
|
54
54
|
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
55
|
-
fabricatio/rust.cpython-312-x86_64-linux-gnu.so,sha256=
|
56
|
-
fabricatio/rust.pyi,sha256=
|
55
|
+
fabricatio/rust.cpython-312-x86_64-linux-gnu.so,sha256=PRFCuB0NSVY8vW321wKHFWaiz_7U0EkAnl8bBFdiDwE,7912824
|
56
|
+
fabricatio/rust.pyi,sha256=D-YxXyjvX6d1Y5pkjcvv-EjQvxpkeA7qgcTaaHOtJpY,25491
|
57
57
|
fabricatio/toolboxes/__init__.py,sha256=dYm_Gd8XolSU_h4wnkA09dlaLDK146eeFz0CUgPZ8_c,380
|
58
58
|
fabricatio/toolboxes/arithmetic.py,sha256=sSTPkKI6-mb278DwQKFO9jKyzc9kCx45xNH7V6bGBpE,1307
|
59
59
|
fabricatio/toolboxes/fs.py,sha256=OQMdeokYxSNVrCZJAweJ0cYiK4k2QuEiNdIbS5IHIV8,705
|
@@ -61,4 +61,4 @@ fabricatio/utils.py,sha256=qvl4R8ThuNIIoBJuR1DGEuWYZ7jRFT_8SRx4I_FA8pU,5298
|
|
61
61
|
fabricatio/workflows/__init__.py,sha256=Lq9pFo2cudwFCrQUUNgSTr1CoU0J1Nw-HNEQN7cHLp8,50
|
62
62
|
fabricatio/workflows/articles.py,sha256=ZDV5nqUKRo1GOuuKWeSV7ZI32FYZU7WiTrD4YDuCeEo,945
|
63
63
|
fabricatio/workflows/rag.py,sha256=uOZXprD479fUhLA6sYvEM8RWcVcUZXXtP0xRbTMPdHE,509
|
64
|
-
fabricatio-0.3.
|
64
|
+
fabricatio-0.3.15.dev4.dist-info/RECORD,,
|
Binary file
|
Binary file
|
File without changes
|