fabricatio 0.2.1.dev0__cp313-cp313-win_amd64.whl → 0.3.14.dev5__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 +12 -20
- fabricatio/actions/__init__.py +1 -5
- fabricatio/actions/article.py +319 -0
- fabricatio/actions/article_rag.py +416 -0
- fabricatio/actions/fs.py +25 -0
- fabricatio/actions/output.py +248 -0
- fabricatio/actions/rag.py +96 -0
- fabricatio/actions/rules.py +83 -0
- fabricatio/capabilities/__init__.py +1 -0
- fabricatio/capabilities/advanced_judge.py +20 -0
- fabricatio/capabilities/advanced_rag.py +61 -0
- fabricatio/capabilities/censor.py +105 -0
- fabricatio/capabilities/check.py +212 -0
- fabricatio/capabilities/correct.py +228 -0
- fabricatio/capabilities/extract.py +74 -0
- fabricatio/capabilities/persist.py +103 -0
- fabricatio/capabilities/propose.py +65 -0
- fabricatio/capabilities/rag.py +263 -0
- fabricatio/capabilities/rating.py +404 -0
- fabricatio/capabilities/review.py +114 -0
- fabricatio/capabilities/task.py +113 -0
- fabricatio/decorators.py +251 -179
- fabricatio/{core.py → emitter.py} +31 -21
- fabricatio/fs/__init__.py +32 -2
- fabricatio/fs/curd.py +32 -9
- fabricatio/fs/readers.py +44 -7
- fabricatio/journal.py +3 -19
- fabricatio/models/action.py +185 -61
- fabricatio/models/adv_kwargs_types.py +63 -0
- fabricatio/models/extra/__init__.py +1 -0
- fabricatio/models/extra/advanced_judge.py +32 -0
- fabricatio/models/extra/aricle_rag.py +284 -0
- fabricatio/models/extra/article_base.py +422 -0
- fabricatio/models/extra/article_essence.py +101 -0
- fabricatio/models/extra/article_main.py +284 -0
- fabricatio/models/extra/article_outline.py +46 -0
- fabricatio/models/extra/article_proposal.py +52 -0
- fabricatio/models/extra/patches.py +20 -0
- fabricatio/models/extra/problem.py +165 -0
- fabricatio/models/extra/rag.py +98 -0
- fabricatio/models/extra/rule.py +52 -0
- fabricatio/models/generic.py +704 -36
- fabricatio/models/kwargs_types.py +112 -17
- fabricatio/models/role.py +74 -27
- fabricatio/models/task.py +94 -60
- fabricatio/models/tool.py +328 -188
- fabricatio/models/usages.py +791 -515
- fabricatio/parser.py +81 -60
- fabricatio/rust.cp313-win_amd64.pyd +0 -0
- fabricatio/rust.pyi +886 -0
- fabricatio/toolboxes/__init__.py +1 -3
- fabricatio/toolboxes/fs.py +17 -1
- fabricatio/utils.py +156 -0
- fabricatio/workflows/__init__.py +1 -0
- fabricatio/workflows/articles.py +24 -0
- fabricatio/workflows/rag.py +11 -0
- fabricatio-0.3.14.dev5.data/scripts/tdown.exe +0 -0
- fabricatio-0.3.14.dev5.data/scripts/ttm.exe +0 -0
- fabricatio-0.3.14.dev5.dist-info/METADATA +188 -0
- fabricatio-0.3.14.dev5.dist-info/RECORD +64 -0
- {fabricatio-0.2.1.dev0.dist-info → fabricatio-0.3.14.dev5.dist-info}/WHEEL +1 -1
- fabricatio/_rust.cp313-win_amd64.pyd +0 -0
- fabricatio/_rust.pyi +0 -53
- fabricatio/_rust_instances.py +0 -8
- fabricatio/actions/communication.py +0 -15
- fabricatio/actions/transmission.py +0 -23
- fabricatio/config.py +0 -263
- fabricatio/models/advanced.py +0 -128
- fabricatio/models/events.py +0 -82
- fabricatio/models/utils.py +0 -78
- fabricatio/toolboxes/task.py +0 -6
- fabricatio-0.2.1.dev0.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.1.dev0.dist-info/METADATA +0 -420
- fabricatio-0.2.1.dev0.dist-info/RECORD +0 -35
- {fabricatio-0.2.1.dev0.dist-info → fabricatio-0.3.14.dev5.dist-info}/licenses/LICENSE +0 -0
@@ -1,26 +1,121 @@
|
|
1
1
|
"""This module contains the types for the keyword arguments of the methods in the models module."""
|
2
2
|
|
3
|
-
from typing import List, NotRequired, TypedDict
|
3
|
+
from typing import Dict, List, NotRequired, Optional, Required, TypedDict
|
4
4
|
|
5
|
-
from pydantic import NonNegativeFloat, NonNegativeInt, PositiveInt
|
6
5
|
|
6
|
+
class ChunkKwargs(TypedDict):
|
7
|
+
"""Configuration parameters for chunking operations."""
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
max_chunk_size: int
|
10
|
+
max_overlapping_rate: NotRequired[float]
|
10
11
|
|
11
|
-
model: NotRequired[str]
|
12
|
-
temperature: NotRequired[NonNegativeFloat]
|
13
|
-
stop: NotRequired[str | List[str]]
|
14
|
-
top_p: NotRequired[NonNegativeFloat]
|
15
|
-
max_tokens: NotRequired[PositiveInt]
|
16
|
-
stream: NotRequired[bool]
|
17
|
-
timeout: NotRequired[PositiveInt]
|
18
|
-
max_retries: NotRequired[PositiveInt]
|
19
12
|
|
13
|
+
class EmbeddingKwargs(TypedDict, total=False):
|
14
|
+
"""Configuration parameters for text embedding operations.
|
20
15
|
|
21
|
-
|
22
|
-
|
16
|
+
These settings control the behavior of embedding models that convert text
|
17
|
+
to vector representations.
|
18
|
+
"""
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
model: str
|
21
|
+
dimensions: int
|
22
|
+
timeout: int
|
23
|
+
caching: bool
|
24
|
+
|
25
|
+
|
26
|
+
class LLMKwargs(TypedDict, total=False):
|
27
|
+
"""Configuration parameters for language model inference.
|
28
|
+
|
29
|
+
These arguments control the behavior of large language model calls,
|
30
|
+
including generation parameters and caching options.
|
31
|
+
"""
|
32
|
+
|
33
|
+
model: Optional[str]
|
34
|
+
temperature: float
|
35
|
+
stop: str | list[str]
|
36
|
+
top_p: float
|
37
|
+
max_tokens: int
|
38
|
+
stream: bool
|
39
|
+
timeout: int
|
40
|
+
max_retries: int
|
41
|
+
no_cache: bool # if the req uses cache in this call
|
42
|
+
no_store: bool # If store the response of this call to cache
|
43
|
+
cache_ttl: int # how long the stored cache is alive, in seconds
|
44
|
+
s_maxage: int # max accepted age of cached response, in seconds
|
45
|
+
presence_penalty: float
|
46
|
+
frequency_penalty: float
|
47
|
+
|
48
|
+
|
49
|
+
class GenerateKwargs(LLMKwargs, total=False):
|
50
|
+
"""Arguments for content generation operations.
|
51
|
+
|
52
|
+
Extends LLMKwargs with additional parameters specific to generation tasks,
|
53
|
+
such as the number of generated items and the system message.
|
54
|
+
"""
|
55
|
+
|
56
|
+
system_message: str
|
57
|
+
|
58
|
+
|
59
|
+
class ValidateKwargs[T](GenerateKwargs, total=False):
|
60
|
+
"""Arguments for content validation operations.
|
61
|
+
|
62
|
+
Extends LLMKwargs with additional parameters specific to validation tasks,
|
63
|
+
such as limiting the number of validation attempts.
|
64
|
+
"""
|
65
|
+
|
66
|
+
default: Optional[T]
|
67
|
+
max_validations: int
|
68
|
+
|
69
|
+
|
70
|
+
class CompositeScoreKwargs(ValidateKwargs[List[Dict[str, float]]], total=False):
|
71
|
+
"""Arguments for composite score generation operations.
|
72
|
+
|
73
|
+
Extends GenerateKwargs with parameters for generating composite scores
|
74
|
+
based on specific criteria and weights.
|
75
|
+
"""
|
76
|
+
|
77
|
+
topic: str
|
78
|
+
criteria: set[str]
|
79
|
+
weights: Dict[str, float]
|
80
|
+
manual: Dict[str, str]
|
81
|
+
|
82
|
+
|
83
|
+
class BestKwargs(CompositeScoreKwargs, total=False):
|
84
|
+
"""Arguments for choose top-k operations."""
|
85
|
+
|
86
|
+
k: int
|
87
|
+
|
88
|
+
|
89
|
+
class ReviewInnerKwargs[T](ValidateKwargs[T], total=False):
|
90
|
+
"""Arguments for content review operations."""
|
91
|
+
|
92
|
+
criteria: set[str]
|
93
|
+
|
94
|
+
|
95
|
+
# noinspection PyTypedDict
|
96
|
+
class ReviewKwargs[T](ReviewInnerKwargs[T], total=False):
|
97
|
+
"""Arguments for content review operations.
|
98
|
+
|
99
|
+
Extends GenerateKwargs with parameters for evaluating content against
|
100
|
+
specific topics and review criteria.
|
101
|
+
"""
|
102
|
+
|
103
|
+
rating_manual: Dict[str, str]
|
104
|
+
topic: Required[str]
|
105
|
+
|
106
|
+
|
107
|
+
class ReferencedKwargs[T](ValidateKwargs[T], total=False):
|
108
|
+
"""Arguments for content review operations."""
|
109
|
+
|
110
|
+
reference: str
|
111
|
+
|
112
|
+
|
113
|
+
# noinspection PyTypedDict
|
114
|
+
class ChooseKwargs[T](ValidateKwargs[T], total=False):
|
115
|
+
"""Arguments for selection operations.
|
116
|
+
|
117
|
+
Extends GenerateKwargs with parameters for selecting among options,
|
118
|
+
such as the number of items to choose.
|
119
|
+
"""
|
120
|
+
|
121
|
+
k: int
|
fabricatio/models/role.py
CHANGED
@@ -1,48 +1,95 @@
|
|
1
|
-
"""Module that contains the Role class."""
|
1
|
+
"""Module that contains the Role class for managing workflows and their event registrations."""
|
2
2
|
|
3
|
-
from
|
3
|
+
from functools import partial
|
4
|
+
from typing import Any, Dict, Self
|
4
5
|
|
5
|
-
from fabricatio.
|
6
|
+
from fabricatio.emitter import env
|
6
7
|
from fabricatio.journal import logger
|
7
8
|
from fabricatio.models.action import WorkFlow
|
8
|
-
from fabricatio.models.
|
9
|
-
from fabricatio.
|
10
|
-
from fabricatio.
|
11
|
-
from
|
12
|
-
from pydantic import Field
|
9
|
+
from fabricatio.models.generic import WithBriefing
|
10
|
+
from fabricatio.rust import Event
|
11
|
+
from fabricatio.utils import is_subclass_of_base
|
12
|
+
from pydantic import ConfigDict, Field
|
13
13
|
|
14
|
+
is_toolbox_usage = partial(is_subclass_of_base, base_module="fabricatio.models.usages", base_name="ToolBoxUsage")
|
15
|
+
is_scoped_config = partial(is_subclass_of_base, base_module="fabricatio.models.generic", base_name="ScopedConfig")
|
14
16
|
|
15
|
-
class Role(ProposeTask, ToolBoxUsage):
|
16
|
-
"""Class that represents a role with a registry of events and workflows."""
|
17
17
|
|
18
|
-
|
19
|
-
"""
|
18
|
+
class Role(WithBriefing):
|
19
|
+
"""Class that represents a role with a registry of events and workflows.
|
20
20
|
|
21
|
-
|
21
|
+
A Role serves as a container for workflows, managing their registration to events
|
22
|
+
and providing them with shared configuration like tools and personality.
|
23
|
+
"""
|
24
|
+
|
25
|
+
model_config = ConfigDict(use_attribute_docstrings=True, arbitrary_types_allowed=True)
|
26
|
+
name: str = ""
|
27
|
+
"""The name of the role."""
|
28
|
+
description: str = ""
|
29
|
+
"""A brief description of the role's responsibilities and capabilities."""
|
30
|
+
|
31
|
+
registry: Dict[Event, WorkFlow] = Field(default_factory=dict)
|
32
|
+
"""The registry of events and workflows."""
|
22
33
|
|
23
34
|
def model_post_init(self, __context: Any) -> None:
|
24
|
-
"""
|
35
|
+
"""Initialize the role by resolving configurations and registering workflows.
|
36
|
+
|
37
|
+
Args:
|
38
|
+
__context: The context used for initialization
|
39
|
+
"""
|
40
|
+
self.name = self.name or self.__class__.__name__
|
41
|
+
|
25
42
|
self.resolve_configuration().register_workflows()
|
26
43
|
|
27
44
|
def register_workflows(self) -> Self:
|
28
|
-
"""Register
|
45
|
+
"""Register each workflow in the registry to its corresponding event in the event bus.
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
Self: The role instance for method chaining
|
49
|
+
"""
|
29
50
|
for event, workflow in self.registry.items():
|
30
|
-
logger.debug(
|
31
|
-
f"Registering workflow: `{workflow.name}` for event: `{Event.instantiate_from(event).collapse()}`"
|
32
|
-
)
|
51
|
+
logger.debug(f"Registering workflow: `{workflow.name}` for event: `{event.collapse()}`")
|
33
52
|
env.on(event, workflow.serve)
|
34
53
|
return self
|
35
54
|
|
36
55
|
def resolve_configuration(self) -> Self:
|
37
|
-
"""
|
56
|
+
"""Apply role-level configuration to all workflows in the registry.
|
57
|
+
|
58
|
+
This includes setting up fallback configurations, injecting personality traits,
|
59
|
+
and providing tool access to workflows and their steps.
|
60
|
+
|
61
|
+
Returns:
|
62
|
+
Self: The role instance for method chaining
|
63
|
+
"""
|
38
64
|
for workflow in self.registry.values():
|
39
65
|
logger.debug(f"Resolving config for workflow: `{workflow.name}`")
|
40
|
-
(
|
41
|
-
|
42
|
-
|
43
|
-
.inject_personality(self.briefing)
|
44
|
-
.supply_tools_from(self)
|
45
|
-
.steps_supply_tools_from_self()
|
46
|
-
)
|
47
|
-
|
66
|
+
self._configure_scoped_config(workflow)
|
67
|
+
self._configure_toolbox_usage(workflow)
|
68
|
+
workflow.inject_personality(self.briefing)
|
48
69
|
return self
|
70
|
+
|
71
|
+
def _configure_scoped_config(self, workflow: WorkFlow) -> None:
|
72
|
+
"""Configure scoped configuration for workflow and its actions."""
|
73
|
+
if not is_scoped_config(self.__class__):
|
74
|
+
return
|
75
|
+
|
76
|
+
fallback_target = self
|
77
|
+
if is_scoped_config(workflow):
|
78
|
+
workflow.fallback_to(self)
|
79
|
+
fallback_target = workflow
|
80
|
+
|
81
|
+
for action in (a for a in workflow.iter_actions() if is_scoped_config(a)):
|
82
|
+
action.fallback_to(fallback_target)
|
83
|
+
|
84
|
+
def _configure_toolbox_usage(self, workflow: WorkFlow) -> None:
|
85
|
+
"""Configure toolbox usage for workflow and its actions."""
|
86
|
+
if not is_toolbox_usage(self.__class__):
|
87
|
+
return
|
88
|
+
|
89
|
+
supply_target = self
|
90
|
+
if is_toolbox_usage(workflow):
|
91
|
+
workflow.supply_tools_from(self)
|
92
|
+
supply_target = workflow
|
93
|
+
|
94
|
+
for action in (a for a in workflow.iter_actions() if is_toolbox_usage(a)):
|
95
|
+
action.supply_tools_from(supply_target)
|
fabricatio/models/task.py
CHANGED
@@ -4,60 +4,44 @@ It includes methods to manage the task's lifecycle, such as starting, finishing,
|
|
4
4
|
"""
|
5
5
|
|
6
6
|
from asyncio import Queue
|
7
|
-
from
|
8
|
-
from typing import Any, List, Optional, Self
|
7
|
+
from typing import Any, Dict, List, Optional, Self, Union
|
9
8
|
|
10
|
-
from fabricatio.
|
11
|
-
from fabricatio.config import configs
|
12
|
-
from fabricatio.core import env
|
9
|
+
from fabricatio.emitter import env
|
13
10
|
from fabricatio.journal import logger
|
14
|
-
from fabricatio.models.
|
15
|
-
from fabricatio.
|
11
|
+
from fabricatio.models.generic import ProposedAble, WithBriefing, WithDependency
|
12
|
+
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, Event, TaskStatus
|
16
13
|
from pydantic import Field, PrivateAttr
|
17
14
|
|
15
|
+
type EventLike = Union[str, Event, List[str]]
|
18
16
|
|
19
|
-
class TaskStatus(Enum):
|
20
|
-
"""An enumeration representing the status of a task.
|
21
17
|
|
22
|
-
|
23
|
-
Pending: The task is pending.
|
24
|
-
Running: The task is currently running.
|
25
|
-
Finished: The task has been successfully completed.
|
26
|
-
Failed: The task has failed.
|
27
|
-
Cancelled: The task has been cancelled.
|
28
|
-
"""
|
29
|
-
|
30
|
-
Pending = "pending"
|
31
|
-
Running = "running"
|
32
|
-
Finished = "finished"
|
33
|
-
Failed = "failed"
|
34
|
-
Cancelled = "cancelled"
|
35
|
-
|
36
|
-
|
37
|
-
class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
18
|
+
class Task[T](WithBriefing, ProposedAble, WithDependency):
|
38
19
|
"""A class representing a task with a status and output.
|
39
20
|
|
40
21
|
Attributes:
|
41
22
|
name (str): The name of the task.
|
42
23
|
description (str): The description of the task.
|
43
|
-
|
24
|
+
goals (str): The goal of the task.
|
44
25
|
dependencies (List[str]): The file dependencies of the task, a list of file paths.
|
45
26
|
namespace (List[str]): The namespace of the task, a list of namespace segment, as string.
|
46
27
|
"""
|
47
28
|
|
48
29
|
name: str = Field(...)
|
49
|
-
"""The name of the task."""
|
30
|
+
"""The name of the task, which should be concise and descriptive."""
|
50
31
|
|
51
32
|
description: str = Field(default="")
|
52
|
-
"""
|
33
|
+
"""A detailed explanation of the task that includes all necessary information. Should be clear and answer what, why, when, where, who, and how questions."""
|
53
34
|
|
54
|
-
|
55
|
-
"""
|
35
|
+
goals: List[str] = Field(default_factory=list)
|
36
|
+
"""A list of objectives that the task aims to accomplish. Each goal should be clear and specific. Complex tasks should be broken into multiple smaller goals."""
|
56
37
|
|
57
38
|
namespace: List[str] = Field(default_factory=list)
|
58
|
-
"""
|
39
|
+
"""A list of string segments that identify the task's location in the system. If not specified, defaults to an empty list."""
|
59
40
|
|
60
|
-
|
41
|
+
dependencies: List[str] = Field(default_factory=list)
|
42
|
+
"""A list of file paths that are needed or mentioned in the task's description (either reading or writing) to complete this task. If not specified, defaults to an empty list."""
|
43
|
+
|
44
|
+
_output: Queue[T | None] = PrivateAttr(default_factory=Queue)
|
61
45
|
"""The output queue of the task."""
|
62
46
|
|
63
47
|
_status: TaskStatus = PrivateAttr(default=TaskStatus.Pending)
|
@@ -65,10 +49,22 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
|
65
49
|
|
66
50
|
_namespace: Event = PrivateAttr(default_factory=Event)
|
67
51
|
"""The namespace of the task as an event, which is generated from the namespace list."""
|
52
|
+
_extra_init_context: Dict = PrivateAttr(default_factory=dict)
|
53
|
+
"""Extra initialization context for the task, which is designed to override the one of the Workflow."""
|
54
|
+
|
55
|
+
@property
|
56
|
+
def extra_init_context(self) -> Dict:
|
57
|
+
"""Extra initialization context for the task, which is designed to override the one of the Workflow."""
|
58
|
+
return self._extra_init_context
|
59
|
+
|
60
|
+
def update_init_context(self, /, **kwargs) -> Self:
|
61
|
+
"""Update the extra initialization context for the task."""
|
62
|
+
self.extra_init_context.update(kwargs)
|
63
|
+
return self
|
68
64
|
|
69
65
|
def model_post_init(self, __context: Any) -> None:
|
70
66
|
"""Initialize the task with a namespace event."""
|
71
|
-
self._namespace.
|
67
|
+
self._namespace.concat(self.namespace)
|
72
68
|
|
73
69
|
def move_to(self, new_namespace: EventLike) -> Self:
|
74
70
|
"""Move the task to a new namespace.
|
@@ -98,20 +94,6 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
|
98
94
|
self.namespace = self._namespace.segments
|
99
95
|
return self
|
100
96
|
|
101
|
-
@classmethod
|
102
|
-
def simple_task(cls, name: str, goal: List[str], description: str) -> Self:
|
103
|
-
"""Create a simple task with a name, goal, and description.
|
104
|
-
|
105
|
-
Args:
|
106
|
-
name (str): The name of the task.
|
107
|
-
goal (List[str]): The goal of the task.
|
108
|
-
description (str): The description of the task.
|
109
|
-
|
110
|
-
Returns:
|
111
|
-
Task: A new instance of the `Task` class.
|
112
|
-
"""
|
113
|
-
return cls(name=name, goal=goal, description=description)
|
114
|
-
|
115
97
|
def update_task(self, goal: Optional[List[str] | str] = None, description: Optional[str] = None) -> Self:
|
116
98
|
"""Update the goal and description of the task.
|
117
99
|
|
@@ -123,12 +105,12 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
|
123
105
|
Task: The updated instance of the `Task` class.
|
124
106
|
"""
|
125
107
|
if goal:
|
126
|
-
self.
|
108
|
+
self.goals = goal if isinstance(goal, list) else [goal]
|
127
109
|
if description:
|
128
110
|
self.description = description
|
129
111
|
return self
|
130
112
|
|
131
|
-
async def get_output(self) -> T:
|
113
|
+
async def get_output(self) -> T | None:
|
132
114
|
"""Get the output of the task.
|
133
115
|
|
134
116
|
Returns:
|
@@ -141,12 +123,12 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
|
141
123
|
"""Return a formatted status label for the task.
|
142
124
|
|
143
125
|
Args:
|
144
|
-
status (TaskStatus): The status of the task.
|
126
|
+
status (fabricatio.constants.TaskStatus): The status of the task.
|
145
127
|
|
146
128
|
Returns:
|
147
129
|
str: The formatted status label.
|
148
130
|
"""
|
149
|
-
return self._namespace.derive(self.name).push(status
|
131
|
+
return self._namespace.derive(self.name).push(status).collapse()
|
150
132
|
|
151
133
|
@property
|
152
134
|
def pending_label(self) -> str:
|
@@ -229,6 +211,7 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
|
229
211
|
"""
|
230
212
|
logger.info(f"Cancelling task `{self.name}`")
|
231
213
|
self._status = TaskStatus.Cancelled
|
214
|
+
await self._output.put(None)
|
232
215
|
await env.emit_async(self.cancelled_label, self)
|
233
216
|
return self
|
234
217
|
|
@@ -240,27 +223,38 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
|
240
223
|
"""
|
241
224
|
logger.info(f"Failing task `{self.name}`")
|
242
225
|
self._status = TaskStatus.Failed
|
226
|
+
await self._output.put(None)
|
243
227
|
await env.emit_async(self.failed_label, self)
|
244
228
|
return self
|
245
229
|
|
246
|
-
|
230
|
+
def publish(self, new_namespace: Optional[EventLike] = None) -> Self:
|
247
231
|
"""Publish the task to the event bus.
|
248
232
|
|
233
|
+
Args:
|
234
|
+
new_namespace(EventLike, optional): The new namespace to move the task to.
|
235
|
+
|
249
236
|
Returns:
|
250
|
-
Task: The published instance of the `Task` class
|
237
|
+
Task: The published instance of the `Task` class.
|
251
238
|
"""
|
239
|
+
if new_namespace:
|
240
|
+
self.move_to(new_namespace)
|
252
241
|
logger.info(f"Publishing task `{(label := self.pending_label)}`")
|
253
|
-
|
242
|
+
env.emit_future(label, self)
|
254
243
|
return self
|
255
244
|
|
256
|
-
async def delegate(self) -> T:
|
257
|
-
"""Delegate the task to the event
|
245
|
+
async def delegate(self, new_namespace: Optional[EventLike] = None) -> T | None:
|
246
|
+
"""Delegate the task to the event.
|
247
|
+
|
248
|
+
Args:
|
249
|
+
new_namespace(EventLike, optional): The new namespace to move the task to.
|
258
250
|
|
259
251
|
Returns:
|
260
|
-
T: The output of the task
|
252
|
+
T|None: The output of the task.
|
261
253
|
"""
|
254
|
+
if new_namespace:
|
255
|
+
self.move_to(new_namespace)
|
262
256
|
logger.info(f"Delegating task `{(label := self.pending_label)}`")
|
263
|
-
|
257
|
+
env.emit_future(label, self)
|
264
258
|
return await self.get_output()
|
265
259
|
|
266
260
|
@property
|
@@ -270,7 +264,47 @@ class Task[T](WithBriefing, WithJsonExample, WithDependency):
|
|
270
264
|
Returns:
|
271
265
|
str: The briefing of the task.
|
272
266
|
"""
|
273
|
-
return
|
274
|
-
|
267
|
+
return TEMPLATE_MANAGER.render_template(
|
268
|
+
CONFIG.templates.task_briefing_template,
|
275
269
|
self.model_dump(),
|
276
270
|
)
|
271
|
+
|
272
|
+
def is_running(self) -> bool:
|
273
|
+
"""Check if the task is running.
|
274
|
+
|
275
|
+
Returns:
|
276
|
+
bool: True if the task is running, False otherwise.
|
277
|
+
"""
|
278
|
+
return self._status == TaskStatus.Running
|
279
|
+
|
280
|
+
def is_finished(self) -> bool:
|
281
|
+
"""Check if the task is finished.
|
282
|
+
|
283
|
+
Returns:
|
284
|
+
bool: True if the task is finished, False otherwise.
|
285
|
+
"""
|
286
|
+
return self._status == TaskStatus.Finished
|
287
|
+
|
288
|
+
def is_failed(self) -> bool:
|
289
|
+
"""Check if the task is failed.
|
290
|
+
|
291
|
+
Returns:
|
292
|
+
bool: True if the task is failed, False otherwise.
|
293
|
+
"""
|
294
|
+
return self._status == TaskStatus.Failed
|
295
|
+
|
296
|
+
def is_cancelled(self) -> bool:
|
297
|
+
"""Check if the task is cancelled.
|
298
|
+
|
299
|
+
Returns:
|
300
|
+
bool: True if the task is cancelled, False otherwise.
|
301
|
+
"""
|
302
|
+
return self._status == TaskStatus.Cancelled
|
303
|
+
|
304
|
+
def is_pending(self) -> bool:
|
305
|
+
"""Check if the task is pending.
|
306
|
+
|
307
|
+
Returns:
|
308
|
+
bool: True if the task is pending, False otherwise.
|
309
|
+
"""
|
310
|
+
return self._status == TaskStatus.Pending
|