fabricatio 0.2.4.dev1__cp312-cp312-win_amd64.whl → 0.2.4.dev2__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 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
@@ -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,8 +1,8 @@
1
- fabricatio-0.2.4.dev1.dist-info/METADATA,sha256=_gk2kBD669jBzVql6w4SSnaMHDkJlQ393i-7QyJBock,8861
2
- fabricatio-0.2.4.dev1.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
- fabricatio-0.2.4.dev1.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
4
- fabricatio/actions/article.py,sha256=8T_ZqNs8OPxL2nTQ5D0YsOMQ7R5_TBf7oM5dbPmMbe8,1654
5
- fabricatio/actions/__init__.py,sha256=CjlbRaRqqKWPxqZEtk7tQt3Mul17CY9O4alo6VjWGNk,130
1
+ fabricatio-0.2.4.dev2.dist-info/METADATA,sha256=YUalxhNAZsg0MtzLphoGT-eQdAjp0sk07vr_4aGqsOU,8861
2
+ fabricatio-0.2.4.dev2.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
+ fabricatio-0.2.4.dev2.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
6
  fabricatio/capabilities/propose.py,sha256=nahXjB6_nP0Fru880oh_9oINrjrL0Qs-SLHA-d3CFUE,1769
7
7
  fabricatio/capabilities/rag.py,sha256=paq2zUOfw6whIBFkKDo1Kg5Ft5YXgWiJBNKq-6uGhuU,13295
8
8
  fabricatio/capabilities/rating.py,sha256=PcUpKxPfVO-vitgA6py1xg9iLJZdf7Fru--18ZUFKKA,14026
@@ -12,9 +12,9 @@ fabricatio/core.py,sha256=VQ_JKgUGIy2gZ8xsTBZCdr_IP7wC5aPg0_bsOmjQ588,6458
12
12
  fabricatio/decorators.py,sha256=uzsP4tFKQNjDHBkofsjjoJA0IUAaYOtt6YVedoyOqlo,6551
13
13
  fabricatio/fs/curd.py,sha256=faMstgGUiQ4k2AW3OXfvvWWTldTtKXco7QINYaMjmyA,3981
14
14
  fabricatio/fs/readers.py,sha256=Pz1-cdZYtmqr032dsroImlkFXAd0kCYY_9qVpD4UrG4,1045
15
- fabricatio/fs/__init__.py,sha256=lWcKYg0v3mv2LnnSegOQaTtlVDODU0vtw_s6iKU5IqQ,122
15
+ fabricatio/fs/__init__.py,sha256=9yH1-3mdWf2isbCqbaQO7xs1f6eoiPn4uKUAETNRk0A,465
16
16
  fabricatio/journal.py,sha256=siqimKF0M_QaaOCMxtjr_BJVNyUIAQWILzE9Q4T6-7c,781
17
- fabricatio/models/action.py,sha256=HVU0cAOuiBszRJrOskFASwt1yxSO7HCP4epS03p92WU,5947
17
+ fabricatio/models/action.py,sha256=yj3Tt_UWGnkoVQNCMOBIqxDeyfXFEQp1oS4xd-nDXCY,6495
18
18
  fabricatio/models/events.py,sha256=pt-WkFhhA5SXmp6-3Vb_o_7I5xbKoTCJ22GAK7YYwpA,4101
19
19
  fabricatio/models/extra.py,sha256=0v5v0a_xcXcDTeIDmwtzUO68HjrmVvLHM6ALWvl9h6w,4328
20
20
  fabricatio/models/generic.py,sha256=3S16T7nZEDhDF-VLSmRPa7NEtapZjU5WQHosoisqbTw,11843
@@ -30,9 +30,10 @@ fabricatio/toolboxes/arithmetic.py,sha256=WLqhY-Pikv11Y_0SGajwZx3WhsLNpHKf9drzAq
30
30
  fabricatio/toolboxes/fs.py,sha256=YkNgon5-bvCiPVEND9971W-6wj8btKNL6nGry2otn9I,498
31
31
  fabricatio/toolboxes/task.py,sha256=kU4a501awIDV7GwNDuSlK3_Ym-5OhCp5sS-insTmUmQ,269
32
32
  fabricatio/toolboxes/__init__.py,sha256=b13KmASO8q5fBLwew964fn9oH86ER5g-S1PgA4fZ_xs,482
33
+ fabricatio/workflows/articles.py,sha256=gZlmC2tS1YnSajZft6jN0VTSj6rcuT8367nBYD8edoI,473
33
34
  fabricatio/_rust.pyi,sha256=0wCqtwWkVxxoqprvk8T27T8QYKIAKHS7xgsmdMNjQKc,1756
34
35
  fabricatio/_rust_instances.py,sha256=dl0-yZ4UvT5g20tQgnPJpmqtkjFGXNG_YK4eLfi_ugQ,279
35
- fabricatio/__init__.py,sha256=lk9xEYWoiGdsIPjTCdoZ85tz0a7SDjXm6ORaxGx-dYw,1405
36
- fabricatio/_rust.cp312-win_amd64.pyd,sha256=OyB3QxCCDgBSoyWf_sseCWdRhXrQ9HqBrb7Vk7QEN7Y,1256448
37
- fabricatio-0.2.4.dev1.data/scripts/tdown.exe,sha256=aRm7EGhU3Mr6brN3iWId7kCKojnttdHnjI0M7Ap2vr0,3397632
38
- fabricatio-0.2.4.dev1.dist-info/RECORD,,
36
+ fabricatio/__init__.py,sha256=lIjAvhmypC8kZNpymjmYByJtZjzJNXDmNzY36x1o7h8,1554
37
+ fabricatio/_rust.cp312-win_amd64.pyd,sha256=7rUG_4XSeuPJ3ohjbxqO82_v-Uzz6thtmnJHLkkHXP8,1256448
38
+ fabricatio-0.2.4.dev2.data/scripts/tdown.exe,sha256=SgyRf4z5d_TsM5rWtd9dvyrELP4lSYAm689xzwqPIm8,3397632
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"]