fabricatio 0.3.15.dev4__cp313-cp313-win_amd64.whl → 0.4.0__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 +9 -8
- fabricatio/actions/output.py +21 -22
- fabricatio/actions/rules.py +83 -83
- fabricatio/rust.cp313-win_amd64.pyd +0 -0
- fabricatio/workflows/rag.py +2 -1
- fabricatio-0.4.0.data/scripts/tdown.exe +0 -0
- {fabricatio-0.3.15.dev4.dist-info → fabricatio-0.4.0.dist-info}/METADATA +18 -16
- fabricatio-0.4.0.dist-info/RECORD +18 -0
- fabricatio/actions/article.py +0 -415
- fabricatio/actions/article_rag.py +0 -407
- fabricatio/capabilities/__init__.py +0 -1
- fabricatio/capabilities/advanced_judge.py +0 -20
- fabricatio/capabilities/advanced_rag.py +0 -61
- fabricatio/capabilities/censor.py +0 -105
- fabricatio/capabilities/check.py +0 -212
- fabricatio/capabilities/correct.py +0 -228
- fabricatio/capabilities/extract.py +0 -74
- fabricatio/capabilities/persist.py +0 -103
- fabricatio/capabilities/propose.py +0 -65
- fabricatio/capabilities/rag.py +0 -264
- fabricatio/capabilities/rating.py +0 -404
- fabricatio/capabilities/review.py +0 -114
- fabricatio/capabilities/task.py +0 -113
- fabricatio/decorators.py +0 -253
- fabricatio/emitter.py +0 -177
- fabricatio/fs/__init__.py +0 -35
- fabricatio/fs/curd.py +0 -153
- fabricatio/fs/readers.py +0 -61
- fabricatio/journal.py +0 -12
- fabricatio/models/action.py +0 -263
- fabricatio/models/adv_kwargs_types.py +0 -63
- fabricatio/models/extra/__init__.py +0 -1
- fabricatio/models/extra/advanced_judge.py +0 -32
- fabricatio/models/extra/aricle_rag.py +0 -286
- fabricatio/models/extra/article_base.py +0 -486
- fabricatio/models/extra/article_essence.py +0 -101
- fabricatio/models/extra/article_main.py +0 -286
- fabricatio/models/extra/article_outline.py +0 -46
- fabricatio/models/extra/article_proposal.py +0 -52
- fabricatio/models/extra/patches.py +0 -20
- fabricatio/models/extra/problem.py +0 -165
- fabricatio/models/extra/rag.py +0 -98
- fabricatio/models/extra/rule.py +0 -52
- fabricatio/models/generic.py +0 -812
- fabricatio/models/kwargs_types.py +0 -121
- fabricatio/models/role.py +0 -99
- fabricatio/models/task.py +0 -310
- fabricatio/models/tool.py +0 -328
- fabricatio/models/usages.py +0 -791
- fabricatio/parser.py +0 -114
- fabricatio/rust.pyi +0 -846
- fabricatio/utils.py +0 -156
- fabricatio/workflows/articles.py +0 -24
- fabricatio-0.3.15.dev4.data/scripts/tdown.exe +0 -0
- fabricatio-0.3.15.dev4.data/scripts/ttm.exe +0 -0
- fabricatio-0.3.15.dev4.dist-info/RECORD +0 -64
- {fabricatio-0.3.15.dev4.dist-info → fabricatio-0.4.0.dist-info}/WHEEL +0 -0
- {fabricatio-0.3.15.dev4.dist-info → fabricatio-0.4.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,121 +0,0 @@
|
|
1
|
-
"""This module contains the types for the keyword arguments of the methods in the models module."""
|
2
|
-
|
3
|
-
from typing import Dict, List, NotRequired, Optional, Required, TypedDict
|
4
|
-
|
5
|
-
|
6
|
-
class ChunkKwargs(TypedDict):
|
7
|
-
"""Configuration parameters for chunking operations."""
|
8
|
-
|
9
|
-
max_chunk_size: int
|
10
|
-
max_overlapping_rate: NotRequired[float]
|
11
|
-
|
12
|
-
|
13
|
-
class EmbeddingKwargs(TypedDict, total=False):
|
14
|
-
"""Configuration parameters for text embedding operations.
|
15
|
-
|
16
|
-
These settings control the behavior of embedding models that convert text
|
17
|
-
to vector representations.
|
18
|
-
"""
|
19
|
-
|
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
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
"""Module that contains the Role class for managing workflows and their event registrations."""
|
2
|
-
|
3
|
-
from functools import partial
|
4
|
-
from typing import Any, Callable, Dict, Self, Type
|
5
|
-
|
6
|
-
from fabricatio.emitter import env
|
7
|
-
from fabricatio.journal import logger
|
8
|
-
from fabricatio.models.action import WorkFlow
|
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
|
-
|
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")
|
16
|
-
|
17
|
-
|
18
|
-
class Role(WithBriefing):
|
19
|
-
"""Class that represents a role with a registry of events and workflows.
|
20
|
-
|
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."""
|
33
|
-
|
34
|
-
def model_post_init(self, __context: Any) -> None:
|
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
|
-
|
42
|
-
self.resolve_configuration().register_workflows()
|
43
|
-
|
44
|
-
def register_workflows(self) -> Self:
|
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
|
-
"""
|
50
|
-
for event, workflow in self.registry.items():
|
51
|
-
logger.debug(f"Registering workflow: `{workflow.name}` for event: `{event.collapse()}`")
|
52
|
-
env.on(event, workflow.serve)
|
53
|
-
return self
|
54
|
-
|
55
|
-
def resolve_configuration(self) -> Self:
|
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
|
-
"""
|
64
|
-
for workflow in self.registry.values():
|
65
|
-
logger.debug(f"Resolving config for workflow: `{workflow.name}`")
|
66
|
-
self._configure_scoped_config(workflow)
|
67
|
-
self._configure_toolbox_usage(workflow)
|
68
|
-
workflow.inject_personality(self.briefing)
|
69
|
-
return self
|
70
|
-
|
71
|
-
def _propagate_config(
|
72
|
-
self,
|
73
|
-
workflow: WorkFlow,
|
74
|
-
has_capability: Callable[[Type], bool],
|
75
|
-
config_method_name: str,
|
76
|
-
capability_description: str,
|
77
|
-
) -> None:
|
78
|
-
"""Propagates configuration to workflow and its actions if they have a given capability."""
|
79
|
-
if not has_capability(self.__class__):
|
80
|
-
return
|
81
|
-
|
82
|
-
config_source_for_actions = self
|
83
|
-
if has_capability(workflow.__class__):
|
84
|
-
logger.debug(
|
85
|
-
f"Configuring {capability_description} inherited from `{self.name}` for workflow: `{workflow.name}`"
|
86
|
-
)
|
87
|
-
getattr(workflow, config_method_name)(self)
|
88
|
-
config_source_for_actions = workflow
|
89
|
-
|
90
|
-
for action in (act for act in workflow.iter_actions() if has_capability(act.__class__)):
|
91
|
-
getattr(action, config_method_name)(config_source_for_actions)
|
92
|
-
|
93
|
-
def _configure_scoped_config(self, workflow: WorkFlow) -> None:
|
94
|
-
"""Configure scoped configuration for workflow and its actions."""
|
95
|
-
self._propagate_config(workflow, is_scoped_config, "fallback_to", "scoped config")
|
96
|
-
|
97
|
-
def _configure_toolbox_usage(self, workflow: WorkFlow) -> None:
|
98
|
-
"""Configure toolbox usage for workflow and its actions."""
|
99
|
-
self._propagate_config(workflow, is_toolbox_usage, "supply_tools_from", "toolbox usage")
|
fabricatio/models/task.py
DELETED
@@ -1,310 +0,0 @@
|
|
1
|
-
"""This module defines the `Task` class, which represents a task with a status and output.
|
2
|
-
|
3
|
-
It includes methods to manage the task's lifecycle, such as starting, finishing, cancelling, and failing the task.
|
4
|
-
"""
|
5
|
-
|
6
|
-
from asyncio import Queue
|
7
|
-
from typing import Any, Dict, List, Optional, Self, Union
|
8
|
-
|
9
|
-
from fabricatio.emitter import env
|
10
|
-
from fabricatio.journal import logger
|
11
|
-
from fabricatio.models.generic import ProposedAble, WithBriefing, WithDependency
|
12
|
-
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, Event, TaskStatus
|
13
|
-
from pydantic import Field, PrivateAttr
|
14
|
-
|
15
|
-
type EventLike = Union[str, Event, List[str]]
|
16
|
-
|
17
|
-
|
18
|
-
class Task[T](WithBriefing, ProposedAble, WithDependency):
|
19
|
-
"""A class representing a task with a status and output.
|
20
|
-
|
21
|
-
Attributes:
|
22
|
-
name (str): The name of the task.
|
23
|
-
description (str): The description of the task.
|
24
|
-
goals (str): The goal of the task.
|
25
|
-
dependencies (List[str]): The file dependencies of the task, a list of file paths.
|
26
|
-
namespace (List[str]): The namespace of the task, a list of namespace segment, as string.
|
27
|
-
"""
|
28
|
-
|
29
|
-
name: str = Field(...)
|
30
|
-
"""The name of the task, which should be concise and descriptive."""
|
31
|
-
|
32
|
-
description: str = Field(default="")
|
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."""
|
34
|
-
|
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."""
|
37
|
-
|
38
|
-
namespace: List[str] = Field(default_factory=list)
|
39
|
-
"""A list of string segments that identify the task's location in the system. If not specified, defaults to an empty list."""
|
40
|
-
|
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)
|
45
|
-
"""The output queue of the task."""
|
46
|
-
|
47
|
-
_status: TaskStatus = PrivateAttr(default=TaskStatus.Pending)
|
48
|
-
"""The status of the task."""
|
49
|
-
|
50
|
-
_namespace: Event = PrivateAttr(default_factory=Event)
|
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
|
64
|
-
|
65
|
-
def model_post_init(self, __context: Any) -> None:
|
66
|
-
"""Initialize the task with a namespace event."""
|
67
|
-
self._namespace.concat(self.namespace)
|
68
|
-
|
69
|
-
def move_to(self, new_namespace: EventLike) -> Self:
|
70
|
-
"""Move the task to a new namespace.
|
71
|
-
|
72
|
-
Args:
|
73
|
-
new_namespace (EventLike): The new namespace to move the task to.
|
74
|
-
|
75
|
-
Returns:
|
76
|
-
Task: The moved instance of the `Task` class.
|
77
|
-
"""
|
78
|
-
logger.debug(f"Moving task `{self.name}` to `{new_namespace}`")
|
79
|
-
self._namespace.clear().concat(new_namespace)
|
80
|
-
self.namespace = self._namespace.segments
|
81
|
-
return self
|
82
|
-
|
83
|
-
def nested_move_to(self, new_parent_namespace: EventLike) -> Self:
|
84
|
-
"""Move the task to a new namespace by nesting it under the new parent namespace.
|
85
|
-
|
86
|
-
Args:
|
87
|
-
new_parent_namespace (EventLike): The new parent namespace to move the task to.
|
88
|
-
|
89
|
-
Returns:
|
90
|
-
Task: The nested moved instance of the `Task` class.
|
91
|
-
"""
|
92
|
-
logger.debug(f"Nested moving task `{self.name}` to `{new_parent_namespace}`")
|
93
|
-
self._namespace.clear().concat(new_parent_namespace).concat(self.namespace)
|
94
|
-
self.namespace = self._namespace.segments
|
95
|
-
return self
|
96
|
-
|
97
|
-
def update_task(self, goal: Optional[List[str] | str] = None, description: Optional[str] = None) -> Self:
|
98
|
-
"""Update the goal and description of the task.
|
99
|
-
|
100
|
-
Args:
|
101
|
-
goal (str|List[str], optional): The new goal of the task.
|
102
|
-
description (str, optional): The new description of the task.
|
103
|
-
|
104
|
-
Returns:
|
105
|
-
Task: The updated instance of the `Task` class.
|
106
|
-
"""
|
107
|
-
if goal:
|
108
|
-
self.goals = goal if isinstance(goal, list) else [goal]
|
109
|
-
if description:
|
110
|
-
self.description = description
|
111
|
-
return self
|
112
|
-
|
113
|
-
async def get_output(self) -> T | None:
|
114
|
-
"""Get the output of the task.
|
115
|
-
|
116
|
-
Returns:
|
117
|
-
T: The output of the task.
|
118
|
-
"""
|
119
|
-
logger.debug(f"Getting output for task {self.name}")
|
120
|
-
return await self._output.get()
|
121
|
-
|
122
|
-
def status_label(self, status: TaskStatus) -> str:
|
123
|
-
"""Return a formatted status label for the task.
|
124
|
-
|
125
|
-
Args:
|
126
|
-
status (fabricatio.constants.TaskStatus): The status of the task.
|
127
|
-
|
128
|
-
Returns:
|
129
|
-
str: The formatted status label.
|
130
|
-
"""
|
131
|
-
return self._namespace.derive(self.name).push(status).collapse()
|
132
|
-
|
133
|
-
@property
|
134
|
-
def pending_label(self) -> str:
|
135
|
-
"""Return the pending status label for the task.
|
136
|
-
|
137
|
-
Returns:
|
138
|
-
str: The pending status label.
|
139
|
-
"""
|
140
|
-
return self.status_label(TaskStatus.Pending)
|
141
|
-
|
142
|
-
@property
|
143
|
-
def running_label(self) -> str:
|
144
|
-
"""Return the running status label for the task.
|
145
|
-
|
146
|
-
Returns:
|
147
|
-
str: The running status label.
|
148
|
-
"""
|
149
|
-
return self.status_label(TaskStatus.Running)
|
150
|
-
|
151
|
-
@property
|
152
|
-
def finished_label(self) -> str:
|
153
|
-
"""Return the finished status label for the task.
|
154
|
-
|
155
|
-
Returns:
|
156
|
-
str: The finished status label.
|
157
|
-
"""
|
158
|
-
return self.status_label(TaskStatus.Finished)
|
159
|
-
|
160
|
-
@property
|
161
|
-
def failed_label(self) -> str:
|
162
|
-
"""Return the failed status label for the task.
|
163
|
-
|
164
|
-
Returns:
|
165
|
-
str: The failed status label.
|
166
|
-
"""
|
167
|
-
return self.status_label(TaskStatus.Failed)
|
168
|
-
|
169
|
-
@property
|
170
|
-
def cancelled_label(self) -> str:
|
171
|
-
"""Return the cancelled status label for the task.
|
172
|
-
|
173
|
-
Returns:
|
174
|
-
str: The cancelled status label.
|
175
|
-
"""
|
176
|
-
return self.status_label(TaskStatus.Cancelled)
|
177
|
-
|
178
|
-
async def finish(self, output: T) -> Self:
|
179
|
-
"""Mark the task as finished and set the output.
|
180
|
-
|
181
|
-
Args:
|
182
|
-
output (T): The output of the task.
|
183
|
-
|
184
|
-
Returns:
|
185
|
-
Task: The finished instance of the `Task` class.
|
186
|
-
"""
|
187
|
-
logger.info(f"Finishing task {self.name}")
|
188
|
-
self._status = TaskStatus.Finished
|
189
|
-
await self._output.put(output)
|
190
|
-
logger.debug(f"Output set for task {self.name}")
|
191
|
-
await env.emit_async(self.finished_label, self)
|
192
|
-
logger.debug(f"Emitted finished event for task {self.name}")
|
193
|
-
return self
|
194
|
-
|
195
|
-
async def start(self) -> Self:
|
196
|
-
"""Mark the task as running.
|
197
|
-
|
198
|
-
Returns:
|
199
|
-
Task: The running instance of the `Task` class.
|
200
|
-
"""
|
201
|
-
logger.info(f"Starting task `{self.name}`")
|
202
|
-
self._status = TaskStatus.Running
|
203
|
-
await env.emit_async(self.running_label, self)
|
204
|
-
return self
|
205
|
-
|
206
|
-
async def cancel(self) -> Self:
|
207
|
-
"""Mark the task as cancelled.
|
208
|
-
|
209
|
-
Returns:
|
210
|
-
Task: The cancelled instance of the `Task` class.
|
211
|
-
"""
|
212
|
-
logger.info(f"Cancelling task `{self.name}`")
|
213
|
-
self._status = TaskStatus.Cancelled
|
214
|
-
await self._output.put(None)
|
215
|
-
await env.emit_async(self.cancelled_label, self)
|
216
|
-
return self
|
217
|
-
|
218
|
-
async def fail(self) -> Self:
|
219
|
-
"""Mark the task as failed.
|
220
|
-
|
221
|
-
Returns:
|
222
|
-
Task: The failed instance of the `Task` class.
|
223
|
-
"""
|
224
|
-
logger.info(f"Failing task `{self.name}`")
|
225
|
-
self._status = TaskStatus.Failed
|
226
|
-
await self._output.put(None)
|
227
|
-
await env.emit_async(self.failed_label, self)
|
228
|
-
return self
|
229
|
-
|
230
|
-
def publish(self, new_namespace: Optional[EventLike] = None) -> Self:
|
231
|
-
"""Publish the task to the event bus.
|
232
|
-
|
233
|
-
Args:
|
234
|
-
new_namespace(EventLike, optional): The new namespace to move the task to.
|
235
|
-
|
236
|
-
Returns:
|
237
|
-
Task: The published instance of the `Task` class.
|
238
|
-
"""
|
239
|
-
if new_namespace:
|
240
|
-
self.move_to(new_namespace)
|
241
|
-
logger.info(f"Publishing task `{(label := self.pending_label)}`")
|
242
|
-
env.emit_future(label, self)
|
243
|
-
return self
|
244
|
-
|
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.
|
250
|
-
|
251
|
-
Returns:
|
252
|
-
T|None: The output of the task.
|
253
|
-
"""
|
254
|
-
if new_namespace:
|
255
|
-
self.move_to(new_namespace)
|
256
|
-
logger.info(f"Delegating task `{(label := self.pending_label)}`")
|
257
|
-
env.emit_future(label, self)
|
258
|
-
return await self.get_output()
|
259
|
-
|
260
|
-
@property
|
261
|
-
def briefing(self) -> str:
|
262
|
-
"""Return a briefing of the task including its goal.
|
263
|
-
|
264
|
-
Returns:
|
265
|
-
str: The briefing of the task.
|
266
|
-
"""
|
267
|
-
return TEMPLATE_MANAGER.render_template(
|
268
|
-
CONFIG.templates.task_briefing_template,
|
269
|
-
self.model_dump(),
|
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
|