fabricatio 0.2.13.dev3__cp312-cp312-win_amd64.whl → 0.3.13__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/__init__.py +3 -3
- fabricatio/actions/article.py +32 -34
- fabricatio/actions/article_rag.py +58 -58
- fabricatio/actions/output.py +22 -21
- fabricatio/actions/rag.py +4 -3
- fabricatio/capabilities/check.py +29 -30
- fabricatio/capabilities/correct.py +23 -23
- fabricatio/capabilities/extract.py +36 -32
- fabricatio/capabilities/rag.py +34 -35
- fabricatio/capabilities/rating.py +77 -72
- fabricatio/capabilities/review.py +12 -11
- fabricatio/capabilities/task.py +4 -5
- fabricatio/core.py +22 -24
- fabricatio/decorators.py +10 -10
- fabricatio/fs/__init__.py +1 -2
- fabricatio/journal.py +2 -9
- fabricatio/models/action.py +2 -1
- fabricatio/models/extra/aricle_rag.py +10 -9
- fabricatio/models/extra/article_base.py +5 -6
- fabricatio/models/extra/article_main.py +11 -10
- fabricatio/models/generic.py +31 -59
- fabricatio/models/role.py +5 -3
- fabricatio/models/task.py +9 -9
- fabricatio/models/tool.py +5 -4
- fabricatio/models/usages.py +170 -161
- fabricatio/parser.py +2 -2
- fabricatio/rust.cp312-win_amd64.pyd +0 -0
- fabricatio/rust.pyi +435 -17
- fabricatio-0.3.13.data/scripts/tdown.exe +0 -0
- fabricatio-0.3.13.data/scripts/ttm.exe +0 -0
- {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/METADATA +1 -3
- fabricatio-0.3.13.dist-info/RECORD +63 -0
- fabricatio/config.py +0 -430
- fabricatio/constants.py +0 -20
- fabricatio/models/events.py +0 -120
- fabricatio/rust_instances.py +0 -10
- fabricatio-0.2.13.dev3.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.13.dev3.data/scripts/ttm.exe +0 -0
- fabricatio-0.2.13.dev3.dist-info/RECORD +0 -67
- {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/licenses/LICENSE +0 -0
fabricatio/models/generic.py
CHANGED
@@ -6,13 +6,7 @@ from pathlib import Path
|
|
6
6
|
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Self, Type, Union, final, overload
|
7
7
|
|
8
8
|
import ujson
|
9
|
-
from fabricatio.
|
10
|
-
from fabricatio.fs.readers import safe_text_read
|
11
|
-
from fabricatio.journal import logger
|
12
|
-
from fabricatio.parser import JsonCapture
|
13
|
-
from fabricatio.rust import blake3_hash, detect_language
|
14
|
-
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
15
|
-
from fabricatio.utils import ok
|
9
|
+
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, blake3_hash, detect_language
|
16
10
|
from litellm.utils import token_counter
|
17
11
|
from pydantic import (
|
18
12
|
BaseModel,
|
@@ -27,6 +21,12 @@ from pydantic import (
|
|
27
21
|
)
|
28
22
|
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
|
29
23
|
|
24
|
+
from fabricatio.fs import dump_text
|
25
|
+
from fabricatio.fs.readers import safe_text_read
|
26
|
+
from fabricatio.journal import logger
|
27
|
+
from fabricatio.parser import JsonCapture
|
28
|
+
from fabricatio.utils import ok
|
29
|
+
|
30
30
|
|
31
31
|
class Base(BaseModel):
|
32
32
|
"""Base class for all models with Pydantic configuration.
|
@@ -74,9 +74,9 @@ class Display(Base):
|
|
74
74
|
str: Combined display output with boundary markers
|
75
75
|
"""
|
76
76
|
return (
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
"--- Start of Extra Info Sequence ---"
|
78
|
+
+ "\n".join(d.compact() if compact else d.display() for d in seq)
|
79
|
+
+ "--- End of Extra Info Sequence ---"
|
80
80
|
)
|
81
81
|
|
82
82
|
|
@@ -117,7 +117,7 @@ class WordCount(Base):
|
|
117
117
|
"""Expected word count of this research component."""
|
118
118
|
|
119
119
|
|
120
|
-
class FromMapping
|
120
|
+
class FromMapping:
|
121
121
|
"""Class that provides a method to generate a list of objects from a mapping."""
|
122
122
|
|
123
123
|
@classmethod
|
@@ -126,7 +126,7 @@ class FromMapping(Base):
|
|
126
126
|
"""Generate a list of objects from a mapping."""
|
127
127
|
|
128
128
|
|
129
|
-
class AsPrompt
|
129
|
+
class AsPrompt:
|
130
130
|
"""Class that provides a method to generate a prompt from the model.
|
131
131
|
|
132
132
|
This class includes a method to generate a prompt based on the model's attributes.
|
@@ -140,7 +140,7 @@ class AsPrompt(Base):
|
|
140
140
|
str: The generated prompt.
|
141
141
|
"""
|
142
142
|
return TEMPLATE_MANAGER.render_template(
|
143
|
-
|
143
|
+
CONFIG.templates.as_prompt_template,
|
144
144
|
self._as_prompt_inner(),
|
145
145
|
)
|
146
146
|
|
@@ -178,13 +178,16 @@ class WithRef[T](Base):
|
|
178
178
|
)
|
179
179
|
|
180
180
|
@overload
|
181
|
-
def update_ref[S: WithRef](self: S, reference: T) -> S:
|
181
|
+
def update_ref[S: WithRef](self: S, reference: T) -> S:
|
182
|
+
...
|
182
183
|
|
183
184
|
@overload
|
184
|
-
def update_ref[S: WithRef](self: S, reference: "WithRef[T]") -> S:
|
185
|
+
def update_ref[S: WithRef](self: S, reference: "WithRef[T]") -> S:
|
186
|
+
...
|
185
187
|
|
186
188
|
@overload
|
187
|
-
def update_ref[S: WithRef](self: S, reference: None = None) -> S:
|
189
|
+
def update_ref[S: WithRef](self: S, reference: None = None) -> S:
|
190
|
+
...
|
188
191
|
|
189
192
|
def update_ref[S: WithRef](self: S, reference: Union[T, "WithRef[T]", None] = None) -> S:
|
190
193
|
"""Update the reference of the object.
|
@@ -201,19 +204,6 @@ class WithRef[T](Base):
|
|
201
204
|
self._reference = reference # pyright: ignore [reportAttributeAccessIssue]
|
202
205
|
return self
|
203
206
|
|
204
|
-
def derive[S: WithRef](self: S, reference: Any) -> S:
|
205
|
-
"""Derive a new object from the current object.
|
206
|
-
|
207
|
-
Args:
|
208
|
-
reference (Any): The reference for the new object.
|
209
|
-
|
210
|
-
Returns:
|
211
|
-
S: A new instance derived from the current object with the provided reference.
|
212
|
-
"""
|
213
|
-
new = self.model_copy()
|
214
|
-
new._reference = reference
|
215
|
-
return new
|
216
|
-
|
217
207
|
|
218
208
|
class PersistentAble(Base):
|
219
209
|
"""Class providing file persistence capabilities.
|
@@ -306,7 +296,7 @@ class PersistentAble(Base):
|
|
306
296
|
return cls.model_validate_json(safe_text_read(path))
|
307
297
|
|
308
298
|
|
309
|
-
class Language
|
299
|
+
class Language:
|
310
300
|
"""Class that provides a language attribute."""
|
311
301
|
|
312
302
|
@property
|
@@ -318,8 +308,7 @@ class Language(Base):
|
|
318
308
|
return detect_language(self.title)
|
319
309
|
if isinstance(self, Named) and self.name:
|
320
310
|
return detect_language(self.name)
|
321
|
-
|
322
|
-
return detect_language(self.model_dump_json(by_alias=True))
|
311
|
+
raise RuntimeError(f"Cannot determine language! class that not support language: {self.__class__.__name__}")
|
323
312
|
|
324
313
|
|
325
314
|
class ModelHash(Base):
|
@@ -337,7 +326,7 @@ class ModelHash(Base):
|
|
337
326
|
return hash(self.model_dump_json())
|
338
327
|
|
339
328
|
|
340
|
-
class UpdateFrom
|
329
|
+
class UpdateFrom:
|
341
330
|
"""Class that provides a method to update the object from another object.
|
342
331
|
|
343
332
|
This class includes methods to update the current object with the attributes of another object.
|
@@ -386,25 +375,7 @@ class UpdateFrom(Base):
|
|
386
375
|
return self.update_pre_check(other).update_from_inner(other)
|
387
376
|
|
388
377
|
|
389
|
-
class
|
390
|
-
"""Class that provides a method to update the object from another object.
|
391
|
-
|
392
|
-
This class includes a method to resolve conflicts when updating the object from another object.
|
393
|
-
"""
|
394
|
-
|
395
|
-
@abstractmethod
|
396
|
-
def resolve_update_conflict(self, other: Self) -> str:
|
397
|
-
"""Resolve the update conflict between two objects.
|
398
|
-
|
399
|
-
Args:
|
400
|
-
other (Self): The other object to resolve the update conflict with.
|
401
|
-
|
402
|
-
Returns:
|
403
|
-
str: The resolved update conflict.
|
404
|
-
"""
|
405
|
-
|
406
|
-
|
407
|
-
class Introspect(Base):
|
378
|
+
class Introspect:
|
408
379
|
"""Class that provides a method to introspect the object.
|
409
380
|
|
410
381
|
This class includes a method to perform internal introspection of the object.
|
@@ -498,12 +469,12 @@ class CreateJsonObjPrompt(WithFormatedJsonSchema):
|
|
498
469
|
"""
|
499
470
|
if isinstance(requirement, str):
|
500
471
|
return TEMPLATE_MANAGER.render_template(
|
501
|
-
|
472
|
+
CONFIG.templates.create_json_obj_template,
|
502
473
|
{"requirement": requirement, "json_schema": cls.formated_json_schema()},
|
503
474
|
)
|
504
475
|
return [
|
505
476
|
TEMPLATE_MANAGER.render_template(
|
506
|
-
|
477
|
+
CONFIG.templates.create_json_obj_template,
|
507
478
|
{"requirement": r, "json_schema": cls.formated_json_schema()},
|
508
479
|
)
|
509
480
|
for r in requirement
|
@@ -575,7 +546,7 @@ class FinalizedDumpAble(Base):
|
|
575
546
|
Returns:
|
576
547
|
Self: The current instance of the object.
|
577
548
|
"""
|
578
|
-
|
549
|
+
dump_text(path, self.finalized_dump())
|
579
550
|
return self
|
580
551
|
|
581
552
|
|
@@ -655,7 +626,7 @@ class WithDependency(Base):
|
|
655
626
|
from fabricatio.fs import MAGIKA
|
656
627
|
|
657
628
|
return TEMPLATE_MANAGER.render_template(
|
658
|
-
|
629
|
+
CONFIG.templates.dependencies_template,
|
659
630
|
{
|
660
631
|
(pth := Path(p)).name: {
|
661
632
|
"path": pth.as_posix(),
|
@@ -672,7 +643,7 @@ class WithDependency(Base):
|
|
672
643
|
)
|
673
644
|
|
674
645
|
|
675
|
-
class Vectorizable
|
646
|
+
class Vectorizable:
|
676
647
|
"""Class that prepares the vectorization of the model.
|
677
648
|
|
678
649
|
This class includes methods to prepare the model for vectorization, ensuring it fits within a specified token length.
|
@@ -695,7 +666,7 @@ class Vectorizable(Base):
|
|
695
666
|
Raises:
|
696
667
|
ValueError: If the chunk exceeds the maximum sequence length.
|
697
668
|
"""
|
698
|
-
max_length = max_length or
|
669
|
+
max_length = max_length or CONFIG.embedding.max_sequence_length
|
699
670
|
chunk = self._prepare_vectorization_inner()
|
700
671
|
if max_length and (length := token_counter(text=chunk)) > max_length:
|
701
672
|
raise ValueError(f"Chunk exceeds maximum sequence length {max_length}, got {length}, see \n{chunk}")
|
@@ -883,7 +854,8 @@ class Patch[T](ProposedAble):
|
|
883
854
|
# copy the desc info of each corresponding fields from `ref_cls`
|
884
855
|
for field_name in [f for f in cls.model_fields if f in ref_cls.model_fields]:
|
885
856
|
my_schema["properties"][field_name]["description"] = (
|
886
|
-
|
857
|
+
ref_cls.model_fields[field_name].description or my_schema["properties"][field_name][
|
858
|
+
"description"]
|
887
859
|
)
|
888
860
|
my_schema["description"] = ref_cls.__doc__
|
889
861
|
|
fabricatio/models/role.py
CHANGED
@@ -2,15 +2,16 @@
|
|
2
2
|
|
3
3
|
from typing import Any, Self, Set
|
4
4
|
|
5
|
+
from fabricatio.rust import Event
|
6
|
+
from pydantic import Field, ConfigDict
|
7
|
+
|
5
8
|
from fabricatio.capabilities.propose import Propose
|
6
9
|
from fabricatio.core import env
|
7
10
|
from fabricatio.journal import logger
|
8
11
|
from fabricatio.models.action import WorkFlow
|
9
|
-
from fabricatio.models.events import Event
|
10
12
|
from fabricatio.models.generic import WithBriefing
|
11
13
|
from fabricatio.models.tool import ToolBox
|
12
14
|
from fabricatio.models.usages import ToolBoxUsage
|
13
|
-
from pydantic import Field
|
14
15
|
|
15
16
|
|
16
17
|
class Role(WithBriefing, Propose, ToolBoxUsage):
|
@@ -23,7 +24,8 @@ class Role(WithBriefing, Propose, ToolBoxUsage):
|
|
23
24
|
registry: Mapping of events to workflows that handle them
|
24
25
|
toolboxes: Set of toolboxes available to this role and its workflows
|
25
26
|
"""
|
26
|
-
|
27
|
+
# fixme: not use arbitrary_types_allowed
|
28
|
+
model_config = ConfigDict(use_attribute_docstrings=True, arbitrary_types_allowed=True)
|
27
29
|
description: str = ""
|
28
30
|
"""A brief description of the role's responsibilities and capabilities."""
|
29
31
|
|
fabricatio/models/task.py
CHANGED
@@ -4,16 +4,16 @@ 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 typing import Any, Dict, List, Optional, Self
|
7
|
+
from typing import Any, Dict, List, Optional, Self, Union
|
8
|
+
|
9
|
+
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, Event, TaskStatus
|
10
|
+
from pydantic import Field, PrivateAttr
|
8
11
|
|
9
|
-
from fabricatio.config import configs
|
10
|
-
from fabricatio.constants import TaskStatus
|
11
12
|
from fabricatio.core import env
|
12
13
|
from fabricatio.journal import logger
|
13
|
-
from fabricatio.models.events import Event, EventLike
|
14
14
|
from fabricatio.models.generic import ProposedAble, WithBriefing, WithDependency
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
type EventLike = Union[str, Event, List[str]]
|
17
17
|
|
18
18
|
|
19
19
|
class Task[T](WithBriefing, ProposedAble, WithDependency):
|
@@ -33,7 +33,7 @@ class Task[T](WithBriefing, ProposedAble, WithDependency):
|
|
33
33
|
description: str = Field(default="")
|
34
34
|
"""A detailed explanation of the task that includes all necessary information. Should be clear and answer what, why, when, where, who, and how questions."""
|
35
35
|
|
36
|
-
goals: List[str] = Field(
|
36
|
+
goals: List[str] = Field(default_factory=list)
|
37
37
|
"""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."""
|
38
38
|
|
39
39
|
namespace: List[str] = Field(default_factory=list)
|
@@ -65,7 +65,7 @@ class Task[T](WithBriefing, ProposedAble, WithDependency):
|
|
65
65
|
|
66
66
|
def model_post_init(self, __context: Any) -> None:
|
67
67
|
"""Initialize the task with a namespace event."""
|
68
|
-
self._namespace.
|
68
|
+
self._namespace.concat(self.namespace)
|
69
69
|
|
70
70
|
def move_to(self, new_namespace: EventLike) -> Self:
|
71
71
|
"""Move the task to a new namespace.
|
@@ -266,7 +266,7 @@ class Task[T](WithBriefing, ProposedAble, WithDependency):
|
|
266
266
|
str: The briefing of the task.
|
267
267
|
"""
|
268
268
|
return TEMPLATE_MANAGER.render_template(
|
269
|
-
|
269
|
+
CONFIG.templates.task_briefing_template,
|
270
270
|
self.model_dump(),
|
271
271
|
)
|
272
272
|
|
fabricatio/models/tool.py
CHANGED
@@ -10,11 +10,12 @@ from inspect import iscoroutinefunction, signature
|
|
10
10
|
from types import CodeType, ModuleType
|
11
11
|
from typing import Any, Callable, Dict, List, Optional, Self, cast, overload
|
12
12
|
|
13
|
-
from fabricatio.
|
13
|
+
from fabricatio.rust import CONFIG
|
14
|
+
from pydantic import BaseModel, ConfigDict, Field
|
15
|
+
|
14
16
|
from fabricatio.decorators import logging_execution_info, use_temp_module
|
15
17
|
from fabricatio.journal import logger
|
16
18
|
from fabricatio.models.generic import WithBriefing
|
17
|
-
from pydantic import BaseModel, ConfigDict, Field
|
18
19
|
|
19
20
|
|
20
21
|
class Tool[**P, R](WithBriefing):
|
@@ -210,7 +211,7 @@ class ToolExecutor(BaseModel):
|
|
210
211
|
M: The module with injected tools.
|
211
212
|
"""
|
212
213
|
module = module or cast(
|
213
|
-
"M", module_from_spec(spec=ModuleSpec(name=
|
214
|
+
"M", module_from_spec(spec=ModuleSpec(name=CONFIG.toolbox.tool_module_name, loader=None))
|
214
215
|
)
|
215
216
|
for tool in self.candidates:
|
216
217
|
logger.debug(f"Injecting tool: {tool.name}")
|
@@ -229,7 +230,7 @@ class ToolExecutor(BaseModel):
|
|
229
230
|
M: The module with injected data.
|
230
231
|
"""
|
231
232
|
module = module or cast(
|
232
|
-
'M', module_from_spec(spec=ModuleSpec(name=
|
233
|
+
'M', module_from_spec(spec=ModuleSpec(name=CONFIG.toolbox.data_module_name, loader=None))
|
233
234
|
)
|
234
235
|
for key, value in self.data.items():
|
235
236
|
logger.debug(f"Injecting data: {key}")
|