fabricatio 0.2.0.dev14__cp312-cp312-win_amd64.whl → 0.2.0.dev18__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/_rust.cp312-win_amd64.pyd +0 -0
- fabricatio/_rust.pyi +11 -11
- fabricatio/_rust_instances.py +1 -1
- fabricatio/actions/communication.py +2 -0
- fabricatio/actions/transmission.py +2 -0
- fabricatio/config.py +40 -14
- fabricatio/decorators.py +44 -7
- fabricatio/fs/curd.py +110 -0
- fabricatio/fs/readers.py +2 -0
- fabricatio/models/action.py +5 -4
- fabricatio/models/advanced.py +119 -0
- fabricatio/models/events.py +4 -2
- fabricatio/models/generic.py +1 -421
- fabricatio/models/kwargs_types.py +26 -0
- fabricatio/models/role.py +3 -2
- fabricatio/models/task.py +2 -29
- fabricatio/models/tool.py +65 -49
- fabricatio/models/usages.py +456 -0
- fabricatio/parser.py +1 -1
- fabricatio/toolboxes/fs.py +14 -0
- fabricatio/toolboxes/task.py +2 -0
- {fabricatio-0.2.0.dev14.data → fabricatio-0.2.0.dev18.data}/scripts/tdown.exe +0 -0
- {fabricatio-0.2.0.dev14.dist-info → fabricatio-0.2.0.dev18.dist-info}/METADATA +6 -1
- fabricatio-0.2.0.dev18.dist-info/RECORD +35 -0
- fabricatio-0.2.0.dev14.dist-info/RECORD +0 -30
- {fabricatio-0.2.0.dev14.dist-info → fabricatio-0.2.0.dev18.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.0.dev14.dist-info → fabricatio-0.2.0.dev18.dist-info}/licenses/LICENSE +0 -0
Binary file
|
fabricatio/_rust.pyi
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
from pathlib import Path
|
2
|
-
from typing import Dict, List,
|
3
|
-
|
2
|
+
from typing import Any, Dict, List, Optional
|
4
3
|
|
5
4
|
class TemplateManager:
|
6
|
-
def __init__(self, template_dirs: List[Path]) -> None:
|
7
|
-
"""
|
8
|
-
|
5
|
+
def __init__(self, template_dirs: List[Path], suffix: Optional[str] = None) -> None:
|
6
|
+
"""Initialize the template manager.
|
7
|
+
|
9
8
|
Args:
|
10
9
|
template_dirs (List[Path]): A list of paths to directories containing templates.
|
10
|
+
suffix (str, optional): The suffix of template files. None means 'hbs' suffix .
|
11
11
|
"""
|
12
12
|
|
13
13
|
@property
|
@@ -19,8 +19,8 @@ class TemplateManager:
|
|
19
19
|
"""Get a list of template names."""
|
20
20
|
|
21
21
|
def get_template(self, name: str) -> str:
|
22
|
-
"""
|
23
|
-
|
22
|
+
"""Get a template by name.
|
23
|
+
|
24
24
|
Args:
|
25
25
|
name (str): The name of the template to retrieve.
|
26
26
|
|
@@ -29,8 +29,8 @@ class TemplateManager:
|
|
29
29
|
"""
|
30
30
|
|
31
31
|
def get_template_source(self, name: str) -> str:
|
32
|
-
"""
|
33
|
-
|
32
|
+
"""Get the source path of a template by name.
|
33
|
+
|
34
34
|
Args:
|
35
35
|
name (str): The name of the template to retrieve.
|
36
36
|
|
@@ -42,8 +42,8 @@ class TemplateManager:
|
|
42
42
|
"""Discover templates in the specified directories."""
|
43
43
|
|
44
44
|
def render_template(self, name: str, data: Dict[str, Any]) -> str:
|
45
|
-
"""
|
46
|
-
|
45
|
+
"""Render a template with the given name and data.
|
46
|
+
|
47
47
|
Args:
|
48
48
|
name (str): The name of the template to render.
|
49
49
|
data (Dict[str, Any]): The data to pass to the template.
|
fabricatio/_rust_instances.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
from fabricatio._rust import TemplateManager
|
2
2
|
from fabricatio.config import configs
|
3
3
|
|
4
|
-
template_manager = TemplateManager(configs.
|
4
|
+
template_manager = TemplateManager(template_dirs=configs.templates.template_dir, suffix=configs.templates.template_suffix)
|
fabricatio/config.py
CHANGED
@@ -116,17 +116,17 @@ class DebugConfig(BaseModel):
|
|
116
116
|
"""The log file of the application."""
|
117
117
|
|
118
118
|
|
119
|
-
class
|
120
|
-
"""
|
119
|
+
class TemplateConfig(BaseModel):
|
120
|
+
"""Template configuration class."""
|
121
121
|
|
122
122
|
model_config = ConfigDict(use_attribute_docstrings=True)
|
123
123
|
template_dir: List[DirectoryPath] = Field(
|
124
124
|
default_factory=lambda: [DirectoryPath(r".\templates"), DirectoryPath(rf"{ROAMING_DIR}\templates")]
|
125
125
|
)
|
126
|
-
"""The directory containing the templates
|
126
|
+
"""The directory containing the templates."""
|
127
127
|
|
128
|
-
template_suffix: str = Field(default="
|
129
|
-
"""The suffix of the
|
128
|
+
template_suffix: str = Field(default="hbs", frozen=True)
|
129
|
+
"""The suffix of the templates."""
|
130
130
|
|
131
131
|
|
132
132
|
class MagikaConfig(BaseModel):
|
@@ -137,6 +137,26 @@ class MagikaConfig(BaseModel):
|
|
137
137
|
"""The directory containing the models for magika."""
|
138
138
|
|
139
139
|
|
140
|
+
class GeneralConfig(BaseModel):
|
141
|
+
"""Global configuration class."""
|
142
|
+
|
143
|
+
model_config = ConfigDict(use_attribute_docstrings=True)
|
144
|
+
workspace: DirectoryPath = Field(default=DirectoryPath(r"."))
|
145
|
+
"""The workspace directory for the application."""
|
146
|
+
|
147
|
+
confirm_on_fs_ops: bool = Field(default=True)
|
148
|
+
"""Whether to confirm on file system operations."""
|
149
|
+
|
150
|
+
|
151
|
+
class ToolBoxConfig(BaseModel):
|
152
|
+
"""Toolbox configuration class."""
|
153
|
+
|
154
|
+
model_config = ConfigDict(use_attribute_docstrings=True)
|
155
|
+
|
156
|
+
tool_module_name: str = Field(default="Toolbox")
|
157
|
+
"""The name of the module containing the toolbox."""
|
158
|
+
|
159
|
+
|
140
160
|
class Settings(BaseSettings):
|
141
161
|
"""Application settings class.
|
142
162
|
|
@@ -144,7 +164,7 @@ class Settings(BaseSettings):
|
|
144
164
|
llm (LLMConfig): LLM Configuration
|
145
165
|
debug (DebugConfig): Debug Configuration
|
146
166
|
pymitter (PymitterConfig): Pymitter Configuration
|
147
|
-
|
167
|
+
templates (TemplateConfig): Template Configuration
|
148
168
|
magika (MagikaConfig): Magika Configuration
|
149
169
|
"""
|
150
170
|
|
@@ -167,20 +187,26 @@ class Settings(BaseSettings):
|
|
167
187
|
pymitter: PymitterConfig = Field(default_factory=PymitterConfig)
|
168
188
|
"""Pymitter Configuration"""
|
169
189
|
|
170
|
-
|
171
|
-
"""
|
190
|
+
templates: TemplateConfig = Field(default_factory=TemplateConfig)
|
191
|
+
"""Template Configuration"""
|
172
192
|
|
173
193
|
magika: MagikaConfig = Field(default_factory=MagikaConfig)
|
174
194
|
"""Magika Configuration"""
|
175
195
|
|
196
|
+
general: GeneralConfig = Field(default_factory=GeneralConfig)
|
197
|
+
"""General Configuration"""
|
198
|
+
|
199
|
+
toolbox: ToolBoxConfig = Field(default_factory=ToolBoxConfig)
|
200
|
+
"""Toolbox Configuration"""
|
201
|
+
|
176
202
|
@classmethod
|
177
203
|
def settings_customise_sources(
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
204
|
+
cls,
|
205
|
+
settings_cls: type[BaseSettings],
|
206
|
+
init_settings: PydanticBaseSettingsSource,
|
207
|
+
env_settings: PydanticBaseSettingsSource,
|
208
|
+
dotenv_settings: PydanticBaseSettingsSource,
|
209
|
+
file_secret_settings: PydanticBaseSettingsSource,
|
184
210
|
) -> tuple[PydanticBaseSettingsSource, ...]:
|
185
211
|
"""Customize settings sources.
|
186
212
|
|
fabricatio/decorators.py
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
+
"""Decorators for Fabricatio."""
|
2
|
+
|
1
3
|
from functools import wraps
|
4
|
+
from inspect import signature
|
2
5
|
from shutil import which
|
3
|
-
from typing import Callable
|
6
|
+
from typing import Callable, Optional
|
7
|
+
|
8
|
+
from questionary import confirm
|
4
9
|
|
10
|
+
from fabricatio.config import configs
|
5
11
|
from fabricatio.journal import logger
|
6
12
|
|
7
13
|
|
8
|
-
def depend_on_external_cmd[**P, R](
|
14
|
+
def depend_on_external_cmd[**P, R](
|
15
|
+
bin_name: str, install_tip: Optional[str], homepage: Optional[str] = None
|
16
|
+
) -> Callable[[Callable[P, R]], Callable[P, R]]:
|
9
17
|
"""Decorator to check for the presence of an external command.
|
10
18
|
|
11
19
|
Args:
|
12
20
|
bin_name (str): The name of the required binary.
|
13
|
-
install_tip (str): Installation instructions for the required binary.
|
21
|
+
install_tip (Optional[str]): Installation instructions for the required binary.
|
22
|
+
homepage (Optional[str]): The homepage of the required binary.
|
14
23
|
|
15
24
|
Returns:
|
16
25
|
Callable[[Callable[P, R]], Callable[P, R]]: A decorator that wraps the function to check for the binary.
|
@@ -23,13 +32,41 @@ def depend_on_external_cmd[**P, R](bin_name: str, install_tip: str) -> Callable[
|
|
23
32
|
@wraps(func)
|
24
33
|
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
25
34
|
if which(bin_name) is None:
|
26
|
-
err = (
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
err = f"`{bin_name}` is required to run {func.__name__}{signature(func)}, please install it the to `PATH` first."
|
36
|
+
if install_tip is not None:
|
37
|
+
err += f"\nInstall tip: {install_tip}"
|
38
|
+
if homepage is not None:
|
39
|
+
err += f"\nHomepage: {homepage}"
|
40
|
+
logger.error(err)
|
30
41
|
raise RuntimeError(err)
|
31
42
|
return func(*args, **kwargs)
|
32
43
|
|
33
44
|
return _wrapper
|
34
45
|
|
35
46
|
return _decorator
|
47
|
+
|
48
|
+
|
49
|
+
def confirm_to_execute[**P, R](func: Callable[P, R]) -> Callable[P, Optional[R]] | Callable[P, R]:
|
50
|
+
"""Decorator to confirm before executing a function.
|
51
|
+
|
52
|
+
Args:
|
53
|
+
func (Callable): The function to be executed
|
54
|
+
|
55
|
+
Returns:
|
56
|
+
Callable: A decorator that wraps the function to confirm before execution.
|
57
|
+
"""
|
58
|
+
if not configs.general.confirm_on_fs_ops:
|
59
|
+
# Skip confirmation if the configuration is set to False
|
60
|
+
return func
|
61
|
+
|
62
|
+
@wraps(func)
|
63
|
+
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
|
64
|
+
if confirm(
|
65
|
+
f"Are you sure to execute function: {func.__name__}{signature(func)} \n📦 Args:{args}\n🔑 Kwargs:{kwargs}\n",
|
66
|
+
instruction="Please input [Yes/No] to proceed (default: Yes):",
|
67
|
+
).ask():
|
68
|
+
return func(*args, **kwargs)
|
69
|
+
logger.warning(f"Function: {func.__name__}{signature(func)} canceled by user.")
|
70
|
+
return None
|
71
|
+
|
72
|
+
return _wrapper
|
fabricatio/fs/curd.py
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
"""File system create, update, read, delete operations."""
|
2
|
+
|
3
|
+
import shutil
|
4
|
+
import subprocess
|
5
|
+
from pathlib import Path
|
6
|
+
from typing import Union
|
7
|
+
|
8
|
+
from fabricatio.decorators import depend_on_external_cmd
|
9
|
+
from fabricatio.journal import logger
|
10
|
+
|
11
|
+
|
12
|
+
def copy_file(src: Union[str, Path], dst: Union[str, Path]) -> None:
|
13
|
+
"""Copy a file from source to destination.
|
14
|
+
|
15
|
+
Args:
|
16
|
+
src: Source file path
|
17
|
+
dst: Destination file path
|
18
|
+
|
19
|
+
Raises:
|
20
|
+
FileNotFoundError: If source file doesn't exist
|
21
|
+
shutil.SameFileError: If source and destination are the same
|
22
|
+
"""
|
23
|
+
try:
|
24
|
+
shutil.copy(src, dst)
|
25
|
+
logger.info(f"Copied file from {src} to {dst}")
|
26
|
+
except OSError as e:
|
27
|
+
logger.error(f"Failed to copy file from {src} to {dst}: {e!s}")
|
28
|
+
raise
|
29
|
+
|
30
|
+
|
31
|
+
def move_file(src: Union[str, Path], dst: Union[str, Path]) -> None:
|
32
|
+
"""Move a file from source to destination.
|
33
|
+
|
34
|
+
Args:
|
35
|
+
src: Source file path
|
36
|
+
dst: Destination file path
|
37
|
+
|
38
|
+
Raises:
|
39
|
+
FileNotFoundError: If source file doesn't exist
|
40
|
+
shutil.SameFileError: If source and destination are the same
|
41
|
+
"""
|
42
|
+
try:
|
43
|
+
shutil.move(src, dst)
|
44
|
+
logger.info(f"Moved file from {src} to {dst}")
|
45
|
+
except OSError as e:
|
46
|
+
logger.error(f"Failed to move file from {src} to {dst}: {e!s}")
|
47
|
+
raise
|
48
|
+
|
49
|
+
|
50
|
+
def delete_file(file_path: Union[str, Path]) -> None:
|
51
|
+
"""Delete a file.
|
52
|
+
|
53
|
+
Args:
|
54
|
+
file_path: Path to the file to be deleted
|
55
|
+
|
56
|
+
Raises:
|
57
|
+
FileNotFoundError: If file doesn't exist
|
58
|
+
PermissionError: If no permission to delete the file
|
59
|
+
"""
|
60
|
+
try:
|
61
|
+
Path(file_path).unlink()
|
62
|
+
logger.info(f"Deleted file: {file_path}")
|
63
|
+
except OSError as e:
|
64
|
+
logger.error(f"Failed to delete file {file_path}: {e!s}")
|
65
|
+
raise
|
66
|
+
|
67
|
+
|
68
|
+
def create_directory(dir_path: Union[str, Path], parents: bool = True, exist_ok: bool = True) -> None:
|
69
|
+
"""Create a directory.
|
70
|
+
|
71
|
+
Args:
|
72
|
+
dir_path: Path to the directory to create
|
73
|
+
parents: Create parent directories if they don't exist
|
74
|
+
exist_ok: Don't raise error if directory already exists
|
75
|
+
"""
|
76
|
+
try:
|
77
|
+
Path(dir_path).mkdir(parents=parents, exist_ok=exist_ok)
|
78
|
+
logger.info(f"Created directory: {dir_path}")
|
79
|
+
except OSError as e:
|
80
|
+
logger.error(f"Failed to create directory {dir_path}: {e!s}")
|
81
|
+
raise
|
82
|
+
|
83
|
+
|
84
|
+
@depend_on_external_cmd(
|
85
|
+
"erd",
|
86
|
+
"Please install `erd` using `cargo install erdtree` or `scoop install erdtree`.",
|
87
|
+
"https://github.com/solidiquis/erdtree",
|
88
|
+
)
|
89
|
+
def tree(dir_path: Union[str, Path]) -> str:
|
90
|
+
"""Generate a tree representation of the directory structure. Requires `erd` to be installed."""
|
91
|
+
dir_path = Path(dir_path)
|
92
|
+
return subprocess.check_output(("erd", dir_path.as_posix()), encoding="utf-8") # noqa: S603
|
93
|
+
|
94
|
+
|
95
|
+
def delete_directory(dir_path: Union[str, Path]) -> None:
|
96
|
+
"""Delete a directory and its contents.
|
97
|
+
|
98
|
+
Args:
|
99
|
+
dir_path: Path to the directory to delete
|
100
|
+
|
101
|
+
Raises:
|
102
|
+
FileNotFoundError: If directory doesn't exist
|
103
|
+
OSError: If directory is not empty and can't be removed
|
104
|
+
"""
|
105
|
+
try:
|
106
|
+
shutil.rmtree(dir_path)
|
107
|
+
logger.info(f"Deleted directory: {dir_path}")
|
108
|
+
except OSError as e:
|
109
|
+
logger.error(f"Failed to delete directory {dir_path}: {e!s}")
|
110
|
+
raise
|
fabricatio/fs/readers.py
CHANGED
fabricatio/models/action.py
CHANGED
@@ -6,9 +6,10 @@ from asyncio import Queue
|
|
6
6
|
from typing import Any, Dict, Self, Tuple, Type, Unpack
|
7
7
|
|
8
8
|
from fabricatio.journal import logger
|
9
|
-
from fabricatio.models.
|
10
|
-
from fabricatio.models.
|
11
|
-
from fabricatio.models.
|
9
|
+
from fabricatio.models.advanced import ProposeTask
|
10
|
+
from fabricatio.models.generic import WithBriefing
|
11
|
+
from fabricatio.models.task import Task
|
12
|
+
from fabricatio.models.usages import ToolBoxUsage
|
12
13
|
from pydantic import Field, PrivateAttr
|
13
14
|
|
14
15
|
|
@@ -51,7 +52,7 @@ class Action(ProposeTask, ToolBoxUsage):
|
|
51
52
|
return f"# The action you are going to perform: \n{super().briefing}"
|
52
53
|
|
53
54
|
|
54
|
-
class WorkFlow[A: Type[Action] | Action](WithBriefing,
|
55
|
+
class WorkFlow[A: Type[Action] | Action](WithBriefing, ToolBoxUsage):
|
55
56
|
"""Class that represents a workflow to be executed in a task."""
|
56
57
|
|
57
58
|
_context: Queue[Dict[str, Any]] = PrivateAttr(default_factory=lambda: Queue(maxsize=1))
|
@@ -0,0 +1,119 @@
|
|
1
|
+
"""A module for advanced models and functionalities."""
|
2
|
+
|
3
|
+
from types import CodeType
|
4
|
+
from typing import List, Optional, Tuple, Unpack
|
5
|
+
|
6
|
+
import orjson
|
7
|
+
from fabricatio._rust_instances import template_manager
|
8
|
+
from fabricatio.config import configs
|
9
|
+
from fabricatio.models.generic import WithBriefing
|
10
|
+
from fabricatio.models.kwargs_types import LLMKwargs
|
11
|
+
from fabricatio.models.task import Task
|
12
|
+
from fabricatio.models.tool import Tool, ToolExecutor
|
13
|
+
from fabricatio.models.usages import LLMUsage, ToolBoxUsage
|
14
|
+
from fabricatio.parser import JsonCapture, PythonCapture
|
15
|
+
from loguru import logger
|
16
|
+
from pydantic import PositiveInt, ValidationError
|
17
|
+
|
18
|
+
|
19
|
+
class ProposeTask(LLMUsage, WithBriefing):
|
20
|
+
"""A class that proposes a task based on a prompt."""
|
21
|
+
|
22
|
+
async def propose(
|
23
|
+
self,
|
24
|
+
prompt: str,
|
25
|
+
max_validations: PositiveInt = 2,
|
26
|
+
**kwargs: Unpack[LLMKwargs],
|
27
|
+
) -> Task:
|
28
|
+
"""Asynchronously proposes a task based on a given prompt and parameters.
|
29
|
+
|
30
|
+
Parameters:
|
31
|
+
prompt: The prompt text for proposing a task, which is a string that must be provided.
|
32
|
+
max_validations: The maximum number of validations allowed, default is 2.
|
33
|
+
**kwargs: The keyword arguments for the LLM (Large Language Model) usage.
|
34
|
+
|
35
|
+
Returns:
|
36
|
+
A Task object based on the proposal result.
|
37
|
+
"""
|
38
|
+
if not prompt:
|
39
|
+
err = f"{self.name}: Prompt must be provided."
|
40
|
+
logger.error(err)
|
41
|
+
raise ValueError(err)
|
42
|
+
|
43
|
+
def _validate_json(response: str) -> None | Task:
|
44
|
+
try:
|
45
|
+
cap = JsonCapture.capture(response)
|
46
|
+
logger.debug(f"Response: \n{response}")
|
47
|
+
logger.info(f"Captured JSON: \n{cap}")
|
48
|
+
return Task.model_validate_json(cap)
|
49
|
+
except ValidationError as e:
|
50
|
+
logger.error(f"Failed to parse task from JSON: {e}")
|
51
|
+
return None
|
52
|
+
|
53
|
+
template_data = {"prompt": prompt, "json_example": Task.json_example()}
|
54
|
+
return await self.aask_validate(
|
55
|
+
question=template_manager.render_template("propose_task", template_data),
|
56
|
+
validator=_validate_json,
|
57
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
58
|
+
max_validations=max_validations,
|
59
|
+
**kwargs,
|
60
|
+
)
|
61
|
+
|
62
|
+
|
63
|
+
class HandleTask(WithBriefing, ToolBoxUsage):
|
64
|
+
"""A class that handles a task based on a task object."""
|
65
|
+
|
66
|
+
async def draft_tool_usage_code(
|
67
|
+
self,
|
68
|
+
task: Task,
|
69
|
+
tools: List[Tool],
|
70
|
+
**kwargs: Unpack[LLMKwargs],
|
71
|
+
) -> Tuple[CodeType, List[str]]:
|
72
|
+
"""Asynchronously drafts the tool usage code for a task based on a given task object and tools."""
|
73
|
+
logger.info(f"Drafting tool usage code for task: {task.briefing}")
|
74
|
+
|
75
|
+
if not tools:
|
76
|
+
err = f"{self.name}: Tools must be provided to draft the tool usage code."
|
77
|
+
logger.error(err)
|
78
|
+
raise ValueError(err)
|
79
|
+
|
80
|
+
def _validator(response: str) -> Tuple[CodeType, List[str]] | None:
|
81
|
+
if (source := PythonCapture.convert_with(response, lambda resp: compile(resp, "<string>", "exec"))) and (
|
82
|
+
to_extract := JsonCapture.convert_with(response, orjson.loads)
|
83
|
+
):
|
84
|
+
return source, to_extract
|
85
|
+
return None
|
86
|
+
|
87
|
+
return await self.aask_validate(
|
88
|
+
question=template_manager.render_template(
|
89
|
+
"draft_tool_usage_code",
|
90
|
+
{
|
91
|
+
"tool_module_name": configs.toolbox.tool_module_name,
|
92
|
+
"task": task.briefing,
|
93
|
+
"tools": [tool.briefing for tool in tools],
|
94
|
+
},
|
95
|
+
),
|
96
|
+
validator=_validator,
|
97
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
98
|
+
**kwargs,
|
99
|
+
)
|
100
|
+
|
101
|
+
async def handle_fin_grind(
|
102
|
+
self,
|
103
|
+
task: Task,
|
104
|
+
**kwargs: Unpack[LLMKwargs],
|
105
|
+
) -> Optional[Tuple]:
|
106
|
+
"""Asynchronously handles a task based on a given task object and parameters."""
|
107
|
+
logger.info(f"Handling task: {task.briefing}")
|
108
|
+
|
109
|
+
tools = await self.gather_tools(task)
|
110
|
+
logger.info(f"{self.name} have gathered {len(tools)} tools gathered")
|
111
|
+
|
112
|
+
if tools:
|
113
|
+
executor = ToolExecutor(execute_sequence=tools)
|
114
|
+
code, to_extract = await self.draft_tool_usage_code(task, tools, **kwargs)
|
115
|
+
cxt = await executor.execute(code)
|
116
|
+
if to_extract:
|
117
|
+
return tuple(cxt.get(k) for k in to_extract)
|
118
|
+
|
119
|
+
return None
|
fabricatio/models/events.py
CHANGED
@@ -47,8 +47,10 @@ class Event(BaseModel):
|
|
47
47
|
|
48
48
|
def push(self, segment: str) -> Self:
|
49
49
|
"""Push a segment to the event."""
|
50
|
-
|
51
|
-
|
50
|
+
if not segment:
|
51
|
+
raise ValueError("The segment must not be empty.")
|
52
|
+
if configs.pymitter.delimiter in segment:
|
53
|
+
raise ValueError("The segment must not contain the delimiter.")
|
52
54
|
|
53
55
|
self.segments.append(segment)
|
54
56
|
return self
|