fabricatio 0.2.4.dev1__tar.gz → 0.2.4.dev3__tar.gz
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-0.2.4.dev1 → fabricatio-0.2.4.dev3}/PKG-INFO +1 -1
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/llm_usages/llm_usage.py +3 -10
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/make_a_rating/rating.py +3 -9
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/make_diary/diary.py +1 -7
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/minor/hello_fabricatio.py +0 -1
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/propose_task/propose.py +0 -1
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/simple_chat/chat.py +0 -1
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/simple_rag/simple_rag.py +0 -1
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/task_handle/handle_task.py +3 -15
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/pyproject.toml +1 -1
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/__init__.py +4 -2
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/actions/article.py +7 -2
- fabricatio-0.2.4.dev3/python/fabricatio/actions/rag.py +25 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/capabilities/rag.py +28 -4
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/config.py +3 -0
- fabricatio-0.2.4.dev3/python/fabricatio/fs/__init__.py +17 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/action.py +17 -1
- fabricatio-0.2.4.dev3/python/fabricatio/workflows/articles.py +11 -0
- fabricatio-0.2.4.dev3/src/hbs_helpers.rs +15 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/src/lib.rs +1 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/src/templates.rs +7 -0
- fabricatio-0.2.4.dev3/templates/built-in/draft_rating_criteria.hbs +40 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/draft_rating_manual.hbs +20 -6
- fabricatio-0.2.4.dev3/templates/built-in/draft_rating_weights_klee.hbs +44 -0
- fabricatio-0.2.4.dev3/templates/built-in/draft_tool_usage_code.hbs +76 -0
- fabricatio-0.2.4.dev3/templates/built-in/extract_criteria_from_reasons.hbs +49 -0
- fabricatio-0.2.4.dev3/templates/built-in/extract_reasons_from_examples.hbs +48 -0
- fabricatio-0.2.4.dev3/templates/built-in/liststr.hbs +44 -0
- fabricatio-0.2.4.dev3/templates/built-in/make_choice.hbs +40 -0
- fabricatio-0.2.4.dev3/templates/built-in/make_judgment.hbs +35 -0
- fabricatio-0.2.4.dev3/templates/built-in/rate_fine_grind.hbs +51 -0
- fabricatio-0.2.4.dev3/templates/built-in/refined_query.hbs +36 -0
- fabricatio-0.2.4.dev3/templates.tar.gz +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/uv.lock +3 -1
- fabricatio-0.2.4.dev1/python/fabricatio/actions/__init__.py +0 -5
- fabricatio-0.2.4.dev1/python/fabricatio/fs/__init__.py +0 -5
- fabricatio-0.2.4.dev1/templates/built-in/draft_rating_criteria.hbs +0 -24
- fabricatio-0.2.4.dev1/templates/built-in/draft_rating_weights_klee.hbs +0 -23
- fabricatio-0.2.4.dev1/templates/built-in/draft_tool_usage_code.hbs +0 -66
- fabricatio-0.2.4.dev1/templates/built-in/extract_criteria_from_reasons.hbs +0 -24
- fabricatio-0.2.4.dev1/templates/built-in/extract_reasons_from_examples.hbs +0 -18
- fabricatio-0.2.4.dev1/templates/built-in/liststr.hbs +0 -26
- fabricatio-0.2.4.dev1/templates/built-in/make_choice.hbs +0 -25
- fabricatio-0.2.4.dev1/templates/built-in/make_judgment.hbs +0 -27
- fabricatio-0.2.4.dev1/templates/built-in/rate_fine_grind.hbs +0 -39
- fabricatio-0.2.4.dev1/templates.tar.gz +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/.gitignore +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/.python-version +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/Cargo.lock +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/Cargo.toml +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/LICENSE +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/Makefile +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/README.md +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/_rust.pyi +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/_rust_instances.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/capabilities/rating.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/extra.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/generic.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/kwargs_types.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/usages.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/models/utils.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/python/fabricatio/toolboxes/task.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/src/hash.rs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/tests/test_config.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.4.dev1 → fabricatio-0.2.4.dev3}/tests/test_models/test_usages.py +0 -0
@@ -11,7 +11,6 @@ from fabricatio.parser import PythonCapture
|
|
11
11
|
class WriteCode(Action):
|
12
12
|
"""Action that says hello to the world."""
|
13
13
|
|
14
|
-
name: str = "write code"
|
15
14
|
output_key: str = "task_output"
|
16
15
|
|
17
16
|
async def _execute(self, task_input: Task[str], **_) -> str:
|
@@ -22,10 +21,8 @@ class WriteCode(Action):
|
|
22
21
|
|
23
22
|
|
24
23
|
class WriteDocumentation(Action):
|
25
|
-
"""
|
24
|
+
"""write documentation for the code in markdown format."""
|
26
25
|
|
27
|
-
name: str = "write documentation"
|
28
|
-
description: str = "write documentation for the code in markdown format"
|
29
26
|
output_key: str = "task_output"
|
30
27
|
|
31
28
|
async def _execute(self, task_input: Task[str], **_) -> str:
|
@@ -38,12 +35,8 @@ async def main() -> None:
|
|
38
35
|
name="Coder",
|
39
36
|
description="A python coder who can write code and documentation",
|
40
37
|
registry={
|
41
|
-
Event.
|
42
|
-
|
43
|
-
),
|
44
|
-
Event.instantiate_from("doc").push_wildcard().push("pending"): WorkFlow(
|
45
|
-
name="write documentation", steps=(WriteDocumentation,)
|
46
|
-
),
|
38
|
+
Event.quick_instantiate("coding"): WorkFlow(name="write code", steps=(WriteCode,)),
|
39
|
+
Event.quick_instantiate("doc"): WorkFlow(name="write documentation", steps=(WriteDocumentation,)),
|
47
40
|
},
|
48
41
|
)
|
49
42
|
|
@@ -12,7 +12,6 @@ from fabricatio.models.task import Task
|
|
12
12
|
class Rate(Action):
|
13
13
|
"""Rate the task."""
|
14
14
|
|
15
|
-
name: str = "rate"
|
16
15
|
output_key: str = "task_output"
|
17
16
|
|
18
17
|
async def _execute(self, to_rate: List[str], rate_topic: str, criteria: Set[str], **_) -> List[Dict[str, float]]:
|
@@ -28,8 +27,6 @@ class Rate(Action):
|
|
28
27
|
class WhatToRate(Action):
|
29
28
|
"""Figure out what to rate."""
|
30
29
|
|
31
|
-
name: str = "figure out what to rate"
|
32
|
-
|
33
30
|
output_key: str = "to_rate"
|
34
31
|
|
35
32
|
async def _execute(self, task_input: Task, rate_topic: str, **cxt: Unpack) -> List[str]:
|
@@ -55,7 +52,6 @@ class WhatToRate(Action):
|
|
55
52
|
class MakeCriteria(Action):
|
56
53
|
"""Make criteria for rating."""
|
57
54
|
|
58
|
-
name: str = "make criteria"
|
59
55
|
output_key: str = "criteria"
|
60
56
|
|
61
57
|
async def _execute(self, rate_topic: str, to_rate: List[str], **cxt: Unpack) -> Set[str]:
|
@@ -67,8 +63,6 @@ class MakeCriteria(Action):
|
|
67
63
|
class MakeCompositeScore(Action):
|
68
64
|
"""Make a composite score."""
|
69
65
|
|
70
|
-
name: str = "make composite score"
|
71
|
-
|
72
66
|
output_key: str = "task_output"
|
73
67
|
|
74
68
|
async def _execute(self, rate_topic: str, to_rate: List[str], **cxt: Unpack) -> List[float]:
|
@@ -84,7 +78,7 @@ async def main() -> None:
|
|
84
78
|
name="TaskRater",
|
85
79
|
description="A role that can rate tasks.",
|
86
80
|
registry={
|
87
|
-
Event.
|
81
|
+
Event.quick_instantiate("rate_food"): WorkFlow(
|
88
82
|
name="Rate food",
|
89
83
|
steps=(WhatToRate, Rate),
|
90
84
|
extra_init_context={
|
@@ -92,14 +86,14 @@ async def main() -> None:
|
|
92
86
|
"criteria": {"taste", "price", "quality", "safety", "healthiness"},
|
93
87
|
},
|
94
88
|
),
|
95
|
-
Event.
|
89
|
+
Event.quick_instantiate("make_criteria_for_food"): WorkFlow(
|
96
90
|
name="Make criteria for food",
|
97
91
|
steps=(WhatToRate, MakeCriteria, Rate),
|
98
92
|
extra_init_context={
|
99
93
|
"rate_topic": "if the food is 'good'",
|
100
94
|
},
|
101
95
|
),
|
102
|
-
Event.
|
96
|
+
Event.quick_instantiate("make_composite_score"): WorkFlow(
|
103
97
|
name="Make composite score",
|
104
98
|
steps=(WhatToRate, MakeCompositeScore),
|
105
99
|
extra_init_context={
|
@@ -13,8 +13,6 @@ from pydantic import Field
|
|
13
13
|
class WriteDiary(Action):
|
14
14
|
"""Write a diary according to the given commit messages in json format."""
|
15
15
|
|
16
|
-
name: str = "write diary"
|
17
|
-
description: str = "write a diary according to the given commit messages in json format"
|
18
16
|
output_key: str = "dump_text"
|
19
17
|
|
20
18
|
async def _execute(self, task_input: Task[str], **_) -> str:
|
@@ -50,8 +48,6 @@ class WriteDiary(Action):
|
|
50
48
|
class DumpText(Action):
|
51
49
|
"""Dump the text to a file."""
|
52
50
|
|
53
|
-
name: str = "dump text"
|
54
|
-
description: str = "dump text to a file"
|
55
51
|
toolboxes: Set[ToolBox] = Field(default_factory=lambda: {fs_toolbox})
|
56
52
|
output_key: str = "task_output"
|
57
53
|
|
@@ -77,9 +73,7 @@ async def main() -> None:
|
|
77
73
|
name="Coder",
|
78
74
|
description="A python coder who can ",
|
79
75
|
registry={
|
80
|
-
Event.
|
81
|
-
name="write documentation", steps=(WriteDiary, DumpText)
|
82
|
-
),
|
76
|
+
Event.quick_instantiate("doc"): WorkFlow(name="write documentation", steps=(WriteDiary, DumpText)),
|
83
77
|
},
|
84
78
|
)
|
85
79
|
|
@@ -11,7 +11,6 @@ task = Task(name="say hello", goals=["say hello"], description="say hello to the
|
|
11
11
|
class Hello(Action):
|
12
12
|
"""Action that says hello."""
|
13
13
|
|
14
|
-
name: str = "hello"
|
15
14
|
output_key: str = "task_output"
|
16
15
|
|
17
16
|
async def _execute(self, task_input: Task[str], **_) -> Any:
|
@@ -10,7 +10,6 @@ from pydantic import Field
|
|
10
10
|
class WriteCode(Action):
|
11
11
|
"""Action that says hello to the world."""
|
12
12
|
|
13
|
-
name: str = "write code"
|
14
13
|
output_key: str = "dump_text"
|
15
14
|
|
16
15
|
async def _execute(self, task_input: Task[str], **_) -> str:
|
@@ -24,8 +23,6 @@ class WriteCode(Action):
|
|
24
23
|
class DumpText(Action):
|
25
24
|
"""Dump the text to a file."""
|
26
25
|
|
27
|
-
name: str = "dump text"
|
28
|
-
description: str = "dump text to a file"
|
29
26
|
toolboxes: Set[ToolBox] = Field(default_factory=lambda: {fs_toolbox})
|
30
27
|
output_key: str = "task_output"
|
31
28
|
|
@@ -48,8 +45,6 @@ class DumpText(Action):
|
|
48
45
|
class WriteDocumentation(Action):
|
49
46
|
"""Action that says hello to the world."""
|
50
47
|
|
51
|
-
name: str = "write documentation"
|
52
|
-
description: str = "write documentation for the code in markdown format"
|
53
48
|
output_key: str = "dump_text"
|
54
49
|
|
55
50
|
async def _execute(self, task_input: Task[str], **_) -> str:
|
@@ -59,8 +54,6 @@ class WriteDocumentation(Action):
|
|
59
54
|
class TestCancel(Action):
|
60
55
|
"""Action that says hello to the world."""
|
61
56
|
|
62
|
-
name: str = "cancel"
|
63
|
-
description: str = "cancel the task"
|
64
57
|
output_key: str = "counter"
|
65
58
|
|
66
59
|
async def _execute(self, counter: int, **_) -> int:
|
@@ -73,7 +66,6 @@ class TestCancel(Action):
|
|
73
66
|
class WriteToOutput(Action):
|
74
67
|
"""Action that says hello to the world."""
|
75
68
|
|
76
|
-
name: str = "write to output"
|
77
69
|
output_key: str = "task_output"
|
78
70
|
|
79
71
|
async def _execute(self, **_) -> str:
|
@@ -86,13 +78,9 @@ async def main() -> None:
|
|
86
78
|
name="Coder",
|
87
79
|
description="A python coder who can ",
|
88
80
|
registry={
|
89
|
-
Event.
|
90
|
-
|
91
|
-
)
|
92
|
-
Event.instantiate_from("doc").push_wildcard().push("pending"): WorkFlow(
|
93
|
-
name="write documentation", steps=(WriteDocumentation, DumpText)
|
94
|
-
),
|
95
|
-
Event.instantiate_from("cancel_test").push_wildcard().push("pending"): WorkFlow(
|
81
|
+
Event.quick_instantiate("coding"): WorkFlow(name="write code", steps=(WriteCode, DumpText)),
|
82
|
+
Event.quick_instantiate("doc"): WorkFlow(name="write documentation", steps=(WriteDocumentation, DumpText)),
|
83
|
+
Event.quick_instantiate("cancel_test"): WorkFlow(
|
96
84
|
name="cancel_test",
|
97
85
|
steps=(TestCancel, TestCancel, TestCancel, TestCancel, TestCancel, TestCancel, WriteToOutput),
|
98
86
|
extra_init_context={"counter": 0},
|
@@ -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
|
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
|
@@ -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
|
+
)
|
@@ -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."""
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"""FileSystem manipulation module for Fabricatio."""
|
2
|
+
|
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
|
5
|
+
|
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
|
+
)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
use handlebars::handlebars_helper;
|
2
|
+
use serde_json::Value;
|
3
|
+
|
4
|
+
handlebars_helper!(len: |v: Value| {
|
5
|
+
if v.is_array(){
|
6
|
+
v.as_array().unwrap().len()
|
7
|
+
}else if v.is_object(){
|
8
|
+
v.as_object().unwrap().len()
|
9
|
+
}else if v.is_string(){
|
10
|
+
v.as_str().unwrap().len()
|
11
|
+
}else{
|
12
|
+
0
|
13
|
+
}
|
14
|
+
|
15
|
+
});
|
@@ -1,3 +1,4 @@
|
|
1
|
+
use crate::hbs_helpers::len;
|
1
2
|
use handlebars::{no_escape, Handlebars};
|
2
3
|
use pyo3::exceptions::PyRuntimeError;
|
3
4
|
use pyo3::prelude::*;
|
@@ -34,6 +35,7 @@ impl TemplateManager {
|
|
34
35
|
suffix:suffix.unwrap_or("hbs".to_string())
|
35
36
|
};
|
36
37
|
manager.discover_templates();
|
38
|
+
manager.register_builtin_helper();
|
37
39
|
Ok(manager)
|
38
40
|
}
|
39
41
|
|
@@ -90,6 +92,11 @@ impl TemplateManager {
|
|
90
92
|
})
|
91
93
|
.collect()
|
92
94
|
}
|
95
|
+
|
96
|
+
fn register_builtin_helper(&mut self){
|
97
|
+
self.handlebars.register_helper("len",Box::new(len))
|
98
|
+
}
|
99
|
+
|
93
100
|
}
|
94
101
|
|
95
102
|
pub(crate) fn register(_: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Task
|
2
|
+
Please draft rating criteria for the topic: "{{ topic }}".
|
3
|
+
|
4
|
+
## CFER Framework
|
5
|
+
Create criteria that are:
|
6
|
+
- **Comprehensive**: Cover all important aspects of the topic
|
7
|
+
- **Fair**: Measurable and objective across different instances
|
8
|
+
- **Evidence-based**: Can be evaluated based on observable evidence
|
9
|
+
- **Relevant**: Directly related to the quality or performance of the topic
|
10
|
+
|
11
|
+
Return the criteria{{#if criteria_count}} with exactly {{ criteria_count }} items{{/if}} in JSON format as a list of strings within code block.
|
12
|
+
|
13
|
+
# Example:
|
14
|
+
Rating criteria for the topic "Nice icecream"
|
15
|
+
|
16
|
+
----- Start of response example -----
|
17
|
+
```json
|
18
|
+
[
|
19
|
+
"Visual appeal (color, presentation, garnish)",
|
20
|
+
"Flavor complexity and authenticity",
|
21
|
+
"Texture consistency and mouthfeel",
|
22
|
+
"Ingredient quality and freshness",
|
23
|
+
"Value for price point"
|
24
|
+
]
|
25
|
+
```
|
26
|
+
----- End of response example -----
|
27
|
+
|
28
|
+
## Aspect Introduction
|
29
|
+
Each criterion should:
|
30
|
+
- Be concise yet descriptive (5-10 words)
|
31
|
+
- Represent a distinct aspect of evaluation
|
32
|
+
- Be applicable across different instances of the topic
|
33
|
+
- Avoid overlapping with other criteria
|
34
|
+
- Use terminology relevant to the domain
|
35
|
+
|
36
|
+
# Warning
|
37
|
+
- Please ensure that the criteria are clear, concise, and independently measurable.
|
38
|
+
- The response SHALL be returned as a JSON array within the codeblock.
|
39
|
+
- No additional explanation is needed.
|
40
|
+
{{#if criteria_count }}- You must return exactly {{ criteria_count }} criteria.{{/if}}
|
@@ -1,16 +1,22 @@
|
|
1
1
|
# Task
|
2
|
-
Please draft a rating manual for the following topic and criteria
|
2
|
+
Please draft a rating manual for the following topic and criteria. This manual will guide evaluators in applying consistent standards.
|
3
3
|
|
4
4
|
Topic: {{ topic }}
|
5
5
|
Criteria: {{ criteria }}
|
6
6
|
|
7
|
-
|
7
|
+
## CFER Framework
|
8
|
+
Ensure your rating manual follows these principles:
|
9
|
+
- **Comprehensive**: Cover all important aspects of each criterion
|
10
|
+
- **Fair**: Describe measurable and objective evaluation standards
|
11
|
+
- **Evidence-based**: Focus on observable evidence for each rating level
|
12
|
+
- **Relevant**: Connect directly to quality or performance within the topic
|
8
13
|
|
14
|
+
Return the rating manual as a JSON object within a codeblock where the keys are the criteria and the values are the detailed descriptions for each criterion.
|
9
15
|
|
10
16
|
# Example:
|
11
17
|
|
12
|
-
|
13
|
-
|
18
|
+
Topic: Nice icecream
|
19
|
+
Criteria: ["outlook","taste","texture"]
|
14
20
|
----- Start of response example -----
|
15
21
|
```json
|
16
22
|
{
|
@@ -19,9 +25,17 @@ criteria:["outlook","taste","texture"]
|
|
19
25
|
"texture": "How the icecream feels. High score for smooth texture without icy bits, melts smoothly in the mouth providing a creamy experience; low score for rough texture containing many ice crystals, feeling like it has been frozen for too long lacking softness."
|
20
26
|
}
|
21
27
|
```
|
22
|
-
-----
|
28
|
+
----- End of response example -----
|
29
|
+
|
30
|
+
## Aspect Introduction
|
31
|
+
For each criterion in your manual:
|
32
|
+
- Provide a clear definition of what the criterion measures
|
33
|
+
- Include specific examples of high-quality and low-quality manifestations
|
34
|
+
- Define observable characteristics evaluators should look for
|
35
|
+
- Use domain-appropriate terminology
|
36
|
+
- Ensure the description enables consistent application across different instances
|
23
37
|
|
24
38
|
# Warning
|
25
39
|
- Please ensure that the rating manual is clear and concise, and that the criteria for each criterion are well-defined.
|
26
40
|
- The response SHALL be returned as a JSON object within the codeblock.
|
27
|
-
- No additional
|
41
|
+
- No additional explanation is needed.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Task:
|
2
|
+
Please compare the relative importance of the following criteria for evaluating "{{topic}}":
|
3
|
+
|
4
|
+
First Criterion: {{first}}
|
5
|
+
Second Criterion: {{second}}
|
6
|
+
|
7
|
+
## CFER Framework
|
8
|
+
When determining the relative importance weight, consider these principles:
|
9
|
+
- **Comprehensive**: Consider how each criterion contributes to the overall evaluation
|
10
|
+
- **Fair**: Base your weighting on objective measures rather than personal preference
|
11
|
+
- **Evidence-based**: Consider measurable impacts of each criterion on outcomes
|
12
|
+
- **Relevant**: Prioritize criteria based on their direct influence on {{topic}} quality
|
13
|
+
|
14
|
+
Provide a positive floating-point number where:
|
15
|
+
- 1.0 means the criteria are equally important
|
16
|
+
- > 1.0 means `{{second}}` is more important (e.g., 2.0 means twice as important)
|
17
|
+
- < 1.0 means `{{first}}` is more important (e.g., 0.5 means half as important)
|
18
|
+
|
19
|
+
Your response SHALL be a positive floating-point number within a JSON codeblock.
|
20
|
+
|
21
|
+
## Aspect Introduction
|
22
|
+
When comparing these criteria:
|
23
|
+
- Consider the core purpose and context of "{{topic}}"
|
24
|
+
- Evaluate which criterion has broader impact on outcomes
|
25
|
+
- Assess which criterion is more foundational or prerequisite
|
26
|
+
- Consider which criterion is more difficult to compensate for if lacking
|
27
|
+
- Think about which criterion users/stakeholders would prioritize
|
28
|
+
- Consider industry standards and expert consensus in this domain
|
29
|
+
|
30
|
+
# Example:
|
31
|
+
Topic: "Best icecream"
|
32
|
+
First Criterion: "Taste"
|
33
|
+
Second Criterion: "Texture"
|
34
|
+
|
35
|
+
----- Start of response example -----
|
36
|
+
```json
|
37
|
+
1.5
|
38
|
+
```
|
39
|
+
----- End of response example -----
|
40
|
+
|
41
|
+
# Warning:
|
42
|
+
- Your response must be a POSITIVE floating-point number within a JSON codeblock.
|
43
|
+
- No explanation or additional information is needed, only the positive floating-point number.
|
44
|
+
- The number should reflect a careful consideration of relative importance, not random selection.
|