fabricatio 0.2.4.dev1__cp312-cp312-manylinux_2_34_x86_64.whl → 0.2.4.dev3__cp312-cp312-manylinux_2_34_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fabricatio/__init__.py +4 -2
- fabricatio/_rust.cpython-312-x86_64-linux-gnu.so +0 -0
- fabricatio/actions/article.py +7 -2
- fabricatio/actions/rag.py +25 -0
- fabricatio/capabilities/rag.py +28 -4
- fabricatio/config.py +3 -0
- fabricatio/fs/__init__.py +14 -2
- fabricatio/models/action.py +17 -1
- fabricatio/workflows/articles.py +11 -0
- {fabricatio-0.2.4.dev1.dist-info → fabricatio-0.2.4.dev3.dist-info}/METADATA +1 -1
- {fabricatio-0.2.4.dev1.dist-info → fabricatio-0.2.4.dev3.dist-info}/RECORD +14 -13
- fabricatio/actions/__init__.py +0 -5
- {fabricatio-0.2.4.dev1.data → fabricatio-0.2.4.dev3.data}/scripts/tdown +0 -0
- {fabricatio-0.2.4.dev1.dist-info → fabricatio-0.2.4.dev3.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.4.dev1.dist-info → fabricatio-0.2.4.dev3.dist-info}/licenses/LICENSE +0 -0
fabricatio/__init__.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
from importlib.util import find_spec
|
4
4
|
|
5
5
|
from fabricatio._rust_instances import template_manager
|
6
|
-
from fabricatio.actions import ExtractArticleEssence
|
6
|
+
from fabricatio.actions.article import ExtractArticleEssence
|
7
7
|
from fabricatio.core import env
|
8
8
|
from fabricatio.fs import magika
|
9
9
|
from fabricatio.journal import logger
|
@@ -44,6 +44,8 @@ __all__ = [
|
|
44
44
|
|
45
45
|
|
46
46
|
if find_spec("pymilvus"):
|
47
|
+
from fabricatio.actions.rag import InjectToDB
|
47
48
|
from fabricatio.capabilities.rag import RAG
|
49
|
+
from fabricatio.workflows.articles import StoreArticle
|
48
50
|
|
49
|
-
__all__ += ["RAG"]
|
51
|
+
__all__ += ["RAG", "InjectToDB", "StoreArticle"]
|
Binary file
|
fabricatio/actions/article.py
CHANGED
@@ -11,11 +11,16 @@ from fabricatio.models.task import Task
|
|
11
11
|
|
12
12
|
|
13
13
|
class ExtractArticleEssence(Action):
|
14
|
-
"""Extract the essence of article(s).
|
14
|
+
"""Extract the essence of article(s) in text format from the paths specified in the task dependencies.
|
15
|
+
|
16
|
+
Notes:
|
17
|
+
This action is designed to extract vital information from articles with Markdown format, which is pure text, and
|
18
|
+
which is converted from pdf files using `magic-pdf` from the `MinerU` project, see https://github.com/opendatalab/MinerU
|
19
|
+
"""
|
15
20
|
|
16
21
|
name: str = "extract article essence"
|
17
22
|
"""The name of the action."""
|
18
|
-
description: str = "Extract the essence of
|
23
|
+
description: str = "Extract the essence of article(s) from the paths specified in the task dependencies."
|
19
24
|
"""The description of the action."""
|
20
25
|
|
21
26
|
output_key: str = "article_essence"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"""Inject data into the database."""
|
2
|
+
|
3
|
+
from typing import List, Optional, Unpack
|
4
|
+
|
5
|
+
from fabricatio.capabilities.rag import RAG
|
6
|
+
from fabricatio.models.action import Action
|
7
|
+
from fabricatio.models.generic import PrepareVectorization
|
8
|
+
|
9
|
+
|
10
|
+
class InjectToDB(Action, RAG):
|
11
|
+
"""Inject data into the database."""
|
12
|
+
|
13
|
+
output_key: str = "collection_name"
|
14
|
+
|
15
|
+
async def _execute[T: PrepareVectorization](
|
16
|
+
self, to_inject: T | List[T], collection_name: Optional[str] = "my_collection", **cxt: Unpack
|
17
|
+
) -> str:
|
18
|
+
if not isinstance(to_inject, list):
|
19
|
+
to_inject = [to_inject]
|
20
|
+
|
21
|
+
await self.view(collection_name, create=True).consume_string(
|
22
|
+
[t.prepare_vectorization(self.embedding_max_sequence_length) for t in to_inject],
|
23
|
+
)
|
24
|
+
|
25
|
+
return collection_name
|
fabricatio/capabilities/rag.py
CHANGED
@@ -13,10 +13,16 @@ from typing import Any, Callable, Dict, List, Optional, Self, Union, Unpack, ove
|
|
13
13
|
from fabricatio._rust_instances import template_manager
|
14
14
|
from fabricatio.config import configs
|
15
15
|
from fabricatio.journal import logger
|
16
|
-
from fabricatio.models.kwargs_types import
|
16
|
+
from fabricatio.models.kwargs_types import (
|
17
|
+
ChooseKwargs,
|
18
|
+
CollectionSimpleConfigKwargs,
|
19
|
+
EmbeddingKwargs,
|
20
|
+
FetchKwargs,
|
21
|
+
LLMKwargs,
|
22
|
+
)
|
17
23
|
from fabricatio.models.usages import EmbeddingUsage
|
18
24
|
from fabricatio.models.utils import MilvusData
|
19
|
-
from more_itertools.recipes import flatten
|
25
|
+
from more_itertools.recipes import flatten, unique
|
20
26
|
from pydantic import Field, PrivateAttr
|
21
27
|
|
22
28
|
|
@@ -221,9 +227,9 @@ class RAG(EmbeddingUsage):
|
|
221
227
|
|
222
228
|
# Step 2: Flatten the search results
|
223
229
|
flattened_results = flatten(search_results)
|
224
|
-
|
230
|
+
unique_results = unique(flattened_results, key=itemgetter("id"))
|
225
231
|
# Step 3: Sort by distance (descending)
|
226
|
-
sorted_results = sorted(
|
232
|
+
sorted_results = sorted(unique_results, key=itemgetter("distance"), reverse=True)
|
227
233
|
|
228
234
|
logger.debug(f"Searched similarities: {[t['distance'] for t in sorted_results]}")
|
229
235
|
# Step 4: Extract the entities
|
@@ -308,3 +314,21 @@ class RAG(EmbeddingUsage):
|
|
308
314
|
f"{rendered}\n\n{extra_system_message}",
|
309
315
|
**kwargs,
|
310
316
|
)
|
317
|
+
|
318
|
+
async def arefined_query(self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs]) -> List[str]:
|
319
|
+
"""Refines the given question using a template.
|
320
|
+
|
321
|
+
Args:
|
322
|
+
question (List[str] | str): The question to be refined.
|
323
|
+
**kwargs (Unpack[ChooseKwargs]): Additional keyword arguments for the refinement process.
|
324
|
+
|
325
|
+
Returns:
|
326
|
+
List[str]: A list of refined questions.
|
327
|
+
"""
|
328
|
+
return await self.aliststr(
|
329
|
+
template_manager.render_template(
|
330
|
+
configs.templates.refined_query_template,
|
331
|
+
{"question": [question] if isinstance(question, str) else question},
|
332
|
+
),
|
333
|
+
**kwargs,
|
334
|
+
)
|
fabricatio/config.py
CHANGED
@@ -209,6 +209,9 @@ class TemplateConfig(BaseModel):
|
|
209
209
|
liststr_template: str = Field(default="liststr")
|
210
210
|
"""The name of the liststr template which will be used to display a list of strings."""
|
211
211
|
|
212
|
+
refined_query_template: str = Field(default="refined_query")
|
213
|
+
"""The name of the refined query template which will be used to refine a query."""
|
214
|
+
|
212
215
|
|
213
216
|
class MagikaConfig(BaseModel):
|
214
217
|
"""Magika configuration class."""
|
fabricatio/fs/__init__.py
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
"""FileSystem manipulation module for Fabricatio."""
|
2
2
|
|
3
|
-
from fabricatio.fs.
|
3
|
+
from fabricatio.fs.curd import copy_file, create_directory, delete_directory, delete_file, dump_text, move_file, tree
|
4
|
+
from fabricatio.fs.readers import magika, safe_json_read, safe_text_read
|
4
5
|
|
5
|
-
__all__ = [
|
6
|
+
__all__ = [
|
7
|
+
"copy_file",
|
8
|
+
"create_directory",
|
9
|
+
"delete_directory",
|
10
|
+
"delete_file",
|
11
|
+
"dump_text",
|
12
|
+
"magika",
|
13
|
+
"move_file",
|
14
|
+
"safe_json_read",
|
15
|
+
"safe_text_read",
|
16
|
+
"tree",
|
17
|
+
]
|
fabricatio/models/action.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
import traceback
|
4
4
|
from abc import abstractmethod
|
5
5
|
from asyncio import Queue, create_task
|
6
|
-
from typing import Any, Dict, Self, Tuple, Type, Union, Unpack
|
6
|
+
from typing import Any, Dict, Self, Tuple, Type, Union, Unpack, final
|
7
7
|
|
8
8
|
from fabricatio.capabilities.rating import GiveRating
|
9
9
|
from fabricatio.capabilities.task import HandleTask, ProposeTask
|
@@ -17,11 +17,26 @@ from pydantic import Field, PrivateAttr
|
|
17
17
|
class Action(HandleTask, ProposeTask, GiveRating):
|
18
18
|
"""Class that represents an action to be executed in a workflow."""
|
19
19
|
|
20
|
+
name: str = Field(default="")
|
21
|
+
"""The name of the action."""
|
22
|
+
description: str = Field(default="")
|
23
|
+
"""The description of the action."""
|
20
24
|
personality: str = Field(default="")
|
21
25
|
"""The personality of whom the action belongs to."""
|
22
26
|
output_key: str = Field(default="")
|
23
27
|
"""The key of the output data."""
|
24
28
|
|
29
|
+
@final
|
30
|
+
def model_post_init(self, __context: Any) -> None:
|
31
|
+
"""Initialize the action by setting the name if not provided.
|
32
|
+
|
33
|
+
Args:
|
34
|
+
__context: The context to be used for initialization.
|
35
|
+
"""
|
36
|
+
self.name = self.name or self.__class__.__name__
|
37
|
+
|
38
|
+
self.description = self.description or self.__class__.__doc__ or ""
|
39
|
+
|
25
40
|
@abstractmethod
|
26
41
|
async def _execute(self, **cxt: Unpack) -> Any:
|
27
42
|
"""Execute the action with the provided arguments.
|
@@ -34,6 +49,7 @@ class Action(HandleTask, ProposeTask, GiveRating):
|
|
34
49
|
"""
|
35
50
|
pass
|
36
51
|
|
52
|
+
@final
|
37
53
|
async def act(self, cxt: Dict[str, Any]) -> Dict[str, Any]:
|
38
54
|
"""Perform the action by executing it and setting the output data.
|
39
55
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"""Store article essence 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
|
+
)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
fabricatio-0.2.4.
|
2
|
-
fabricatio-0.2.4.
|
3
|
-
fabricatio-0.2.4.
|
1
|
+
fabricatio-0.2.4.dev3.dist-info/METADATA,sha256=aL1eAIQviM4LPVRJ4D2HyZT87tbZq47zgG9n8Q7xCzY,8589
|
2
|
+
fabricatio-0.2.4.dev3.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
|
3
|
+
fabricatio-0.2.4.dev3.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
|
4
4
|
fabricatio/decorators.py,sha256=cJHsxxbnMhc4SzPl4454CPLuDP3H0qbTrzV_U2rLPrs,6372
|
5
5
|
fabricatio/core.py,sha256=MaEKZ6DDmbdScAY-7F1gwGA6fr7ADX6Mz5rNVi2msFA,6277
|
6
6
|
fabricatio/models/generic.py,sha256=bjAD8g4tz1VjnIfnpTD6sRu1dBuBoswmUrn6pCnL6aY,11504
|
@@ -12,7 +12,7 @@ fabricatio/models/utils.py,sha256=vahILaesw50ofFft-wZ9kZ_Qogqi6vIOISWczvwVXxk,43
|
|
12
12
|
fabricatio/models/usages.py,sha256=iXh4MbDhrzshOxH704NY_5nbt7Lx5ckyBCs_nboxlM8,24943
|
13
13
|
fabricatio/models/events.py,sha256=sBCKeNoYc4TFDoke-jhFEyA11RcdGu-wdF5ynAuVOMM,3983
|
14
14
|
fabricatio/models/task.py,sha256=A0xdbrMeqhWqpmoMplTuaZmsKKHl93InZJ2iKjaRNBA,10683
|
15
|
-
fabricatio/models/action.py,sha256=
|
15
|
+
fabricatio/models/action.py,sha256=CYg4YPOo_NhAl8Nm8bCoEJkF4xPZZ-ZsVJmABrx2u_Q,6335
|
16
16
|
fabricatio/toolboxes/fs.py,sha256=oZjGOmtN8ZbkMXxCMatqvdPavVXyQ87AEDc1lx9jimY,483
|
17
17
|
fabricatio/toolboxes/__init__.py,sha256=iEBsH0aRPLccIe6eyZ6iH5GdK8yYNQTnCwLzw4pWXAA,465
|
18
18
|
fabricatio/toolboxes/arithmetic.py,sha256=sSTPkKI6-mb278DwQKFO9jKyzc9kCx45xNH7V6bGBpE,1307
|
@@ -20,19 +20,20 @@ fabricatio/toolboxes/task.py,sha256=9J3W-48CCEUh5PFz0XEC47Hv23Ugn1BEg-J_woQE1UA,
|
|
20
20
|
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
21
|
fabricatio/fs/readers.py,sha256=lqMrM5Nt3l6QJmPDoBno2PSaN2BbFwfUjBqaghrbK3A,1002
|
22
22
|
fabricatio/fs/curd.py,sha256=g74Pc2WPSkPlCXX0cWj2jyiDYTfkLwpwM480eyCkmc8,3851
|
23
|
-
fabricatio/fs/__init__.py,sha256=
|
24
|
-
fabricatio/config.py,sha256=
|
23
|
+
fabricatio/fs/__init__.py,sha256=Jlzk4AvBFgcgQ6nIgGRSUIh2UZHtpl27eyu395lR3c0,448
|
24
|
+
fabricatio/config.py,sha256=DfGJurqWVoLNgx9-DiCqBhcxgMSBY52atriw2iZsq1E,13341
|
25
25
|
fabricatio/journal.py,sha256=bzxZay48ZWI0VIkkDXm4Wc_Cc9lBQYa2VGx3Hxy_PtA,753
|
26
|
-
fabricatio/__init__.py,sha256=
|
27
|
-
fabricatio/actions/
|
28
|
-
fabricatio/actions/article.py,sha256=
|
26
|
+
fabricatio/__init__.py,sha256=gakP6hzHIQccKu9ByHhUP-cN36wCPEr11s13iTdO6EY,1503
|
27
|
+
fabricatio/actions/rag.py,sha256=tP1uKLq7mo19YhsJzFbGYryrcMx6xcvBc3n_Wzh0hjg,796
|
28
|
+
fabricatio/actions/article.py,sha256=ozqEa75_MS4OfCJZzcmF5_s3AJmAUrQGdHORWtZBsE0,1977
|
29
29
|
fabricatio/_rust_instances.py,sha256=JAtO-vL8ihvduf1SHLNf0w7ZSVGCJeIv6zZ9Ekyy1hY,271
|
30
|
+
fabricatio/workflows/articles.py,sha256=KlTaMSnxkQqHAIl-zZ8_wMqheka7IL99nt7XzQxDSF0,462
|
30
31
|
fabricatio/parser.py,sha256=S-4p1mjvJZEgnQW6WKdkmE68MzqqWXGSiLbADdhE-W4,4791
|
31
|
-
fabricatio/capabilities/rag.py,sha256=
|
32
|
+
fabricatio/capabilities/rag.py,sha256=OscJ8MVgOViMYps7rp8-MzAfSiog5i7zp7RkFzoSJPI,13805
|
32
33
|
fabricatio/capabilities/rating.py,sha256=E1obAS48B4j3Cf6rC6h-TyzRb4vQ2Hho2IM7630jSoI,13695
|
33
34
|
fabricatio/capabilities/propose.py,sha256=oW9QKpY2mDkVPEvgsgqxXxDR2ylVqN5TEL8E0Wh_vJI,1714
|
34
35
|
fabricatio/capabilities/task.py,sha256=BISAFbMgBI4udW0otE3-iyq0RXc05YN_30N0yI5qLxQ,4504
|
35
36
|
fabricatio/_rust.pyi,sha256=clhcURuiB9zlFo4m3VyoWQ8Xs4tvg6KNHXpF-ok9h4o,1703
|
36
|
-
fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=
|
37
|
-
fabricatio-0.2.4.
|
38
|
-
fabricatio-0.2.4.
|
37
|
+
fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=cdj3XswppApEvlov50l7ZgS_MLO3DMj_8B2SFdsWXe0,1350776
|
38
|
+
fabricatio-0.2.4.dev3.data/scripts/tdown,sha256=lUUKFHytXf1um4ZhtzvZlMqpBPWN7IjAsKKT9IgDwog,4560064
|
39
|
+
fabricatio-0.2.4.dev3.dist-info/RECORD,,
|
fabricatio/actions/__init__.py
DELETED
File without changes
|
File without changes
|
File without changes
|