fabricatio 0.2.4.dev3__cp312-cp312-win_amd64.whl → 0.2.5.dev0__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fabricatio/__init__.py +12 -5
- fabricatio/_rust.cp312-win_amd64.pyd +0 -0
- fabricatio/actions/article.py +44 -12
- fabricatio/actions/output.py +21 -0
- fabricatio/capabilities/rag.py +40 -8
- fabricatio/capabilities/rating.py +6 -15
- fabricatio/capabilities/review.py +141 -0
- fabricatio/config.py +6 -0
- fabricatio/fs/__init__.py +11 -1
- fabricatio/fs/curd.py +14 -8
- fabricatio/fs/readers.py +5 -2
- fabricatio/models/action.py +2 -3
- fabricatio/models/extra.py +81 -9
- fabricatio/models/generic.py +25 -1
- fabricatio/models/kwargs_types.py +9 -1
- fabricatio/models/role.py +2 -2
- fabricatio/models/task.py +0 -14
- fabricatio/models/tool.py +3 -2
- fabricatio/models/usages.py +36 -0
- fabricatio/toolboxes/__init__.py +1 -3
- fabricatio/toolboxes/fs.py +15 -1
- fabricatio/workflows/articles.py +10 -6
- fabricatio/workflows/rag.py +11 -0
- fabricatio-0.2.5.dev0.data/scripts/tdown.exe +0 -0
- {fabricatio-0.2.4.dev3.dist-info → fabricatio-0.2.5.dev0.dist-info}/METADATA +2 -1
- fabricatio-0.2.5.dev0.dist-info/RECORD +41 -0
- fabricatio/toolboxes/task.py +0 -6
- fabricatio-0.2.4.dev3.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.4.dev3.dist-info/RECORD +0 -39
- {fabricatio-0.2.4.dev3.dist-info → fabricatio-0.2.5.dev0.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.4.dev3.dist-info → fabricatio-0.2.5.dev0.dist-info}/licenses/LICENSE +0 -0
fabricatio/__init__.py
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
from importlib.util import find_spec
|
4
4
|
|
5
5
|
from fabricatio._rust_instances import template_manager
|
6
|
-
from fabricatio.actions.article import ExtractArticleEssence
|
6
|
+
from fabricatio.actions.article import ExtractArticleEssence, GenerateArticleProposal, GenerateOutline
|
7
|
+
from fabricatio.actions.output import DumpFinalizedOutput
|
7
8
|
from fabricatio.core import env
|
8
|
-
from fabricatio.fs import magika
|
9
|
+
from fabricatio.fs import magika, safe_json_read, safe_text_read
|
9
10
|
from fabricatio.journal import logger
|
10
11
|
from fabricatio.models.action import Action, WorkFlow
|
11
12
|
from fabricatio.models.events import Event
|
@@ -15,15 +16,19 @@ from fabricatio.models.task import Task
|
|
15
16
|
from fabricatio.models.tool import ToolBox
|
16
17
|
from fabricatio.models.utils import Message, Messages
|
17
18
|
from fabricatio.parser import Capture, CodeBlockCapture, JsonCapture, PythonCapture
|
18
|
-
from fabricatio.toolboxes import arithmetic_toolbox, basic_toolboxes, fs_toolbox
|
19
|
+
from fabricatio.toolboxes import arithmetic_toolbox, basic_toolboxes, fs_toolbox
|
20
|
+
from fabricatio.workflows.articles import WriteOutlineWorkFlow
|
19
21
|
|
20
22
|
__all__ = [
|
21
23
|
"Action",
|
22
24
|
"ArticleEssence",
|
23
25
|
"Capture",
|
24
26
|
"CodeBlockCapture",
|
27
|
+
"DumpFinalizedOutput",
|
25
28
|
"Event",
|
26
29
|
"ExtractArticleEssence",
|
30
|
+
"GenerateArticleProposal",
|
31
|
+
"GenerateOutline",
|
27
32
|
"JsonCapture",
|
28
33
|
"Message",
|
29
34
|
"Messages",
|
@@ -32,13 +37,15 @@ __all__ = [
|
|
32
37
|
"Task",
|
33
38
|
"ToolBox",
|
34
39
|
"WorkFlow",
|
40
|
+
"WriteOutlineWorkFlow",
|
35
41
|
"arithmetic_toolbox",
|
36
42
|
"basic_toolboxes",
|
37
43
|
"env",
|
38
44
|
"fs_toolbox",
|
39
45
|
"logger",
|
40
46
|
"magika",
|
41
|
-
"
|
47
|
+
"safe_json_read",
|
48
|
+
"safe_text_read",
|
42
49
|
"template_manager",
|
43
50
|
]
|
44
51
|
|
@@ -46,6 +53,6 @@ __all__ = [
|
|
46
53
|
if find_spec("pymilvus"):
|
47
54
|
from fabricatio.actions.rag import InjectToDB
|
48
55
|
from fabricatio.capabilities.rag import RAG
|
49
|
-
from fabricatio.workflows.
|
56
|
+
from fabricatio.workflows.rag import StoreArticle
|
50
57
|
|
51
58
|
__all__ += ["RAG", "InjectToDB", "StoreArticle"]
|
Binary file
|
fabricatio/actions/article.py
CHANGED
@@ -4,9 +4,10 @@ from os import PathLike
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import Callable, List
|
6
6
|
|
7
|
+
from fabricatio.fs import safe_text_read
|
7
8
|
from fabricatio.journal import logger
|
8
9
|
from fabricatio.models.action import Action
|
9
|
-
from fabricatio.models.extra import ArticleEssence
|
10
|
+
from fabricatio.models.extra import ArticleEssence, ArticleOutline, ArticleProposal
|
10
11
|
from fabricatio.models.task import Task
|
11
12
|
|
12
13
|
|
@@ -18,11 +19,6 @@ class ExtractArticleEssence(Action):
|
|
18
19
|
which is converted from pdf files using `magic-pdf` from the `MinerU` project, see https://github.com/opendatalab/MinerU
|
19
20
|
"""
|
20
21
|
|
21
|
-
name: str = "extract article essence"
|
22
|
-
"""The name of the action."""
|
23
|
-
description: str = "Extract the essence of article(s) from the paths specified in the task dependencies."
|
24
|
-
"""The description of the action."""
|
25
|
-
|
26
22
|
output_key: str = "article_essence"
|
27
23
|
"""The key of the output data."""
|
28
24
|
|
@@ -32,12 +28,8 @@ class ExtractArticleEssence(Action):
|
|
32
28
|
reader: Callable[[P], str] = lambda p: Path(p).read_text(encoding="utf-8"),
|
33
29
|
**_,
|
34
30
|
) -> List[ArticleEssence]:
|
35
|
-
if not
|
36
|
-
|
37
|
-
affirm_case="The task does not violate the role, and could be approved since the file dependencies are specified.",
|
38
|
-
deny_case="The task does violate the role, and could not be approved.",
|
39
|
-
):
|
40
|
-
logger.info(err := "Task not approved.")
|
31
|
+
if not task_input.dependencies:
|
32
|
+
logger.info(err := "Task not approved, since no dependencies are provided.")
|
41
33
|
raise RuntimeError(err)
|
42
34
|
|
43
35
|
# trim the references
|
@@ -47,3 +39,43 @@ class ExtractArticleEssence(Action):
|
|
47
39
|
contents,
|
48
40
|
system_message=f"# your personal briefing: \n{self.briefing}",
|
49
41
|
)
|
42
|
+
|
43
|
+
|
44
|
+
class GenerateArticleProposal(Action):
|
45
|
+
"""Generate an outline for the article based on the extracted essence."""
|
46
|
+
|
47
|
+
output_key: str = "article_proposal"
|
48
|
+
"""The key of the output data."""
|
49
|
+
|
50
|
+
async def _execute(
|
51
|
+
self,
|
52
|
+
task_input: Task,
|
53
|
+
**_,
|
54
|
+
) -> ArticleProposal:
|
55
|
+
input_path = await self.awhich_pathstr(
|
56
|
+
f"{task_input.briefing}\nExtract the path of file, which contains the article briefing that I need to read."
|
57
|
+
)
|
58
|
+
|
59
|
+
return await self.propose(
|
60
|
+
ArticleProposal,
|
61
|
+
safe_text_read(input_path),
|
62
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
63
|
+
)
|
64
|
+
|
65
|
+
|
66
|
+
class GenerateOutline(Action):
|
67
|
+
"""Generate the article based on the outline."""
|
68
|
+
|
69
|
+
output_key: str = "article"
|
70
|
+
"""The key of the output data."""
|
71
|
+
|
72
|
+
async def _execute(
|
73
|
+
self,
|
74
|
+
article_proposal: ArticleProposal,
|
75
|
+
**_,
|
76
|
+
) -> ArticleOutline:
|
77
|
+
return await self.propose(
|
78
|
+
ArticleOutline,
|
79
|
+
article_proposal.display(),
|
80
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
81
|
+
)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"""Dump the finalized output to a file."""
|
2
|
+
|
3
|
+
from typing import Unpack
|
4
|
+
|
5
|
+
from fabricatio.models.action import Action
|
6
|
+
from fabricatio.models.generic import FinalizedDumpAble
|
7
|
+
from fabricatio.models.task import Task
|
8
|
+
|
9
|
+
|
10
|
+
class DumpFinalizedOutput(Action):
|
11
|
+
"""Dump the finalized output to a file."""
|
12
|
+
|
13
|
+
output_key: str = "dump_path"
|
14
|
+
|
15
|
+
async def _execute(self, task_input: Task, to_dump: FinalizedDumpAble, **cxt: Unpack) -> str:
|
16
|
+
dump_path = await self.awhich_pathstr(
|
17
|
+
f"{task_input.briefing}\n\nExtract a single path of the file, to which I will dump the data."
|
18
|
+
)
|
19
|
+
|
20
|
+
to_dump.finalized_dump_to(dump_path)
|
21
|
+
return dump_path
|
fabricatio/capabilities/rag.py
CHANGED
@@ -242,7 +242,6 @@ class RAG(EmbeddingUsage):
|
|
242
242
|
async def aretrieve(
|
243
243
|
self,
|
244
244
|
query: List[str] | str,
|
245
|
-
collection_name: Optional[str] = None,
|
246
245
|
final_limit: int = 20,
|
247
246
|
**kwargs: Unpack[FetchKwargs],
|
248
247
|
) -> List[str]:
|
@@ -250,7 +249,6 @@ class RAG(EmbeddingUsage):
|
|
250
249
|
|
251
250
|
Args:
|
252
251
|
query (List[str] | str): The query to be used for retrieval.
|
253
|
-
collection_name (Optional[str]): The name of the collection. If not provided, the currently viewed collection is used.
|
254
252
|
final_limit (int): The final limit on the number of results to return.
|
255
253
|
**kwargs (Unpack[FetchKwargs]): Additional keyword arguments for retrieval.
|
256
254
|
|
@@ -263,15 +261,14 @@ class RAG(EmbeddingUsage):
|
|
263
261
|
await self.afetch_document(
|
264
262
|
vecs=(await self.vectorize(query)),
|
265
263
|
desired_fields="text",
|
266
|
-
collection_name=collection_name,
|
267
264
|
**kwargs,
|
268
265
|
)
|
269
266
|
)[:final_limit]
|
270
267
|
|
271
268
|
async def aask_retrieved(
|
272
269
|
self,
|
273
|
-
question: str
|
274
|
-
query: List[str] | str,
|
270
|
+
question: str,
|
271
|
+
query: Optional[List[str] | str] = None,
|
275
272
|
collection_name: Optional[str] = None,
|
276
273
|
extra_system_message: str = "",
|
277
274
|
result_per_query: int = 10,
|
@@ -285,7 +282,7 @@ class RAG(EmbeddingUsage):
|
|
285
282
|
specified question using the retrieved documents as context.
|
286
283
|
|
287
284
|
Args:
|
288
|
-
question (str
|
285
|
+
question (str): The question to be asked.
|
289
286
|
query (List[str] | str): The query or list of queries used for document retrieval.
|
290
287
|
collection_name (Optional[str]): The name of the collection to retrieve documents from.
|
291
288
|
If not provided, the currently viewed collection is used.
|
@@ -299,9 +296,9 @@ class RAG(EmbeddingUsage):
|
|
299
296
|
str: A string response generated after asking with the context of retrieved documents.
|
300
297
|
"""
|
301
298
|
docs = await self.aretrieve(
|
302
|
-
query,
|
303
|
-
collection_name,
|
299
|
+
query or question,
|
304
300
|
final_limit,
|
301
|
+
collection_name=collection_name,
|
305
302
|
result_per_query=result_per_query,
|
306
303
|
similarity_threshold=similarity_threshold,
|
307
304
|
)
|
@@ -332,3 +329,38 @@ class RAG(EmbeddingUsage):
|
|
332
329
|
),
|
333
330
|
**kwargs,
|
334
331
|
)
|
332
|
+
|
333
|
+
async def aask_refined(
|
334
|
+
self,
|
335
|
+
question: str,
|
336
|
+
collection_name: Optional[str] = None,
|
337
|
+
extra_system_message: str = "",
|
338
|
+
result_per_query: int = 10,
|
339
|
+
final_limit: int = 20,
|
340
|
+
similarity_threshold: float = 0.37,
|
341
|
+
**kwargs: Unpack[LLMKwargs],
|
342
|
+
) -> str:
|
343
|
+
"""Asks a question using a refined query based on the provided question.
|
344
|
+
|
345
|
+
Args:
|
346
|
+
question (str): The question to be asked.
|
347
|
+
collection_name (Optional[str]): The name of the collection to retrieve documents from.
|
348
|
+
extra_system_message (str): An additional system message to be included in the prompt.
|
349
|
+
result_per_query (int): The number of results to return per query. Default is 10.
|
350
|
+
final_limit (int): The maximum number of retrieved documents to consider. Default is 20.
|
351
|
+
similarity_threshold (float): The threshold for similarity, only results above this threshold will be returned.
|
352
|
+
**kwargs (Unpack[LLMKwargs]): Additional keyword arguments passed to the underlying `aask` method.
|
353
|
+
|
354
|
+
Returns:
|
355
|
+
str: A string response generated after asking with the refined question.
|
356
|
+
"""
|
357
|
+
return await self.aask_retrieved(
|
358
|
+
question,
|
359
|
+
await self.arefined_query(question, **kwargs),
|
360
|
+
collection_name=collection_name,
|
361
|
+
extra_system_message=extra_system_message,
|
362
|
+
result_per_query=result_per_query,
|
363
|
+
final_limit=final_limit,
|
364
|
+
similarity_threshold=similarity_threshold,
|
365
|
+
**kwargs,
|
366
|
+
)
|
@@ -4,7 +4,7 @@ from asyncio import gather
|
|
4
4
|
from itertools import permutations
|
5
5
|
from typing import Dict, List, Set, Tuple, Union, Unpack, overload
|
6
6
|
|
7
|
-
import
|
7
|
+
from cache import AsyncLRU
|
8
8
|
from fabricatio._rust_instances import template_manager
|
9
9
|
from fabricatio.config import configs
|
10
10
|
from fabricatio.journal import logger
|
@@ -40,10 +40,8 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
40
40
|
|
41
41
|
def _validator(response: str) -> Dict[str, float] | None:
|
42
42
|
if (
|
43
|
-
(json_data := JsonCapture.
|
44
|
-
and isinstance(json_data, dict)
|
43
|
+
(json_data := JsonCapture.validate_with(response, dict, str))
|
45
44
|
and json_data.keys() == rating_manual.keys()
|
46
|
-
and all(isinstance(v, float) for v in json_data.values())
|
47
45
|
and all(score_range[0] <= v <= score_range[1] for v in json_data.values())
|
48
46
|
):
|
49
47
|
return json_data
|
@@ -115,6 +113,7 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
115
113
|
return await gather(*[self.rate_fine_grind(item, manual, score_range, **kwargs) for item in to_rate])
|
116
114
|
raise ValueError("to_rate must be a string or a list of strings")
|
117
115
|
|
116
|
+
@AsyncLRU(maxsize=32)
|
118
117
|
async def draft_rating_manual(
|
119
118
|
self, topic: str, criteria: Set[str], **kwargs: Unpack[ValidateKwargs]
|
120
119
|
) -> Dict[str, str]:
|
@@ -169,16 +168,6 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
169
168
|
Returns:
|
170
169
|
Set[str]: A set of rating dimensions.
|
171
170
|
"""
|
172
|
-
|
173
|
-
def _validator(response: str) -> Set[str] | None:
|
174
|
-
if (
|
175
|
-
json_data := JsonCapture.validate_with(
|
176
|
-
response, target_type=list, elements_type=str, length=criteria_count
|
177
|
-
)
|
178
|
-
) is not None:
|
179
|
-
return set(json_data)
|
180
|
-
return None
|
181
|
-
|
182
171
|
return await self.aask_validate(
|
183
172
|
question=(
|
184
173
|
template_manager.render_template(
|
@@ -189,7 +178,9 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
189
178
|
},
|
190
179
|
)
|
191
180
|
),
|
192
|
-
validator=
|
181
|
+
validator=lambda resp: set(out)
|
182
|
+
if (out := JsonCapture.validate_with(resp, list, str, criteria_count))
|
183
|
+
else out,
|
193
184
|
system_message=f"# your personal briefing: \n{self.briefing}",
|
194
185
|
**kwargs,
|
195
186
|
)
|
@@ -0,0 +1,141 @@
|
|
1
|
+
"""A module that provides functionality to rate tasks based on a rating manual and score range."""
|
2
|
+
|
3
|
+
from typing import List, Optional, Set, Unpack
|
4
|
+
|
5
|
+
from fabricatio import template_manager
|
6
|
+
from fabricatio.capabilities.propose import Propose
|
7
|
+
from fabricatio.capabilities.rating import GiveRating
|
8
|
+
from fabricatio.config import configs
|
9
|
+
from fabricatio.models.generic import Display, ProposedAble, WithBriefing
|
10
|
+
from fabricatio.models.kwargs_types import GenerateKwargs, ReviewKwargs
|
11
|
+
from fabricatio.models.task import Task
|
12
|
+
from pydantic import PrivateAttr
|
13
|
+
|
14
|
+
|
15
|
+
class ReviewResult[T](ProposedAble, Display):
|
16
|
+
"""Class that represents the result of a review.
|
17
|
+
|
18
|
+
This class holds the problems identified in a review and their proposed solutions,
|
19
|
+
along with a reference to the reviewed object.
|
20
|
+
|
21
|
+
Attributes:
|
22
|
+
existing_problems (List[str]): List of problems identified in the review.
|
23
|
+
proposed_solutions (List[str]): List of proposed solutions to the problems identified in the review.
|
24
|
+
|
25
|
+
Type Parameters:
|
26
|
+
T: The type of the object being reviewed.
|
27
|
+
"""
|
28
|
+
|
29
|
+
existing_problems: List[str]
|
30
|
+
"""List of problems identified in the review."""
|
31
|
+
|
32
|
+
proposed_solutions: List[str]
|
33
|
+
"""List of proposed solutions to the problems identified in the review."""
|
34
|
+
|
35
|
+
_ref: T = PrivateAttr(None)
|
36
|
+
"""Reference to the object being reviewed."""
|
37
|
+
|
38
|
+
def update_ref[K](self, ref: K) -> "ReviewResult[K]":
|
39
|
+
"""Update the reference to the object being reviewed.
|
40
|
+
|
41
|
+
Args:
|
42
|
+
ref (K): The new reference to the object being reviewed.
|
43
|
+
|
44
|
+
Returns:
|
45
|
+
ReviewResult[K]: The updated instance of the ReviewResult class with the new reference type.
|
46
|
+
"""
|
47
|
+
self._ref = ref
|
48
|
+
return self
|
49
|
+
|
50
|
+
def deref(self) -> T:
|
51
|
+
"""Dereference the object being reviewed.
|
52
|
+
|
53
|
+
Returns:
|
54
|
+
T: The object being reviewed.
|
55
|
+
"""
|
56
|
+
return self._ref
|
57
|
+
|
58
|
+
|
59
|
+
class Review(GiveRating, Propose):
|
60
|
+
"""Class that provides functionality to review tasks and strings using a language model.
|
61
|
+
|
62
|
+
This class extends GiveRating and Propose capabilities to analyze content,
|
63
|
+
identify problems, and suggest solutions based on specified criteria.
|
64
|
+
|
65
|
+
The review process can be applied to Task objects or plain strings with
|
66
|
+
appropriate topic and criteria.
|
67
|
+
"""
|
68
|
+
|
69
|
+
async def review_task[T](self, task: Task[T], **kwargs: Unpack[ReviewKwargs]) -> ReviewResult[Task[T]]:
|
70
|
+
"""Review a task using specified review criteria.
|
71
|
+
|
72
|
+
This method analyzes a task object to identify problems and propose solutions
|
73
|
+
based on the criteria provided in kwargs.
|
74
|
+
|
75
|
+
Args:
|
76
|
+
task (Task[T]): The task object to be reviewed.
|
77
|
+
**kwargs (Unpack[ReviewKwargs]): Additional keyword arguments for the review process,
|
78
|
+
including topic and optional criteria.
|
79
|
+
|
80
|
+
Returns:
|
81
|
+
ReviewResult[Task[T]]: A review result containing identified problems and proposed solutions,
|
82
|
+
with a reference to the original task.
|
83
|
+
"""
|
84
|
+
return await self.review_obj(task, **kwargs)
|
85
|
+
|
86
|
+
async def review_string(
|
87
|
+
self, text: str, topic: str, criteria: Optional[Set[str]] = None, **kwargs: Unpack[GenerateKwargs]
|
88
|
+
) -> ReviewResult[str]:
|
89
|
+
"""Review a string based on specified topic and criteria.
|
90
|
+
|
91
|
+
This method analyzes a text string to identify problems and propose solutions
|
92
|
+
based on the given topic and criteria.
|
93
|
+
|
94
|
+
Args:
|
95
|
+
text (str): The text content to be reviewed.
|
96
|
+
topic (str): The subject topic for the review criteria.
|
97
|
+
criteria (Optional[Set[str]], optional): A set of criteria for the review.
|
98
|
+
If not provided, criteria will be drafted automatically. Defaults to None.
|
99
|
+
**kwargs (Unpack[GenerateKwargs]): Additional keyword arguments for the LLM usage.
|
100
|
+
|
101
|
+
Returns:
|
102
|
+
ReviewResult[str]: A review result containing identified problems and proposed solutions,
|
103
|
+
with a reference to the original text.
|
104
|
+
"""
|
105
|
+
criteria = criteria or (await self.draft_rating_criteria(topic))
|
106
|
+
manual = await self.draft_rating_manual(topic, criteria)
|
107
|
+
res: ReviewResult[str] = await self.propose(
|
108
|
+
ReviewResult,
|
109
|
+
template_manager.render_template(
|
110
|
+
configs.templates.review_string_template, {"text": text, "topic": topic, "criteria_manual": manual}
|
111
|
+
),
|
112
|
+
**kwargs,
|
113
|
+
)
|
114
|
+
return res.update_ref(text)
|
115
|
+
|
116
|
+
async def review_obj[M: (Display, WithBriefing)](self, obj: M, **kwargs: Unpack[ReviewKwargs]) -> ReviewResult[M]:
|
117
|
+
"""Review an object that implements Display or WithBriefing interface.
|
118
|
+
|
119
|
+
This method extracts displayable text from the object and performs a review
|
120
|
+
based on the criteria provided in kwargs.
|
121
|
+
|
122
|
+
Args:
|
123
|
+
obj (M): The object to be reviewed, which must implement either Display or WithBriefing.
|
124
|
+
**kwargs (Unpack[ReviewKwargs]): Additional keyword arguments for the review process,
|
125
|
+
including topic and optional criteria.
|
126
|
+
|
127
|
+
Raises:
|
128
|
+
TypeError: If the object does not implement Display or WithBriefing.
|
129
|
+
|
130
|
+
Returns:
|
131
|
+
ReviewResult[M]: A review result containing identified problems and proposed solutions,
|
132
|
+
with a reference to the original object.
|
133
|
+
"""
|
134
|
+
if isinstance(obj, Display):
|
135
|
+
text = obj.display()
|
136
|
+
elif isinstance(obj, WithBriefing):
|
137
|
+
text = obj.briefing
|
138
|
+
else:
|
139
|
+
raise TypeError(f"Unsupported type for review: {type(obj)}")
|
140
|
+
|
141
|
+
return (await self.review_string(text, **kwargs)).update_ref(obj)
|
fabricatio/config.py
CHANGED
@@ -212,6 +212,12 @@ class TemplateConfig(BaseModel):
|
|
212
212
|
refined_query_template: str = Field(default="refined_query")
|
213
213
|
"""The name of the refined query template which will be used to refine a query."""
|
214
214
|
|
215
|
+
pathstr_template: str = Field(default="pathstr")
|
216
|
+
"""The name of the pathstr template which will be used to acquire a path of strings."""
|
217
|
+
|
218
|
+
review_string_template: str = Field(default="review_string")
|
219
|
+
"""The name of the review string template which will be used to review a string."""
|
220
|
+
|
215
221
|
|
216
222
|
class MagikaConfig(BaseModel):
|
217
223
|
"""Magika configuration class."""
|
fabricatio/fs/__init__.py
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
"""FileSystem manipulation module for Fabricatio."""
|
2
2
|
|
3
|
-
from fabricatio.fs.curd import
|
3
|
+
from fabricatio.fs.curd import (
|
4
|
+
absolute_path,
|
5
|
+
copy_file,
|
6
|
+
create_directory,
|
7
|
+
delete_directory,
|
8
|
+
delete_file,
|
9
|
+
dump_text,
|
10
|
+
move_file,
|
11
|
+
tree,
|
12
|
+
)
|
4
13
|
from fabricatio.fs.readers import magika, safe_json_read, safe_text_read
|
5
14
|
|
6
15
|
__all__ = [
|
16
|
+
"absolute_path",
|
7
17
|
"copy_file",
|
8
18
|
"create_directory",
|
9
19
|
"delete_directory",
|
fabricatio/fs/curd.py
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
import shutil
|
4
4
|
import subprocess
|
5
|
+
from os import PathLike
|
5
6
|
from pathlib import Path
|
6
7
|
from typing import Union
|
7
8
|
|
8
|
-
from fabricatio.decorators import depend_on_external_cmd
|
9
|
+
from fabricatio.decorators import depend_on_external_cmd
|
9
10
|
from fabricatio.journal import logger
|
10
11
|
|
11
12
|
|
12
|
-
@logging_execution_info
|
13
13
|
def dump_text(path: Union[str, Path], text: str) -> None:
|
14
14
|
"""Dump text to a file. you need to make sure the file's parent directory exists.
|
15
15
|
|
@@ -23,7 +23,6 @@ def dump_text(path: Union[str, Path], text: str) -> None:
|
|
23
23
|
Path(path).write_text(text, encoding="utf-8", errors="ignore")
|
24
24
|
|
25
25
|
|
26
|
-
@logging_execution_info
|
27
26
|
def copy_file(src: Union[str, Path], dst: Union[str, Path]) -> None:
|
28
27
|
"""Copy a file from source to destination.
|
29
28
|
|
@@ -43,7 +42,6 @@ def copy_file(src: Union[str, Path], dst: Union[str, Path]) -> None:
|
|
43
42
|
raise
|
44
43
|
|
45
44
|
|
46
|
-
@logging_execution_info
|
47
45
|
def move_file(src: Union[str, Path], dst: Union[str, Path]) -> None:
|
48
46
|
"""Move a file from source to destination.
|
49
47
|
|
@@ -63,7 +61,6 @@ def move_file(src: Union[str, Path], dst: Union[str, Path]) -> None:
|
|
63
61
|
raise
|
64
62
|
|
65
63
|
|
66
|
-
@logging_execution_info
|
67
64
|
def delete_file(file_path: Union[str, Path]) -> None:
|
68
65
|
"""Delete a file.
|
69
66
|
|
@@ -82,7 +79,6 @@ def delete_file(file_path: Union[str, Path]) -> None:
|
|
82
79
|
raise
|
83
80
|
|
84
81
|
|
85
|
-
@logging_execution_info
|
86
82
|
def create_directory(dir_path: Union[str, Path], parents: bool = True, exist_ok: bool = True) -> None:
|
87
83
|
"""Create a directory.
|
88
84
|
|
@@ -99,7 +95,6 @@ def create_directory(dir_path: Union[str, Path], parents: bool = True, exist_ok:
|
|
99
95
|
raise
|
100
96
|
|
101
97
|
|
102
|
-
@logging_execution_info
|
103
98
|
@depend_on_external_cmd(
|
104
99
|
"erd",
|
105
100
|
"Please install `erd` using `cargo install erdtree` or `scoop install erdtree`.",
|
@@ -111,7 +106,6 @@ def tree(dir_path: Union[str, Path]) -> str:
|
|
111
106
|
return subprocess.check_output(("erd", dir_path.as_posix()), encoding="utf-8") # noqa: S603
|
112
107
|
|
113
108
|
|
114
|
-
@logging_execution_info
|
115
109
|
def delete_directory(dir_path: Union[str, Path]) -> None:
|
116
110
|
"""Delete a directory and its contents.
|
117
111
|
|
@@ -128,3 +122,15 @@ def delete_directory(dir_path: Union[str, Path]) -> None:
|
|
128
122
|
except OSError as e:
|
129
123
|
logger.error(f"Failed to delete directory {dir_path}: {e!s}")
|
130
124
|
raise
|
125
|
+
|
126
|
+
|
127
|
+
def absolute_path(path: str | Path | PathLike) -> str:
|
128
|
+
"""Get the absolute path of a file or directory.
|
129
|
+
|
130
|
+
Args:
|
131
|
+
path (str, Path, PathLike): The path to the file or directory.
|
132
|
+
|
133
|
+
Returns:
|
134
|
+
str: The absolute path of the file or directory.
|
135
|
+
"""
|
136
|
+
return Path(path).expanduser().resolve().as_posix()
|
fabricatio/fs/readers.py
CHANGED
@@ -7,6 +7,7 @@ from magika import Magika
|
|
7
7
|
from orjson import orjson
|
8
8
|
|
9
9
|
from fabricatio.config import configs
|
10
|
+
from fabricatio.journal import logger
|
10
11
|
|
11
12
|
magika = Magika(model_dir=configs.magika.model_dir)
|
12
13
|
|
@@ -23,7 +24,8 @@ def safe_text_read(path: Path | str) -> str:
|
|
23
24
|
path = Path(path)
|
24
25
|
try:
|
25
26
|
return path.read_text(encoding="utf-8")
|
26
|
-
except (UnicodeDecodeError, IsADirectoryError, FileNotFoundError):
|
27
|
+
except (UnicodeDecodeError, IsADirectoryError, FileNotFoundError) as e:
|
28
|
+
logger.error(f"Failed to read file {path}: {e!s}")
|
27
29
|
return ""
|
28
30
|
|
29
31
|
|
@@ -39,5 +41,6 @@ def safe_json_read(path: Path | str) -> Dict:
|
|
39
41
|
path = Path(path)
|
40
42
|
try:
|
41
43
|
return orjson.loads(path.read_text(encoding="utf-8"))
|
42
|
-
except (orjson.JSONDecodeError, IsADirectoryError, FileNotFoundError):
|
44
|
+
except (orjson.JSONDecodeError, IsADirectoryError, FileNotFoundError) as e:
|
45
|
+
logger.error(f"Failed to read file {path}: {e!s}")
|
43
46
|
return {}
|
fabricatio/models/action.py
CHANGED
@@ -5,7 +5,7 @@ from abc import abstractmethod
|
|
5
5
|
from asyncio import Queue, create_task
|
6
6
|
from typing import Any, Dict, Self, Tuple, Type, Union, Unpack, final
|
7
7
|
|
8
|
-
from fabricatio.capabilities.
|
8
|
+
from fabricatio.capabilities.review import Review
|
9
9
|
from fabricatio.capabilities.task import HandleTask, ProposeTask
|
10
10
|
from fabricatio.journal import logger
|
11
11
|
from fabricatio.models.generic import WithBriefing
|
@@ -14,7 +14,7 @@ from fabricatio.models.usages import ToolBoxUsage
|
|
14
14
|
from pydantic import Field, PrivateAttr
|
15
15
|
|
16
16
|
|
17
|
-
class Action(HandleTask, ProposeTask,
|
17
|
+
class Action(HandleTask, ProposeTask, Review):
|
18
18
|
"""Class that represents an action to be executed in a workflow."""
|
19
19
|
|
20
20
|
name: str = Field(default="")
|
@@ -34,7 +34,6 @@ class Action(HandleTask, ProposeTask, GiveRating):
|
|
34
34
|
__context: The context to be used for initialization.
|
35
35
|
"""
|
36
36
|
self.name = self.name or self.__class__.__name__
|
37
|
-
|
38
37
|
self.description = self.description or self.__class__.__doc__ or ""
|
39
38
|
|
40
39
|
@abstractmethod
|
fabricatio/models/extra.py
CHANGED
@@ -2,15 +2,13 @@
|
|
2
2
|
|
3
3
|
from typing import List
|
4
4
|
|
5
|
-
from fabricatio.models.generic import Display, PrepareVectorization, ProposedAble
|
6
|
-
from pydantic import
|
5
|
+
from fabricatio.models.generic import Base, Display, FinalizedDumpAble, PrepareVectorization, ProposedAble
|
6
|
+
from pydantic import Field
|
7
7
|
|
8
8
|
|
9
|
-
class Equation(
|
9
|
+
class Equation(Base):
|
10
10
|
"""Structured representation of mathematical equations (including their physical or conceptual meanings)."""
|
11
11
|
|
12
|
-
model_config = ConfigDict(use_attribute_docstrings=True)
|
13
|
-
|
14
12
|
description: str = Field(...)
|
15
13
|
"""A concise explanation of the equation's meaning, purpose, and relevance in the context of the research."""
|
16
14
|
|
@@ -18,11 +16,9 @@ class Equation(BaseModel):
|
|
18
16
|
"""The LaTeX code used to represent the equation in a publication-ready format."""
|
19
17
|
|
20
18
|
|
21
|
-
class Figure(
|
19
|
+
class Figure(Base):
|
22
20
|
"""Structured representation of figures (including their academic significance and explanatory captions)."""
|
23
21
|
|
24
|
-
model_config = ConfigDict(use_attribute_docstrings=True)
|
25
|
-
|
26
22
|
description: str = Field(...)
|
27
23
|
"""A detailed explanation of the figure's content and its role in conveying key insights."""
|
28
24
|
|
@@ -33,7 +29,7 @@ class Figure(BaseModel):
|
|
33
29
|
"""The file path to the figure"""
|
34
30
|
|
35
31
|
|
36
|
-
class Highlightings(
|
32
|
+
class Highlightings(Base):
|
37
33
|
"""Structured representation of highlighted elements in an academic paper (including equations, algorithms, figures, and tables)."""
|
38
34
|
|
39
35
|
# Academic Achievements Showcase
|
@@ -94,3 +90,79 @@ class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
|
94
90
|
|
95
91
|
def _prepare_vectorization_inner(self) -> str:
|
96
92
|
return self.model_dump_json()
|
93
|
+
|
94
|
+
|
95
|
+
class ArticleProposal(ProposedAble, Display):
|
96
|
+
"""Structured representation of the proposal for an academic paper."""
|
97
|
+
|
98
|
+
title: str = Field(...)
|
99
|
+
"""The proposed title of the paper."""
|
100
|
+
|
101
|
+
focused_problem: List[str] = Field(default_factory=list)
|
102
|
+
"""The specific research problem or question that the paper aims to address."""
|
103
|
+
research_aim: List[str] = Field(default_factory=list)
|
104
|
+
"""The main objective or goal of the research, outlining what the study aims to achieve."""
|
105
|
+
research_methods: List[str] = Field(default_factory=list)
|
106
|
+
"""The methods used in the research, including the approach, techniques, and tools employed."""
|
107
|
+
|
108
|
+
|
109
|
+
class ArticleSubsectionOutline(Base):
|
110
|
+
"""Structured representation of the subsections of an academic paper."""
|
111
|
+
|
112
|
+
title: str = Field(...)
|
113
|
+
"""The title of the subsection."""
|
114
|
+
|
115
|
+
description: str = Field(...)
|
116
|
+
"""A brief description of the subsection's content should be, how it fits into the overall structure of the paper, and its significance in the context of the research."""
|
117
|
+
|
118
|
+
|
119
|
+
class ArticleSectionOutline(Base):
|
120
|
+
"""Structured representation of the sections of an academic paper."""
|
121
|
+
|
122
|
+
title: str = Field(...)
|
123
|
+
"""The title of the section."""
|
124
|
+
description: str = Field(...)
|
125
|
+
"""A brief description of the section's content should be, how it fits into the overall structure of the paper, and its significance in the context of the research."""
|
126
|
+
subsections: List[ArticleSubsectionOutline] = Field(default_factory=list)
|
127
|
+
"""The subsections of the section, outlining their content and significance."""
|
128
|
+
|
129
|
+
|
130
|
+
class ArticleChapterOutline(Base):
|
131
|
+
"""Structured representation of the chapters of an academic paper."""
|
132
|
+
|
133
|
+
title: str = Field(...)
|
134
|
+
"""The title of the chapter."""
|
135
|
+
description: str = Field(...)
|
136
|
+
"""A brief description of the chapter's content should be, how it fits into the overall structure of the paper, and its significance in the context of the research."""
|
137
|
+
sections: List[ArticleSectionOutline] = Field(default_factory=list)
|
138
|
+
"""The sections of the chapter, outlining their content and significance."""
|
139
|
+
|
140
|
+
|
141
|
+
class ArticleOutline(ProposedAble, Display, FinalizedDumpAble):
|
142
|
+
"""Structured representation of the outline for an academic paper."""
|
143
|
+
|
144
|
+
title: str = Field(...)
|
145
|
+
"""The proposed title of the paper."""
|
146
|
+
|
147
|
+
prospect: str = Field(...)
|
148
|
+
"""A brief description of the research problem or question that the paper aims to address manipulating methods or techniques"""
|
149
|
+
|
150
|
+
chapters: List[ArticleChapterOutline] = Field(default_factory=list)
|
151
|
+
"""The chapters of the paper, outlining their content and significance."""
|
152
|
+
|
153
|
+
def finalized_dump(self) -> str:
|
154
|
+
"""Finalized dump of the article outline.
|
155
|
+
|
156
|
+
Returns:
|
157
|
+
str: The finalized dump of the article outline.
|
158
|
+
"""
|
159
|
+
lines: List[str] = []
|
160
|
+
|
161
|
+
for chapter in self.chapters:
|
162
|
+
lines.append(f"= {chapter.title}")
|
163
|
+
for section in chapter.sections:
|
164
|
+
lines.append(f"== {section.title}")
|
165
|
+
for subsection in section.subsections:
|
166
|
+
lines.append(f"=== {subsection.title}")
|
167
|
+
|
168
|
+
return "\n\n".join(lines)
|
fabricatio/models/generic.py
CHANGED
@@ -120,11 +120,35 @@ class InstantiateFromString(Base):
|
|
120
120
|
|
121
121
|
|
122
122
|
class ProposedAble(CreateJsonObjPrompt, InstantiateFromString):
|
123
|
-
"""Class that provides
|
123
|
+
"""Class that provides a method to propose a JSON object based on the requirement."""
|
124
124
|
|
125
125
|
pass
|
126
126
|
|
127
127
|
|
128
|
+
class FinalizedDumpAble(Base):
|
129
|
+
"""Class that provides a method to finalize the dump of the object."""
|
130
|
+
|
131
|
+
@abstractmethod
|
132
|
+
def finalized_dump(self) -> str:
|
133
|
+
"""Finalize the dump of the object.
|
134
|
+
|
135
|
+
Returns:
|
136
|
+
str: The finalized dump of the object.
|
137
|
+
"""
|
138
|
+
|
139
|
+
def finalized_dump_to(self, path: str | Path) -> Self:
|
140
|
+
"""Finalize the dump of the object to a file.
|
141
|
+
|
142
|
+
Args:
|
143
|
+
path (str | Path): The path to save the finalized dump.
|
144
|
+
|
145
|
+
Returns:
|
146
|
+
Self: The current instance of the object.
|
147
|
+
"""
|
148
|
+
Path(path).write_text(self.finalized_dump(), encoding="utf-8")
|
149
|
+
return self
|
150
|
+
|
151
|
+
|
128
152
|
class WithDependency(Base):
|
129
153
|
"""Class that manages file dependencies."""
|
130
154
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""This module contains the types for the keyword arguments of the methods in the models module."""
|
2
2
|
|
3
|
-
from typing import List, NotRequired, TypedDict
|
3
|
+
from typing import List, NotRequired, Set, TypedDict
|
4
4
|
|
5
5
|
from pydantic import NonNegativeFloat, NonNegativeInt, PositiveInt
|
6
6
|
|
@@ -15,6 +15,7 @@ class CollectionSimpleConfigKwargs(TypedDict):
|
|
15
15
|
class FetchKwargs(TypedDict):
|
16
16
|
"""A type representing the keyword arguments for the fetch method."""
|
17
17
|
|
18
|
+
collection_name: NotRequired[str]
|
18
19
|
similarity_threshold: NotRequired[float]
|
19
20
|
result_per_query: NotRequired[int]
|
20
21
|
|
@@ -53,6 +54,13 @@ class GenerateKwargs(ValidateKwargs):
|
|
53
54
|
system_message: NotRequired[str]
|
54
55
|
|
55
56
|
|
57
|
+
class ReviewKwargs(GenerateKwargs):
|
58
|
+
"""A type representing the keyword arguments for the review method."""
|
59
|
+
|
60
|
+
topic: str
|
61
|
+
criteria: NotRequired[Set[str]]
|
62
|
+
|
63
|
+
|
56
64
|
class ChooseKwargs(GenerateKwargs):
|
57
65
|
"""A type representing the keyword arguments for the choose method."""
|
58
66
|
|
fabricatio/models/role.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from typing import Any, Self, Set
|
4
4
|
|
5
|
-
from fabricatio.capabilities.
|
5
|
+
from fabricatio.capabilities.review import Review
|
6
6
|
from fabricatio.capabilities.task import HandleTask, ProposeTask
|
7
7
|
from fabricatio.core import env
|
8
8
|
from fabricatio.journal import logger
|
@@ -12,7 +12,7 @@ from fabricatio.models.tool import ToolBox
|
|
12
12
|
from pydantic import Field
|
13
13
|
|
14
14
|
|
15
|
-
class Role(ProposeTask, HandleTask,
|
15
|
+
class Role(ProposeTask, HandleTask, Review):
|
16
16
|
"""Class that represents a role with a registry of events and workflows."""
|
17
17
|
|
18
18
|
registry: dict[Event | str, WorkFlow] = Field(...)
|
fabricatio/models/task.py
CHANGED
@@ -83,20 +83,6 @@ class Task[T](WithBriefing, ProposedAble, WithDependency):
|
|
83
83
|
self.namespace = self._namespace.segments
|
84
84
|
return self
|
85
85
|
|
86
|
-
@classmethod
|
87
|
-
def simple_task(cls, name: str, goal: List[str], description: str) -> Self:
|
88
|
-
"""Create a simple task with a name, goal, and description.
|
89
|
-
|
90
|
-
Args:
|
91
|
-
name (str): The name of the task.
|
92
|
-
goal (List[str]): The goal of the task.
|
93
|
-
description (str): The description of the task.
|
94
|
-
|
95
|
-
Returns:
|
96
|
-
Task: A new instance of the `Task` class.
|
97
|
-
"""
|
98
|
-
return cls(name=name, goals=goal, description=description)
|
99
|
-
|
100
86
|
def update_task(self, goal: Optional[List[str] | str] = None, description: Optional[str] = None) -> Self:
|
101
87
|
"""Update the goal and description of the task.
|
102
88
|
|
fabricatio/models/tool.py
CHANGED
@@ -7,7 +7,7 @@ from types import CodeType, ModuleType
|
|
7
7
|
from typing import Any, Callable, Dict, List, Optional, Self, overload
|
8
8
|
|
9
9
|
from fabricatio.config import configs
|
10
|
-
from fabricatio.decorators import use_temp_module
|
10
|
+
from fabricatio.decorators import logging_execution_info, use_temp_module
|
11
11
|
from fabricatio.journal import logger
|
12
12
|
from fabricatio.models.generic import WithBriefing
|
13
13
|
from pydantic import BaseModel, ConfigDict, Field
|
@@ -31,6 +31,7 @@ class Tool[**P, R](WithBriefing):
|
|
31
31
|
|
32
32
|
if not self.name:
|
33
33
|
raise RuntimeError("The tool must have a source function.")
|
34
|
+
|
34
35
|
self.description = self.description or self.source.__doc__ or ""
|
35
36
|
self.description = self.description.strip()
|
36
37
|
|
@@ -84,7 +85,7 @@ class ToolBox(WithBriefing):
|
|
84
85
|
Returns:
|
85
86
|
Self: The current instance of the toolbox.
|
86
87
|
"""
|
87
|
-
self.
|
88
|
+
self.collect_tool(logging_execution_info(func))
|
88
89
|
return self
|
89
90
|
|
90
91
|
@property
|
fabricatio/models/usages.py
CHANGED
@@ -258,6 +258,42 @@ class LLMUsage(ScopedConfig):
|
|
258
258
|
**kwargs,
|
259
259
|
)
|
260
260
|
|
261
|
+
async def apathstr(self, requirement: str, **kwargs: Unpack[ChooseKwargs]) -> List[str]:
|
262
|
+
"""Asynchronously generates a list of strings based on a given requirement.
|
263
|
+
|
264
|
+
Args:
|
265
|
+
requirement (str): The requirement for the list of strings.
|
266
|
+
**kwargs (Unpack[ChooseKwargs]): Additional keyword arguments for the LLM usage.
|
267
|
+
|
268
|
+
Returns:
|
269
|
+
List[str]: The validated response as a list of strings.
|
270
|
+
"""
|
271
|
+
return await self.aliststr(
|
272
|
+
template_manager.render_template(
|
273
|
+
configs.templates.pathstr_template,
|
274
|
+
{"requirement": requirement},
|
275
|
+
),
|
276
|
+
**kwargs,
|
277
|
+
)
|
278
|
+
|
279
|
+
async def awhich_pathstr(self, requirement: str, **kwargs: Unpack[GenerateKwargs]) -> str:
|
280
|
+
"""Asynchronously generates a single path string based on a given requirement.
|
281
|
+
|
282
|
+
Args:
|
283
|
+
requirement (str): The requirement for the list of strings.
|
284
|
+
**kwargs (Unpack[GenerateKwargs]): Additional keyword arguments for the LLM usage.
|
285
|
+
|
286
|
+
Returns:
|
287
|
+
str: The validated response as a single string.
|
288
|
+
"""
|
289
|
+
return (
|
290
|
+
await self.apathstr(
|
291
|
+
requirement,
|
292
|
+
k=1,
|
293
|
+
**kwargs,
|
294
|
+
)
|
295
|
+
).pop()
|
296
|
+
|
261
297
|
async def achoose[T: WithBriefing](
|
262
298
|
self,
|
263
299
|
instruction: str,
|
fabricatio/toolboxes/__init__.py
CHANGED
@@ -5,13 +5,11 @@ from typing import Set
|
|
5
5
|
from fabricatio.models.tool import ToolBox
|
6
6
|
from fabricatio.toolboxes.arithmetic import arithmetic_toolbox
|
7
7
|
from fabricatio.toolboxes.fs import fs_toolbox
|
8
|
-
from fabricatio.toolboxes.task import task_toolbox
|
9
8
|
|
10
|
-
basic_toolboxes: Set[ToolBox] = {
|
9
|
+
basic_toolboxes: Set[ToolBox] = {arithmetic_toolbox}
|
11
10
|
|
12
11
|
__all__ = [
|
13
12
|
"arithmetic_toolbox",
|
14
13
|
"basic_toolboxes",
|
15
14
|
"fs_toolbox",
|
16
|
-
"task_toolbox",
|
17
15
|
]
|
fabricatio/toolboxes/fs.py
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
"""File system tool box."""
|
2
2
|
|
3
|
-
from fabricatio.fs
|
3
|
+
from fabricatio.fs import (
|
4
|
+
absolute_path,
|
5
|
+
copy_file,
|
6
|
+
create_directory,
|
7
|
+
delete_directory,
|
8
|
+
delete_file,
|
9
|
+
dump_text,
|
10
|
+
move_file,
|
11
|
+
safe_json_read,
|
12
|
+
safe_text_read,
|
13
|
+
tree,
|
14
|
+
)
|
4
15
|
from fabricatio.models.tool import ToolBox
|
5
16
|
|
6
17
|
fs_toolbox = (
|
@@ -12,4 +23,7 @@ fs_toolbox = (
|
|
12
23
|
.add_tool(tree)
|
13
24
|
.add_tool(delete_directory)
|
14
25
|
.add_tool(create_directory)
|
26
|
+
.add_tool(absolute_path)
|
27
|
+
.add_tool(safe_text_read)
|
28
|
+
.add_tool(safe_json_read)
|
15
29
|
)
|
fabricatio/workflows/articles.py
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
"""Store article essence in the database."""
|
2
2
|
|
3
|
-
from fabricatio.actions.article import
|
4
|
-
from fabricatio.actions.
|
3
|
+
from fabricatio.actions.article import GenerateArticleProposal, GenerateOutline
|
4
|
+
from fabricatio.actions.output import DumpFinalizedOutput
|
5
5
|
from fabricatio.models.action import WorkFlow
|
6
6
|
|
7
|
-
|
8
|
-
name="
|
9
|
-
description="
|
10
|
-
steps=(
|
7
|
+
WriteOutlineWorkFlow = WorkFlow(
|
8
|
+
name="Generate Article Outline",
|
9
|
+
description="Generate an outline for an article. dump the outline to the given path. in typst format.",
|
10
|
+
steps=(
|
11
|
+
GenerateArticleProposal,
|
12
|
+
GenerateOutline(output_key="to_dump"),
|
13
|
+
DumpFinalizedOutput(output_key="task_output"),
|
14
|
+
),
|
11
15
|
)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"""The workflow for extracting the essence of an article and storing it in the database."""
|
2
|
+
|
3
|
+
from fabricatio.actions.article import ExtractArticleEssence
|
4
|
+
from fabricatio.actions.rag import InjectToDB
|
5
|
+
from fabricatio.models.action import WorkFlow
|
6
|
+
|
7
|
+
StoreArticle = WorkFlow(
|
8
|
+
name="Extract Article Essence",
|
9
|
+
description="Extract the essence of an article in the given path, and store it in the database.",
|
10
|
+
steps=(ExtractArticleEssence(output_key="to_inject"), InjectToDB(output_key="task_output")),
|
11
|
+
)
|
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fabricatio
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.5.dev0
|
4
4
|
Classifier: License :: OSI Approved :: MIT License
|
5
5
|
Classifier: Programming Language :: Rust
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -9,6 +9,7 @@ Classifier: Framework :: AsyncIO
|
|
9
9
|
Classifier: Framework :: Pydantic :: 2
|
10
10
|
Classifier: Typing :: Typed
|
11
11
|
Requires-Dist: appdirs>=1.4.4
|
12
|
+
Requires-Dist: async-cache>=1.1.1
|
12
13
|
Requires-Dist: asyncio>=3.4.3
|
13
14
|
Requires-Dist: asyncstdlib>=3.13.0
|
14
15
|
Requires-Dist: litellm>=1.60.0
|
@@ -0,0 +1,41 @@
|
|
1
|
+
fabricatio-0.2.5.dev0.dist-info/METADATA,sha256=l9b8k3MoqoNyI7GkF5IpDd1nhwb1ybmqXflut5G-m6A,8895
|
2
|
+
fabricatio-0.2.5.dev0.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
|
3
|
+
fabricatio-0.2.5.dev0.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
|
4
|
+
fabricatio/actions/article.py,sha256=PFO7QJw0SXryReA2kGJgd35NeIxCodpudNQxlXNg8xA,2785
|
5
|
+
fabricatio/actions/output.py,sha256=RWXulsfN_qrCFik0B6lGwXf6MMtgK3CaF1ENbK0l85o,684
|
6
|
+
fabricatio/actions/rag.py,sha256=lZfw9SZ8oxbWPK_bvWsEpVkWJbGP8HUnlNbxLh11Wdg,821
|
7
|
+
fabricatio/capabilities/propose.py,sha256=nahXjB6_nP0Fru880oh_9oINrjrL0Qs-SLHA-d3CFUE,1769
|
8
|
+
fabricatio/capabilities/rag.py,sha256=AQTtFPDluTByl5NXYZZIvAw2qFKpnulzxL7fmStJD0w,15547
|
9
|
+
fabricatio/capabilities/rating.py,sha256=F0caWNrhQVJQsrI8RMvfnBWLeMESoPnMLGongxVxUCk,13706
|
10
|
+
fabricatio/capabilities/review.py,sha256=PWs3sz7PqJ6ySj0YpJoTHxr51kIfiuYhwZucq2exkqY,5866
|
11
|
+
fabricatio/capabilities/task.py,sha256=s6FiC9Wg_l-qSa2LgsoKV9f6wXZN6Q_FlWn3XbSnrys,4618
|
12
|
+
fabricatio/config.py,sha256=xztfwwnMsFPleeYw8QE-1z2c-V704BoKIWjM9U4Mm2U,13987
|
13
|
+
fabricatio/core.py,sha256=VQ_JKgUGIy2gZ8xsTBZCdr_IP7wC5aPg0_bsOmjQ588,6458
|
14
|
+
fabricatio/decorators.py,sha256=uzsP4tFKQNjDHBkofsjjoJA0IUAaYOtt6YVedoyOqlo,6551
|
15
|
+
fabricatio/fs/curd.py,sha256=m9ulUM95vF1OY4ogCugVSSvquG_0IUvZF7p2JnkZTQs,4146
|
16
|
+
fabricatio/fs/readers.py,sha256=Jw3NQ1AFMy_tZvGomTSu37kMojUoDeaZQS91w-xbNX0,1214
|
17
|
+
fabricatio/fs/__init__.py,sha256=YzCKEE1f_dvll3HnxKhq-bo8igkwTlA1A-GYm4bobj8,548
|
18
|
+
fabricatio/journal.py,sha256=siqimKF0M_QaaOCMxtjr_BJVNyUIAQWILzE9Q4T6-7c,781
|
19
|
+
fabricatio/models/action.py,sha256=6bpjtitOJ18QjE3XvnBPyKHomyQ_BjEB_hrtxuIle4E,6485
|
20
|
+
fabricatio/models/events.py,sha256=pt-WkFhhA5SXmp6-3Vb_o_7I5xbKoTCJ22GAK7YYwpA,4101
|
21
|
+
fabricatio/models/extra.py,sha256=1vmtnE0n15ZSRVKmPmtChA34y0y-G07uTywXek_oGzs,7463
|
22
|
+
fabricatio/models/generic.py,sha256=wzFoZIUDrrk1eXEpjw2a-T48c9_dB7KTVUnYuMDstKo,12560
|
23
|
+
fabricatio/models/kwargs_types.py,sha256=ZOmUxk22d5lRk5IQTGnBFK_YkjCVG1FEGLYjXqr24nY,2002
|
24
|
+
fabricatio/models/role.py,sha256=bdO9YVn7OA5DDpCxreQSNZIzGRHX7RoN1723V9Ob0oU,1822
|
25
|
+
fabricatio/models/task.py,sha256=sbC0EAZC4rPL2GCJ9i9GlFcZUJ96g39SQ2QP8bbgdqs,10492
|
26
|
+
fabricatio/models/tool.py,sha256=JdpldDqlXZ0TZc9eh6IrdHB3FAldEPxsSxeSm4naJhA,7025
|
27
|
+
fabricatio/models/usages.py,sha256=AcOpsInEmIDorTEYNvcyiAE2fsEuWfJwhNSZ2mrRf_g,26865
|
28
|
+
fabricatio/models/utils.py,sha256=QI3bYrKBbzLbKvyzVrZXGcWq3trOOTE-hQAC_WNvjMg,4457
|
29
|
+
fabricatio/parser.py,sha256=qNYshYtuwbZHZG1kQKYYHZOzYhDO4DZJJYh2k4Imz3s,4911
|
30
|
+
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
|
+
fabricatio/toolboxes/arithmetic.py,sha256=WLqhY-Pikv11Y_0SGajwZx3WhsLNpHKf9drzAqOf_nY,1369
|
32
|
+
fabricatio/toolboxes/fs.py,sha256=xOhmb1PcCBbc5V9EQtr624DKe0M4QzajA5dz_0cu1fI,688
|
33
|
+
fabricatio/toolboxes/__init__.py,sha256=KBJi5OG_pExscdlM7Bnt_UF43j4I3Lv6G71kPVu4KQU,395
|
34
|
+
fabricatio/workflows/articles.py,sha256=RebdC_BzSXC-xsck5I9ccC_XIgfhtoeM8FZuhtVDn3U,580
|
35
|
+
fabricatio/workflows/rag.py,sha256=-YYp2tlE9Vtfgpg6ROpu6QVO8j8yVSPa6yDzlN3qVxs,520
|
36
|
+
fabricatio/_rust.pyi,sha256=0wCqtwWkVxxoqprvk8T27T8QYKIAKHS7xgsmdMNjQKc,1756
|
37
|
+
fabricatio/_rust_instances.py,sha256=dl0-yZ4UvT5g20tQgnPJpmqtkjFGXNG_YK4eLfi_ugQ,279
|
38
|
+
fabricatio/__init__.py,sha256=tLyQcHKnV3OVWY2_WzBlhLxOv3VCSCm8p8TCYLbu8Mk,1870
|
39
|
+
fabricatio/_rust.cp312-win_amd64.pyd,sha256=kLXP2Sk186x2L2weatQKDxVz5FPste2GqNVVyIobqjQ,1275904
|
40
|
+
fabricatio-0.2.5.dev0.data/scripts/tdown.exe,sha256=zzziaIIK9hVEk8Ar9J3yJV_HCU0mKA_7OAEH0jXkcIM,3392000
|
41
|
+
fabricatio-0.2.5.dev0.dist-info/RECORD,,
|
fabricatio/toolboxes/task.py
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
"""This module contains the toolbox for tasks management."""
|
2
|
-
|
3
|
-
from fabricatio.models.task import Task
|
4
|
-
from fabricatio.models.tool import ToolBox
|
5
|
-
|
6
|
-
task_toolbox = ToolBox(name="TaskToolBox", description="A toolbox for tasks management.").add_tool(Task.simple_task)
|
Binary file
|
@@ -1,39 +0,0 @@
|
|
1
|
-
fabricatio-0.2.4.dev3.dist-info/METADATA,sha256=ylm4KBEqXPqU0YJT7HpEaLhwMuWEPU3YaDcTMsleHEE,8861
|
2
|
-
fabricatio-0.2.4.dev3.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
|
3
|
-
fabricatio-0.2.4.dev3.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
|
4
|
-
fabricatio/actions/article.py,sha256=xrY04lIbq2ol_eW0kw0l9GmZsOXSlTCpjuR38t_bzEE,2026
|
5
|
-
fabricatio/actions/rag.py,sha256=lZfw9SZ8oxbWPK_bvWsEpVkWJbGP8HUnlNbxLh11Wdg,821
|
6
|
-
fabricatio/capabilities/propose.py,sha256=nahXjB6_nP0Fru880oh_9oINrjrL0Qs-SLHA-d3CFUE,1769
|
7
|
-
fabricatio/capabilities/rag.py,sha256=UWRUQtlhGUT9Zz3c5iErWjpiTr4LWUV184uMSMhrC_g,14139
|
8
|
-
fabricatio/capabilities/rating.py,sha256=PcUpKxPfVO-vitgA6py1xg9iLJZdf7Fru--18ZUFKKA,14026
|
9
|
-
fabricatio/capabilities/task.py,sha256=s6FiC9Wg_l-qSa2LgsoKV9f6wXZN6Q_FlWn3XbSnrys,4618
|
10
|
-
fabricatio/config.py,sha256=dbVwH1ZEkBSt1wiO7q4gl6U5_72y6AKkcwswPYXEQCc,13681
|
11
|
-
fabricatio/core.py,sha256=VQ_JKgUGIy2gZ8xsTBZCdr_IP7wC5aPg0_bsOmjQ588,6458
|
12
|
-
fabricatio/decorators.py,sha256=uzsP4tFKQNjDHBkofsjjoJA0IUAaYOtt6YVedoyOqlo,6551
|
13
|
-
fabricatio/fs/curd.py,sha256=faMstgGUiQ4k2AW3OXfvvWWTldTtKXco7QINYaMjmyA,3981
|
14
|
-
fabricatio/fs/readers.py,sha256=Pz1-cdZYtmqr032dsroImlkFXAd0kCYY_9qVpD4UrG4,1045
|
15
|
-
fabricatio/fs/__init__.py,sha256=9yH1-3mdWf2isbCqbaQO7xs1f6eoiPn4uKUAETNRk0A,465
|
16
|
-
fabricatio/journal.py,sha256=siqimKF0M_QaaOCMxtjr_BJVNyUIAQWILzE9Q4T6-7c,781
|
17
|
-
fabricatio/models/action.py,sha256=yj3Tt_UWGnkoVQNCMOBIqxDeyfXFEQp1oS4xd-nDXCY,6495
|
18
|
-
fabricatio/models/events.py,sha256=pt-WkFhhA5SXmp6-3Vb_o_7I5xbKoTCJ22GAK7YYwpA,4101
|
19
|
-
fabricatio/models/extra.py,sha256=0v5v0a_xcXcDTeIDmwtzUO68HjrmVvLHM6ALWvl9h6w,4328
|
20
|
-
fabricatio/models/generic.py,sha256=3S16T7nZEDhDF-VLSmRPa7NEtapZjU5WQHosoisqbTw,11843
|
21
|
-
fabricatio/models/kwargs_types.py,sha256=Xhy5LcTB1oWBGVGipLf5y_dTb7tBzMO5QAQdEfZeI9I,1786
|
22
|
-
fabricatio/models/role.py,sha256=gYvleTeKUGDUNKPAC5B0EPMLC4jZ4vHsFHmHiVXkU6c,1830
|
23
|
-
fabricatio/models/task.py,sha256=BRE3XBQXTXH7UHsJDN7UzxIBRQbDVf7T4a00_111inw,10996
|
24
|
-
fabricatio/models/tool.py,sha256=WTFnpF6xZ1nJbmIOonLsGQcM-kkDCeZiAFqyil9xg2U,6988
|
25
|
-
fabricatio/models/usages.py,sha256=EdQrjAltM_D-WBvzPtzF11npGA1fpF1JGwDLDHYxCyQ,25535
|
26
|
-
fabricatio/models/utils.py,sha256=QI3bYrKBbzLbKvyzVrZXGcWq3trOOTE-hQAC_WNvjMg,4457
|
27
|
-
fabricatio/parser.py,sha256=qNYshYtuwbZHZG1kQKYYHZOzYhDO4DZJJYh2k4Imz3s,4911
|
28
|
-
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
|
-
fabricatio/toolboxes/arithmetic.py,sha256=WLqhY-Pikv11Y_0SGajwZx3WhsLNpHKf9drzAqOf_nY,1369
|
30
|
-
fabricatio/toolboxes/fs.py,sha256=YkNgon5-bvCiPVEND9971W-6wj8btKNL6nGry2otn9I,498
|
31
|
-
fabricatio/toolboxes/task.py,sha256=kU4a501awIDV7GwNDuSlK3_Ym-5OhCp5sS-insTmUmQ,269
|
32
|
-
fabricatio/toolboxes/__init__.py,sha256=b13KmASO8q5fBLwew964fn9oH86ER5g-S1PgA4fZ_xs,482
|
33
|
-
fabricatio/workflows/articles.py,sha256=gZlmC2tS1YnSajZft6jN0VTSj6rcuT8367nBYD8edoI,473
|
34
|
-
fabricatio/_rust.pyi,sha256=0wCqtwWkVxxoqprvk8T27T8QYKIAKHS7xgsmdMNjQKc,1756
|
35
|
-
fabricatio/_rust_instances.py,sha256=dl0-yZ4UvT5g20tQgnPJpmqtkjFGXNG_YK4eLfi_ugQ,279
|
36
|
-
fabricatio/__init__.py,sha256=lIjAvhmypC8kZNpymjmYByJtZjzJNXDmNzY36x1o7h8,1554
|
37
|
-
fabricatio/_rust.cp312-win_amd64.pyd,sha256=awkdolid46gR8FEGI9Hxx04KPmXs35jZdXaauhazzoM,1277952
|
38
|
-
fabricatio-0.2.4.dev3.data/scripts/tdown.exe,sha256=OhB53d4Eswjsw9TEcNsQCkd5D32BVEME6yRGsti1PTU,3397632
|
39
|
-
fabricatio-0.2.4.dev3.dist-info/RECORD,,
|
File without changes
|
File without changes
|