fabricatio 0.4.0__cp313-cp313-win_amd64.whl → 0.4.0.dev0__cp313-cp313-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 +1 -3
- fabricatio/rust.cp313-win_amd64.pyd +0 -0
- fabricatio/toolboxes/arithmetic.py +1 -1
- fabricatio/toolboxes/fs.py +2 -2
- {fabricatio-0.4.0.data → fabricatio-0.4.0.dev0.data}/scripts/tdown.exe +0 -0
- {fabricatio-0.4.0.dist-info → fabricatio-0.4.0.dev0.dist-info}/METADATA +8 -3
- fabricatio-0.4.0.dev0.dist-info/RECORD +13 -0
- fabricatio/actions/__init__.py +0 -1
- fabricatio/actions/fs.py +0 -25
- fabricatio/actions/output.py +0 -247
- fabricatio/actions/rag.py +0 -96
- fabricatio/actions/rules.py +0 -83
- fabricatio-0.4.0.dist-info/RECORD +0 -18
- {fabricatio-0.4.0.dist-info → fabricatio-0.4.0.dev0.dist-info}/WHEEL +0 -0
- {fabricatio-0.4.0.dist-info → fabricatio-0.4.0.dev0.dist-info}/licenses/LICENSE +0 -0
fabricatio/__init__.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
"""Fabricatio is a Python library for building llm app using event-based agent structure."""
|
2
2
|
|
3
|
+
from fabricatio import toolboxes, workflows
|
3
4
|
from fabricatio_core import fs, models, parser, utils
|
4
5
|
from fabricatio_core.journal import logger
|
5
6
|
from fabricatio_core.models.action import Action, WorkFlow
|
@@ -8,8 +9,6 @@ from fabricatio_core.models.task import Task
|
|
8
9
|
from fabricatio_core.models.tool import ToolBox
|
9
10
|
from fabricatio_core.rust import CONFIG, TEMPLATE_MANAGER, Event
|
10
11
|
|
11
|
-
from fabricatio import actions, toolboxes, workflows
|
12
|
-
|
13
12
|
__all__ = [
|
14
13
|
"CONFIG",
|
15
14
|
"TEMPLATE_MANAGER",
|
@@ -19,7 +18,6 @@ __all__ = [
|
|
19
18
|
"Task",
|
20
19
|
"ToolBox",
|
21
20
|
"WorkFlow",
|
22
|
-
"actions",
|
23
21
|
"fs",
|
24
22
|
"logger",
|
25
23
|
"models",
|
Binary file
|
fabricatio/toolboxes/fs.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"""File system tool box."""
|
2
2
|
|
3
|
-
from
|
3
|
+
from fabricatio_core.fs import (
|
4
4
|
absolute_path,
|
5
5
|
copy_file,
|
6
6
|
create_directory,
|
@@ -13,7 +13,7 @@ from fabricatio.fs import (
|
|
13
13
|
safe_text_read,
|
14
14
|
tree,
|
15
15
|
)
|
16
|
-
from
|
16
|
+
from fabricatio_core.models.tool import ToolBox
|
17
17
|
|
18
18
|
fs_toolbox = (
|
19
19
|
ToolBox(name="FsToolBox", description="A toolbox for basic file system operations.")
|
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fabricatio
|
3
|
-
Version: 0.4.0
|
3
|
+
Version: 0.4.0.dev0
|
4
4
|
Classifier: License :: OSI Approved :: MIT License
|
5
5
|
Classifier: Programming Language :: Rust
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -10,8 +10,7 @@ Classifier: Framework :: AsyncIO
|
|
10
10
|
Classifier: Framework :: Pydantic :: 2
|
11
11
|
Classifier: Typing :: Typed
|
12
12
|
Requires-Dist: fabricatio-core
|
13
|
-
Requires-Dist: fabricatio
|
14
|
-
Requires-Dist: fabricatio[ftd,qa,rag,cli,typst,rule,judge] ; extra == 'full'
|
13
|
+
Requires-Dist: fabricatio[ftd,qa,rag,cli,typst,rule,judge,capabilities,actions] ; extra == 'full'
|
15
14
|
Requires-Dist: fabricatio-rag ; extra == 'rag'
|
16
15
|
Requires-Dist: fabricatio-judge ; extra == 'judge'
|
17
16
|
Requires-Dist: fabricatio-rule ; extra == 'rule'
|
@@ -19,6 +18,9 @@ Requires-Dist: questionary>=2.1.0 ; extra == 'qa'
|
|
19
18
|
Requires-Dist: magika>=0.6.1 ; extra == 'ftd'
|
20
19
|
Requires-Dist: typer-slim[standard]>=0.15.2 ; extra == 'cli'
|
21
20
|
Requires-Dist: fabricatio-typst ; extra == 'typst'
|
21
|
+
Requires-Dist: fabricatio-improve ; extra == 'improve'
|
22
|
+
Requires-Dist: fabricatio-capabilities ; extra == 'capabilities'
|
23
|
+
Requires-Dist: fabricatio-actions ; extra == 'actions'
|
22
24
|
Provides-Extra: full
|
23
25
|
Provides-Extra: rag
|
24
26
|
Provides-Extra: judge
|
@@ -27,6 +29,9 @@ Provides-Extra: qa
|
|
27
29
|
Provides-Extra: ftd
|
28
30
|
Provides-Extra: cli
|
29
31
|
Provides-Extra: typst
|
32
|
+
Provides-Extra: improve
|
33
|
+
Provides-Extra: capabilities
|
34
|
+
Provides-Extra: actions
|
30
35
|
License-File: LICENSE
|
31
36
|
Summary: A LLM multi-agent framework.
|
32
37
|
Keywords: ai,agents,multi-agent,llm,pyo3
|
@@ -0,0 +1,13 @@
|
|
1
|
+
fabricatio-0.4.0.dev0.data/scripts/tdown.exe,sha256=CknuR-ux_D0TLfFPS5ciBdsheg4cbiJAV9BjoRm_w1s,3378176
|
2
|
+
fabricatio-0.4.0.dev0.dist-info/METADATA,sha256=e2CWOqor1_NCKIPX0iLwzs_PU5sDOg-vgssE03c8Adw,5428
|
3
|
+
fabricatio-0.4.0.dev0.dist-info/WHEEL,sha256=Fk195VgSS-LCRRJAxz6O39eu2NdDhBCq3h9q4zoTguY,96
|
4
|
+
fabricatio-0.4.0.dev0.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
|
5
|
+
fabricatio/__init__.py,sha256=lRDjxg_ZZwE9GTASwUOuHc6asov0JRJHJ4PqI2rph_g,759
|
6
|
+
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
fabricatio/rust.cp313-win_amd64.pyd,sha256=jlL8yq1Uk8ApCYOFFlfwDZpGHl7Num2V-KIJwW5PuVY,176128
|
8
|
+
fabricatio/toolboxes/__init__.py,sha256=KBJi5OG_pExscdlM7Bnt_UF43j4I3Lv6G71kPVu4KQU,395
|
9
|
+
fabricatio/toolboxes/arithmetic.py,sha256=tcaHLzGQvnlbxG57IANpZ2vTRO5QpSt366RckBlBIOg,1374
|
10
|
+
fabricatio/toolboxes/fs.py,sha256=fpSfU6YkCVJzSXsbT9WT3m80tH8i6mhLWnu9u7yhV-w,746
|
11
|
+
fabricatio/workflows/__init__.py,sha256=5ScFSTA-bvhCesj3U9Mnmi6Law6N1fmh5UKyh58L3u8,51
|
12
|
+
fabricatio/workflows/rag.py,sha256=O8qCLhZTJTEj72R7W6Nq3WFg2I42arzQJkIGaeDdpss,527
|
13
|
+
fabricatio-0.4.0.dev0.dist-info/RECORD,,
|
fabricatio/actions/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
"""A module containing some builtin actins."""
|
fabricatio/actions/fs.py
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
"""A module for file system utilities."""
|
2
|
-
|
3
|
-
from pathlib import Path
|
4
|
-
from typing import Any, List, Mapping, Self
|
5
|
-
|
6
|
-
from fabricatio.fs import safe_text_read
|
7
|
-
from fabricatio.journal import logger
|
8
|
-
from fabricatio.models.action import Action
|
9
|
-
from fabricatio.models.generic import FromMapping
|
10
|
-
|
11
|
-
|
12
|
-
class ReadText(Action, FromMapping):
|
13
|
-
"""Read text from a file."""
|
14
|
-
output_key: str = "read_text"
|
15
|
-
read_path: str | Path
|
16
|
-
"""Path to the file to read."""
|
17
|
-
|
18
|
-
async def _execute(self, *_: Any, **cxt) -> str:
|
19
|
-
logger.info(f"Read text from {Path(self.read_path).as_posix()} to {self.output_key}")
|
20
|
-
return safe_text_read(self.read_path)
|
21
|
-
|
22
|
-
@classmethod
|
23
|
-
def from_mapping(cls, mapping: Mapping[str, str | Path], **kwargs: Any) -> List[Self]:
|
24
|
-
"""Create a list of ReadText actions from a mapping of output_key to read_path."""
|
25
|
-
return [cls(read_path=p, output_key=k, **kwargs) for k, p in mapping.items()]
|
fabricatio/actions/output.py
DELETED
@@ -1,247 +0,0 @@
|
|
1
|
-
"""Dump the finalized output to a file."""
|
2
|
-
|
3
|
-
from pathlib import Path
|
4
|
-
from typing import Any, Iterable, List, Mapping, Optional, Self, Sequence, Type
|
5
|
-
|
6
|
-
from fabricatio.fs import dump_text
|
7
|
-
from fabricatio.journal import logger
|
8
|
-
from fabricatio.models.action import Action
|
9
|
-
from fabricatio.models.generic import FinalizedDumpAble, FromMapping, FromSequence, PersistentAble
|
10
|
-
from fabricatio.models.task import Task
|
11
|
-
from fabricatio.models.usages import LLMUsage
|
12
|
-
from fabricatio.rust import TEMPLATE_MANAGER
|
13
|
-
from fabricatio.utils import ok
|
14
|
-
|
15
|
-
|
16
|
-
class DumpFinalizedOutput(Action, LLMUsage):
|
17
|
-
"""Dump the finalized output to a file."""
|
18
|
-
|
19
|
-
output_key: str = "dump_path"
|
20
|
-
dump_path: Optional[str] = None
|
21
|
-
|
22
|
-
async def _execute(
|
23
|
-
self,
|
24
|
-
to_dump: FinalizedDumpAble,
|
25
|
-
task_input: Optional[Task] = None,
|
26
|
-
dump_path: Optional[str | Path] = None,
|
27
|
-
**_,
|
28
|
-
) -> str:
|
29
|
-
dump_path = Path(
|
30
|
-
dump_path
|
31
|
-
or self.dump_path
|
32
|
-
or ok(
|
33
|
-
await self.awhich_pathstr(
|
34
|
-
f"{ok(task_input, 'Neither `task_input` and `dump_path` is provided.').briefing}\n\nExtract a single path of the file, to which I will dump the data."
|
35
|
-
),
|
36
|
-
"Could not find the path of file to dump the data.",
|
37
|
-
)
|
38
|
-
)
|
39
|
-
logger.info(f"Saving output to {dump_path.as_posix()}")
|
40
|
-
ok(to_dump, "Could not dump the data since the path is not specified.").finalized_dump_to(dump_path)
|
41
|
-
return dump_path.as_posix()
|
42
|
-
|
43
|
-
|
44
|
-
class RenderedDump(Action, LLMUsage):
|
45
|
-
"""Render the data to a file."""
|
46
|
-
|
47
|
-
output_key: str = "dump_path"
|
48
|
-
dump_path: Optional[str] = None
|
49
|
-
|
50
|
-
template_name: str
|
51
|
-
"""The template name to render the data."""
|
52
|
-
|
53
|
-
async def _execute(
|
54
|
-
self,
|
55
|
-
to_dump: FinalizedDumpAble,
|
56
|
-
task_input: Optional[Task] = None,
|
57
|
-
dump_path: Optional[str | Path] = None,
|
58
|
-
**_,
|
59
|
-
) -> str:
|
60
|
-
dump_path = Path(
|
61
|
-
dump_path
|
62
|
-
or self.dump_path
|
63
|
-
or ok(
|
64
|
-
await self.awhich_pathstr(
|
65
|
-
f"{ok(task_input, 'Neither `task_input` and `dump_path` is provided.').briefing}\n\nExtract a single path of the file, to which I will dump the data."
|
66
|
-
),
|
67
|
-
"Could not find the path of file to dump the data.",
|
68
|
-
)
|
69
|
-
)
|
70
|
-
|
71
|
-
logger.info(f"Saving output to {dump_path.as_posix()}")
|
72
|
-
dump_text(
|
73
|
-
dump_path,
|
74
|
-
TEMPLATE_MANAGER.render_template(
|
75
|
-
self.template_name, {to_dump.__class__.__name__: to_dump.finalized_dump()}
|
76
|
-
),
|
77
|
-
)
|
78
|
-
|
79
|
-
return dump_path.as_posix()
|
80
|
-
|
81
|
-
|
82
|
-
class PersistentAll(Action, LLMUsage):
|
83
|
-
"""Persist all the data to a file."""
|
84
|
-
|
85
|
-
output_key: str = "persistent_count"
|
86
|
-
"""The number of objects persisted."""
|
87
|
-
persist_dir: Optional[str] = None
|
88
|
-
"""The directory to persist the data."""
|
89
|
-
override: bool = False
|
90
|
-
"""Whether to remove the existing dir before dumping."""
|
91
|
-
|
92
|
-
async def _execute(
|
93
|
-
self,
|
94
|
-
task_input: Optional[Task] = None,
|
95
|
-
persist_dir: Optional[str | Path] = None,
|
96
|
-
**cxt,
|
97
|
-
) -> int:
|
98
|
-
persist_dir = Path(
|
99
|
-
persist_dir
|
100
|
-
or self.persist_dir
|
101
|
-
or ok(
|
102
|
-
await self.awhich_pathstr(
|
103
|
-
f"{ok(task_input, 'Neither `task_input` and `dump_path` is provided.').briefing}\n\nExtract a single path of the file, to which I will persist the data."
|
104
|
-
),
|
105
|
-
"Can not find the path of file to persist the data.",
|
106
|
-
)
|
107
|
-
)
|
108
|
-
|
109
|
-
count = 0
|
110
|
-
if persist_dir.is_file():
|
111
|
-
logger.warning("Dump should be a directory, but it is a file. Skip dumping.")
|
112
|
-
return count
|
113
|
-
if self.override and persist_dir.is_dir():
|
114
|
-
logger.info(f"Override the existing directory {persist_dir.as_posix()}.")
|
115
|
-
persist_dir.rmdir()
|
116
|
-
logger.info(f"Starting persistence in directory {persist_dir}")
|
117
|
-
for k, v in cxt.items():
|
118
|
-
final_dir = persist_dir.joinpath(k)
|
119
|
-
logger.debug(f"Checking key {k} for persistence")
|
120
|
-
if isinstance(v, PersistentAble):
|
121
|
-
logger.info(f"Persisting object {k} to {final_dir}")
|
122
|
-
final_dir.mkdir(parents=True, exist_ok=True)
|
123
|
-
v.persist(final_dir)
|
124
|
-
count += 1
|
125
|
-
if isinstance(v, Iterable) and any(
|
126
|
-
persistent_ables := (pers for pers in v if isinstance(pers, PersistentAble))
|
127
|
-
):
|
128
|
-
logger.info(f"Persisting collection {k} to {final_dir}")
|
129
|
-
final_dir.mkdir(parents=True, exist_ok=True)
|
130
|
-
for per in persistent_ables:
|
131
|
-
per.persist(final_dir)
|
132
|
-
count += 1
|
133
|
-
logger.info(f"Persisted {count} objects to {persist_dir}")
|
134
|
-
return count
|
135
|
-
|
136
|
-
|
137
|
-
class RetrieveFromPersistent[T: PersistentAble](Action):
|
138
|
-
"""Retrieve the object from the persistent file."""
|
139
|
-
|
140
|
-
output_key: str = "retrieved_obj"
|
141
|
-
"""Retrieve the object from the persistent file."""
|
142
|
-
load_path: str
|
143
|
-
"""The path of the persistent file or directory contains multiple file."""
|
144
|
-
retrieve_cls: Type[T]
|
145
|
-
"""The class of the object to retrieve."""
|
146
|
-
|
147
|
-
async def _execute(self, /, **_) -> Optional[T | List[T]]:
|
148
|
-
logger.info(f"Retrieve `{self.retrieve_cls.__name__}` from {self.load_path}")
|
149
|
-
if not (p := Path(self.load_path)).exists():
|
150
|
-
logger.warning(f"Path {self.load_path} does not exist")
|
151
|
-
return None
|
152
|
-
|
153
|
-
if p.is_dir():
|
154
|
-
logger.info(f"Found directory with {len(list(p.glob('*')))} items")
|
155
|
-
return [self.retrieve_cls.from_persistent(per) for per in p.glob("*")]
|
156
|
-
return self.retrieve_cls.from_persistent(self.load_path)
|
157
|
-
|
158
|
-
|
159
|
-
class RetrieveFromLatest[T: PersistentAble](RetrieveFromPersistent[T], FromMapping):
|
160
|
-
"""Retrieve the object from the latest persistent file in the dir at `load_path`."""
|
161
|
-
|
162
|
-
async def _execute(self, /, **_) -> Optional[T]:
|
163
|
-
logger.info(f"Retrieve latest `{self.retrieve_cls.__name__}` from {self.load_path}")
|
164
|
-
if not (p := Path(self.load_path)).exists():
|
165
|
-
logger.warning(f"Path {self.load_path} does not exist")
|
166
|
-
return None
|
167
|
-
|
168
|
-
if p.is_dir():
|
169
|
-
logger.info(f"Found directory with {len(list(p.glob('*')))} items")
|
170
|
-
return self.retrieve_cls.from_latest_persistent(self.load_path)
|
171
|
-
logger.error(f"Path {self.load_path} is not a directory")
|
172
|
-
return None
|
173
|
-
|
174
|
-
@classmethod
|
175
|
-
def from_mapping(
|
176
|
-
cls,
|
177
|
-
mapping: Mapping[str, str | Path],
|
178
|
-
*,
|
179
|
-
retrieve_cls: Type[T],
|
180
|
-
**kwargs,
|
181
|
-
) -> List["RetrieveFromLatest[T]"]:
|
182
|
-
"""Create a list of `RetrieveFromLatest` from the mapping."""
|
183
|
-
return [
|
184
|
-
cls(retrieve_cls=retrieve_cls, load_path=Path(p).as_posix(), output_key=o, **kwargs)
|
185
|
-
for o, p in mapping.items()
|
186
|
-
]
|
187
|
-
|
188
|
-
|
189
|
-
class GatherAsList(Action):
|
190
|
-
"""Gather the objects from the context as a list.
|
191
|
-
|
192
|
-
Notes:
|
193
|
-
If both `gather_suffix` and `gather_prefix` are specified, only the objects with the suffix will be gathered.
|
194
|
-
"""
|
195
|
-
|
196
|
-
output_key: str = "gathered"
|
197
|
-
"""Gather the objects from the context as a list."""
|
198
|
-
gather_suffix: Optional[str] = None
|
199
|
-
"""Gather the objects from the context as a list."""
|
200
|
-
gather_prefix: Optional[str] = None
|
201
|
-
"""Gather the objects from the context as a list."""
|
202
|
-
|
203
|
-
async def _execute(self, **cxt) -> List[Any]:
|
204
|
-
if self.gather_suffix is not None:
|
205
|
-
result = [cxt[k] for k in cxt if k.endswith(self.gather_suffix)]
|
206
|
-
logger.debug(f"Gathered {len(result)} items with suffix {self.gather_suffix}")
|
207
|
-
return result
|
208
|
-
if self.gather_prefix is None:
|
209
|
-
logger.error(err := "Either `gather_suffix` or `gather_prefix` must be specified.")
|
210
|
-
raise ValueError(err)
|
211
|
-
result = [cxt[k] for k in cxt if k.startswith(self.gather_prefix)]
|
212
|
-
logger.debug(f"Gathered {len(result)} items with prefix {self.gather_prefix}")
|
213
|
-
return result
|
214
|
-
|
215
|
-
|
216
|
-
class Forward(Action, FromMapping, FromSequence):
|
217
|
-
"""Forward the object from the context to the output."""
|
218
|
-
|
219
|
-
output_key: str = "forwarded"
|
220
|
-
"""Gather the objects from the context as a list."""
|
221
|
-
original: str
|
222
|
-
|
223
|
-
async def _execute(self, *_: Any, **cxt) -> Any:
|
224
|
-
source = cxt.get(self.original)
|
225
|
-
if source is None:
|
226
|
-
logger.warning(f"Original object {self.original} not found in the context")
|
227
|
-
return source
|
228
|
-
|
229
|
-
@classmethod
|
230
|
-
def from_sequence(cls, sequence: Sequence[str], *, original: str, **kwargs: Any) -> List[Self]:
|
231
|
-
"""Create a list of `Forward` from the sequence."""
|
232
|
-
return [cls(original=original, output_key=o, **kwargs) for o in sequence]
|
233
|
-
|
234
|
-
@classmethod
|
235
|
-
def from_mapping(cls, mapping: Mapping[str, str | Sequence[str]], **kwargs: Any) -> List[Self]:
|
236
|
-
"""Create a list of `Forward` from the mapping."""
|
237
|
-
actions = []
|
238
|
-
for original_key, output_val in mapping.items():
|
239
|
-
if isinstance(output_val, str):
|
240
|
-
actions.append(cls(original=original_key, output_key=output_val, **kwargs))
|
241
|
-
elif isinstance(output_val, Sequence):
|
242
|
-
actions.extend(cls(original=original_key, output_key=output_key, **kwargs) for output_key in output_val)
|
243
|
-
else:
|
244
|
-
logger.warning(
|
245
|
-
f"Invalid type for output key value in mapping: {type(output_val)} for original key {original_key}. Expected str or Sequence[str]."
|
246
|
-
)
|
247
|
-
return actions
|
fabricatio/actions/rag.py
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
"""Inject data into the database."""
|
2
|
-
|
3
|
-
from typing import List, Optional
|
4
|
-
|
5
|
-
from fabricatio.capabilities.rag import RAG
|
6
|
-
from fabricatio.journal import logger
|
7
|
-
from fabricatio.models.action import Action
|
8
|
-
from fabricatio.models.extra.rag import MilvusClassicModel, MilvusDataBase
|
9
|
-
from fabricatio.models.task import Task
|
10
|
-
from fabricatio.rust import CONFIG
|
11
|
-
from fabricatio.utils import ok
|
12
|
-
|
13
|
-
|
14
|
-
class InjectToDB(Action, RAG):
|
15
|
-
"""Inject data into the database."""
|
16
|
-
|
17
|
-
output_key: str = "collection_name"
|
18
|
-
collection_name: str = "my_collection"
|
19
|
-
"""The name of the collection to inject data into."""
|
20
|
-
|
21
|
-
async def _execute[T: MilvusDataBase](
|
22
|
-
self, to_inject: Optional[T] | List[Optional[T]], override_inject: bool = False, **_
|
23
|
-
) -> Optional[str]:
|
24
|
-
from pymilvus.milvus_client import IndexParams
|
25
|
-
|
26
|
-
if to_inject is None:
|
27
|
-
return None
|
28
|
-
if not isinstance(to_inject, list):
|
29
|
-
to_inject = [to_inject]
|
30
|
-
if not (seq := [t for t in to_inject if t is not None]): # filter out None
|
31
|
-
return None
|
32
|
-
logger.info(f"Injecting {len(seq)} items into the collection '{self.collection_name}'")
|
33
|
-
if override_inject:
|
34
|
-
self.check_client().client.drop_collection(self.collection_name)
|
35
|
-
|
36
|
-
await self.view(
|
37
|
-
self.collection_name,
|
38
|
-
create=True,
|
39
|
-
schema=seq[0].as_milvus_schema(
|
40
|
-
ok(
|
41
|
-
self.milvus_dimensions
|
42
|
-
or CONFIG.rag.milvus_dimensions
|
43
|
-
or self.embedding_dimensions
|
44
|
-
or CONFIG.embedding.dimensions
|
45
|
-
),
|
46
|
-
),
|
47
|
-
index_params=IndexParams(
|
48
|
-
seq[0].vector_field_name,
|
49
|
-
index_name=seq[0].vector_field_name,
|
50
|
-
index_type=seq[0].index_type,
|
51
|
-
metric_type=seq[0].metric_type,
|
52
|
-
),
|
53
|
-
).add_document(seq, flush=True)
|
54
|
-
|
55
|
-
return self.collection_name
|
56
|
-
|
57
|
-
|
58
|
-
class RAGTalk(Action, RAG):
|
59
|
-
"""RAG-enabled conversational action that processes user questions based on a given task.
|
60
|
-
|
61
|
-
This action establishes an interactive conversation loop where it retrieves context-relevant
|
62
|
-
information to answer user queries according to the assigned task briefing.
|
63
|
-
|
64
|
-
Notes:
|
65
|
-
task_input: Task briefing that guides how to respond to user questions
|
66
|
-
collection_name: Name of the vector collection to use for retrieval (default: "my_collection")
|
67
|
-
|
68
|
-
Returns:
|
69
|
-
Number of conversation turns completed before termination
|
70
|
-
"""
|
71
|
-
|
72
|
-
output_key: str = "task_output"
|
73
|
-
|
74
|
-
async def _execute(self, task_input: Task[str], **kwargs) -> int:
|
75
|
-
from questionary import text
|
76
|
-
|
77
|
-
collection_name = kwargs.get("collection_name", "my_collection")
|
78
|
-
counter = 0
|
79
|
-
|
80
|
-
self.view(collection_name, create=True)
|
81
|
-
|
82
|
-
try:
|
83
|
-
while True:
|
84
|
-
user_say = await text("User: ").ask_async()
|
85
|
-
if user_say is None:
|
86
|
-
break
|
87
|
-
ret: List[MilvusClassicModel] = await self.aretrieve(user_say, document_model=MilvusClassicModel)
|
88
|
-
|
89
|
-
gpt_say = await self.aask(
|
90
|
-
user_say, system_message="\n".join(m.text for m in ret) + "\nYou can refer facts provided above."
|
91
|
-
)
|
92
|
-
print(f"GPT: {gpt_say}") # noqa: T201
|
93
|
-
counter += 1
|
94
|
-
except KeyboardInterrupt:
|
95
|
-
logger.info(f"executed talk action {counter} times")
|
96
|
-
return counter
|
fabricatio/actions/rules.py
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
"""A module containing the DraftRuleSet action."""
|
2
|
-
|
3
|
-
from typing import Any, List, Mapping, Optional, Self, Tuple
|
4
|
-
|
5
|
-
from fabricatio.capabilities.check import Check
|
6
|
-
from fabricatio.journal import logger
|
7
|
-
from fabricatio.models.action import Action
|
8
|
-
from fabricatio.models.extra.rule import RuleSet
|
9
|
-
from fabricatio.models.generic import FromMapping
|
10
|
-
from fabricatio.utils import ok
|
11
|
-
|
12
|
-
|
13
|
-
class DraftRuleSet(Action, Check, FromMapping):
|
14
|
-
"""Action to draft a ruleset based on a given requirement description."""
|
15
|
-
|
16
|
-
output_key: str = "drafted_ruleset"
|
17
|
-
"""The key used to store the drafted ruleset in the context dictionary."""
|
18
|
-
|
19
|
-
ruleset_requirement: Optional[str] = None
|
20
|
-
"""The natural language description of the desired ruleset characteristics."""
|
21
|
-
rule_count: int = 0
|
22
|
-
"""The number of rules to generate in the ruleset (0 for no restriction)."""
|
23
|
-
|
24
|
-
async def _execute(
|
25
|
-
self,
|
26
|
-
ruleset_requirement: Optional[str] = None,
|
27
|
-
**_,
|
28
|
-
) -> Optional[RuleSet]:
|
29
|
-
"""Draft a ruleset based on the requirement description.
|
30
|
-
|
31
|
-
Args:
|
32
|
-
ruleset_requirement (str): Natural language description of desired ruleset characteristics
|
33
|
-
rule_count (int): Number of rules to generate (0 for no restriction)
|
34
|
-
**kwargs: Validation parameters for rule generation
|
35
|
-
|
36
|
-
Returns:
|
37
|
-
Optional[RuleSet]: Drafted ruleset object or None if generation fails
|
38
|
-
"""
|
39
|
-
ruleset = await self.draft_ruleset(
|
40
|
-
ruleset_requirement=ok(ruleset_requirement or self.ruleset_requirement, "No ruleset requirement provided"),
|
41
|
-
rule_count=self.rule_count,
|
42
|
-
)
|
43
|
-
if ruleset:
|
44
|
-
logger.info(f"Drafted Ruleset length: {len(ruleset.rules)}\n{ruleset.display()}")
|
45
|
-
else:
|
46
|
-
logger.warning(f"Drafting Rule Failed for:\n{ruleset_requirement}")
|
47
|
-
return ruleset
|
48
|
-
|
49
|
-
@classmethod
|
50
|
-
def from_mapping(cls, mapping: Mapping[str, Tuple[int, str]], **kwargs) -> List[Self]:
|
51
|
-
"""Create a list of DraftRuleSet actions from a mapping of output keys to tuples of rule counts and requirements."""
|
52
|
-
return [cls(ruleset_requirement=r, rule_count=c, output_key=k, **kwargs) for k, (c, r) in mapping.items()]
|
53
|
-
|
54
|
-
|
55
|
-
class GatherRuleset(Action, FromMapping):
|
56
|
-
"""Action to gather a ruleset from a given requirement description."""
|
57
|
-
|
58
|
-
output_key: str = "gathered_ruleset"
|
59
|
-
"""The key used to store the drafted ruleset in the context dictionary."""
|
60
|
-
|
61
|
-
to_gather: List[str]
|
62
|
-
"""the cxt name of RuleSet to gather"""
|
63
|
-
|
64
|
-
@classmethod
|
65
|
-
def from_mapping(cls, mapping: Mapping[str, List[str]], **kwargs: Any) -> List[Self]:
|
66
|
-
"""Create a list of GatherRuleset actions from a mapping of output keys to tuples of rule counts and requirements."""
|
67
|
-
return [cls(to_gather=t, output_key=k, **kwargs) for k, t in mapping.items()]
|
68
|
-
|
69
|
-
async def _execute(self, **cxt) -> RuleSet:
|
70
|
-
logger.info(f"Gathering Ruleset from {self.to_gather}")
|
71
|
-
# Fix for not_found
|
72
|
-
not_found = next((t for t in self.to_gather if t not in cxt), None)
|
73
|
-
if not_found:
|
74
|
-
raise ValueError(
|
75
|
-
f"Not all required keys found in context: {self.to_gather}|`{not_found}` not found in context."
|
76
|
-
)
|
77
|
-
|
78
|
-
# Fix for invalid RuleSet check
|
79
|
-
invalid = next((t for t in self.to_gather if not isinstance(cxt[t], RuleSet)), None)
|
80
|
-
if invalid is not None:
|
81
|
-
raise TypeError(f"Invalid RuleSet instance for key `{invalid}`")
|
82
|
-
|
83
|
-
return RuleSet.gather(*[cxt[t] for t in self.to_gather])
|
@@ -1,18 +0,0 @@
|
|
1
|
-
fabricatio-0.4.0.data/scripts/tdown.exe,sha256=wJB4uqkaC7lj5SdJTbsBoa6Cz-Bl_WC-jnZeabGwfic,3378176
|
2
|
-
fabricatio-0.4.0.dist-info/METADATA,sha256=f0SYcL4jgeWa4X3giEG6zJZ6qXActgZQ0ynZuJXO2ds,5189
|
3
|
-
fabricatio-0.4.0.dist-info/WHEEL,sha256=Fk195VgSS-LCRRJAxz6O39eu2NdDhBCq3h9q4zoTguY,96
|
4
|
-
fabricatio-0.4.0.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
|
5
|
-
fabricatio/__init__.py,sha256=9YbjjPgR_-rvuXt86oNLXZodDm3zltnMNmhP-1pESvE,786
|
6
|
-
fabricatio/actions/__init__.py,sha256=wVENCFtpVb1rLFxoOFJt9-8smLWXuJV7IwA8P3EfFz4,48
|
7
|
-
fabricatio/actions/fs.py,sha256=gJR14U4ln35nt8Z7OWLVAZpqGaLnED-r1Yi-lX22tkI,959
|
8
|
-
fabricatio/actions/output.py,sha256=nYKCUkNyAVziJmKS_Hdxnb015CrHRFdLJuQJlkEyB1s,9971
|
9
|
-
fabricatio/actions/rag.py,sha256=vgCzIfbSd3_vL3QxB12PY4h12V9Pe3sZRsWme0KC6X8,3583
|
10
|
-
fabricatio/actions/rules.py,sha256=07ILsiwR250AUcKLPHTUPpWD_mPhPCfWKSkEAKcPv3A,3557
|
11
|
-
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
fabricatio/rust.cp313-win_amd64.pyd,sha256=L-c7Su6i5T4fqbGfJU8pqQW5Vx4kaDM1gvidnlFmp9g,176128
|
13
|
-
fabricatio/toolboxes/__init__.py,sha256=KBJi5OG_pExscdlM7Bnt_UF43j4I3Lv6G71kPVu4KQU,395
|
14
|
-
fabricatio/toolboxes/arithmetic.py,sha256=WLqhY-Pikv11Y_0SGajwZx3WhsLNpHKf9drzAqOf_nY,1369
|
15
|
-
fabricatio/toolboxes/fs.py,sha256=l4L1CVxJmjw9Ld2XUpIlWfV0_Fu_2Og6d3E13I-S4aE,736
|
16
|
-
fabricatio/workflows/__init__.py,sha256=5ScFSTA-bvhCesj3U9Mnmi6Law6N1fmh5UKyh58L3u8,51
|
17
|
-
fabricatio/workflows/rag.py,sha256=O8qCLhZTJTEj72R7W6Nq3WFg2I42arzQJkIGaeDdpss,527
|
18
|
-
fabricatio-0.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|