fabricatio 0.2.4.dev1__cp312-cp312-manylinux_2_34_x86_64.whl → 0.2.4.dev2__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 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"]
@@ -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 an article. output as json"
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/fs/__init__.py CHANGED
@@ -1,5 +1,17 @@
1
1
  """FileSystem manipulation module for Fabricatio."""
2
2
 
3
- from fabricatio.fs.readers import magika
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__ = ["magika"]
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
+ ]
@@ -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
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.4.dev1
3
+ Version: 0.2.4.dev2
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,6 +1,6 @@
1
- fabricatio-0.2.4.dev1.dist-info/METADATA,sha256=Y5iwc8ttCDQZinkAsi9fgqDCvHLpE91wIha-thu9NJ0,8589
2
- fabricatio-0.2.4.dev1.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
3
- fabricatio-0.2.4.dev1.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
1
+ fabricatio-0.2.4.dev2.dist-info/METADATA,sha256=vhANe4uPf0Sg_UmcfdmjBD9GI44lY6XrlLz0OFf4bQk,8589
2
+ fabricatio-0.2.4.dev2.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
3
+ fabricatio-0.2.4.dev2.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=EfggvxZFhdfHmie0C3XCHFXSlLIjZKB3MXf0530MAiI,5803
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,13 +20,14 @@ 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=bYE9r8uR0dtknzbg_YaGv_6Wwa27ntkQt0Tl7Kb3HFI,117
23
+ fabricatio/fs/__init__.py,sha256=Jlzk4AvBFgcgQ6nIgGRSUIh2UZHtpl27eyu395lR3c0,448
24
24
  fabricatio/config.py,sha256=ZUUJ5rb6ZBq8Vrkk9wqfMU8ncomRoHgarW7YuThEJK4,13188
25
25
  fabricatio/journal.py,sha256=bzxZay48ZWI0VIkkDXm4Wc_Cc9lBQYa2VGx3Hxy_PtA,753
26
- fabricatio/__init__.py,sha256=I1CtksFFUCXsnSLAL51369S4ExY9uUE9Xdo4jK6hFls,1356
27
- fabricatio/actions/__init__.py,sha256=ggTW1wZntPjWP-JHEZe1vqoyImmUnCt15h40zC5rx98,125
28
- fabricatio/actions/article.py,sha256=esuDgD1eJ4W_UPvpdHSPugT2qDbqfNdatFx9xgFT5l4,1610
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
32
  fabricatio/capabilities/rag.py,sha256=bF-SSZRQbG00QjzoAXrWCfzFxHxfvxV3al_G8T4jxL8,12985
32
33
  fabricatio/capabilities/rating.py,sha256=E1obAS48B4j3Cf6rC6h-TyzRb4vQ2Hho2IM7630jSoI,13695
@@ -34,5 +35,5 @@ fabricatio/capabilities/propose.py,sha256=oW9QKpY2mDkVPEvgsgqxXxDR2ylVqN5TEL8E0W
34
35
  fabricatio/capabilities/task.py,sha256=BISAFbMgBI4udW0otE3-iyq0RXc05YN_30N0yI5qLxQ,4504
35
36
  fabricatio/_rust.pyi,sha256=clhcURuiB9zlFo4m3VyoWQ8Xs4tvg6KNHXpF-ok9h4o,1703
36
37
  fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=CDyz4oafWsO46rOc8DyHBfDVj4dY2LkheAQTGfSXmgs,1333952
37
- fabricatio-0.2.4.dev1.data/scripts/tdown,sha256=lUUKFHytXf1um4ZhtzvZlMqpBPWN7IjAsKKT9IgDwog,4560064
38
- fabricatio-0.2.4.dev1.dist-info/RECORD,,
38
+ fabricatio-0.2.4.dev2.data/scripts/tdown,sha256=lUUKFHytXf1um4ZhtzvZlMqpBPWN7IjAsKKT9IgDwog,4560064
39
+ fabricatio-0.2.4.dev2.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- """module for actions."""
2
-
3
- from fabricatio.actions.article import ExtractArticleEssence
4
-
5
- __all__ = ["ExtractArticleEssence"]