fabricatio 0.3.13__cp312-cp312-manylinux_2_34_x86_64.whl → 0.3.14.dev1__cp312-cp312-manylinux_2_34_x86_64.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 +2 -8
- fabricatio/journal.py +0 -3
- fabricatio/models/action.py +6 -21
- fabricatio/models/generic.py +7 -6
- fabricatio/models/kwargs_types.py +1 -46
- fabricatio/models/role.py +41 -25
- fabricatio/models/usages.py +12 -5
- fabricatio/rust.cpython-312-x86_64-linux-gnu.so +0 -0
- fabricatio/rust.pyi +2 -2
- fabricatio/utils.py +69 -4
- {fabricatio-0.3.13.data → fabricatio-0.3.14.dev1.data}/scripts/tdown +0 -0
- {fabricatio-0.3.13.data → fabricatio-0.3.14.dev1.data}/scripts/ttm +0 -0
- {fabricatio-0.3.13.dist-info → fabricatio-0.3.14.dev1.dist-info}/METADATA +7 -7
- {fabricatio-0.3.13.dist-info → fabricatio-0.3.14.dev1.dist-info}/RECORD +16 -16
- {fabricatio-0.3.13.dist-info → fabricatio-0.3.14.dev1.dist-info}/WHEEL +0 -0
- {fabricatio-0.3.13.dist-info → fabricatio-0.3.14.dev1.dist-info}/licenses/LICENSE +0 -0
fabricatio/__init__.py
CHANGED
@@ -2,35 +2,29 @@
|
|
2
2
|
|
3
3
|
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, BibManager, Event
|
4
4
|
|
5
|
-
from fabricatio import actions, capabilities, toolboxes, workflows
|
6
|
-
from fabricatio.core import env
|
5
|
+
from fabricatio import actions, capabilities, parser, toolboxes, workflows
|
7
6
|
from fabricatio.journal import logger
|
8
7
|
from fabricatio.models import extra
|
9
8
|
from fabricatio.models.action import Action, WorkFlow
|
10
9
|
from fabricatio.models.role import Role
|
11
10
|
from fabricatio.models.task import Task
|
12
11
|
from fabricatio.models.tool import ToolBox
|
13
|
-
from fabricatio.parser import Capture, GenericCapture, JsonCapture, PythonCapture
|
14
12
|
|
15
13
|
__all__ = [
|
16
14
|
"CONFIG",
|
17
15
|
"TEMPLATE_MANAGER",
|
18
16
|
"Action",
|
19
17
|
"BibManager",
|
20
|
-
"Capture",
|
21
18
|
"Event",
|
22
|
-
"GenericCapture",
|
23
|
-
"JsonCapture",
|
24
|
-
"PythonCapture",
|
25
19
|
"Role",
|
26
20
|
"Task",
|
27
21
|
"ToolBox",
|
28
22
|
"WorkFlow",
|
29
23
|
"actions",
|
30
24
|
"capabilities",
|
31
|
-
"env",
|
32
25
|
"extra",
|
33
26
|
"logger",
|
27
|
+
"parser",
|
34
28
|
"toolboxes",
|
35
29
|
"workflows",
|
36
30
|
]
|
fabricatio/journal.py
CHANGED
fabricatio/models/action.py
CHANGED
@@ -12,14 +12,13 @@ Classes:
|
|
12
12
|
import traceback
|
13
13
|
from abc import abstractmethod
|
14
14
|
from asyncio import Queue, create_task
|
15
|
-
from typing import Any, ClassVar, Dict, Self, Sequence, Tuple, Type, Union, final
|
15
|
+
from typing import Any, ClassVar, Dict, Generator, Self, Sequence, Tuple, Type, Union, final
|
16
16
|
|
17
17
|
from pydantic import Field, PrivateAttr
|
18
18
|
|
19
19
|
from fabricatio.journal import logger
|
20
20
|
from fabricatio.models.generic import WithBriefing
|
21
21
|
from fabricatio.models.task import Task
|
22
|
-
from fabricatio.models.usages import ToolBoxUsage
|
23
22
|
from fabricatio.utils import override_kwargs
|
24
23
|
|
25
24
|
OUTPUT_KEY = "task_output"
|
@@ -106,7 +105,7 @@ class Action(WithBriefing):
|
|
106
105
|
return self
|
107
106
|
|
108
107
|
|
109
|
-
class WorkFlow(WithBriefing
|
108
|
+
class WorkFlow(WithBriefing):
|
110
109
|
"""Manages sequences of actions to fulfill tasks.
|
111
110
|
|
112
111
|
Handles context propagation between actions, error handling, and task lifecycle
|
@@ -148,6 +147,10 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
148
147
|
# Convert any action classes to instances
|
149
148
|
self._instances = tuple(step if isinstance(step, Action) else step() for step in self.steps)
|
150
149
|
|
150
|
+
def iter_actions(self) -> Generator[Action, None, None]:
|
151
|
+
"""Iterate over action instances."""
|
152
|
+
yield from self._instances
|
153
|
+
|
151
154
|
def inject_personality(self, personality: str) -> Self:
|
152
155
|
"""Set personality for actions without existing personality.
|
153
156
|
|
@@ -249,24 +252,6 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
249
252
|
|
250
253
|
await self._context.put({self.task_input_key: task, **ctx})
|
251
254
|
|
252
|
-
def steps_fallback_to_self(self) -> Self:
|
253
|
-
"""Configure all steps to use this workflow's configuration as fallback.
|
254
|
-
|
255
|
-
Returns:
|
256
|
-
Self: The workflow instance for method chaining.
|
257
|
-
"""
|
258
|
-
self.hold_to(self._instances)
|
259
|
-
return self
|
260
|
-
|
261
|
-
def steps_supply_tools_from_self(self) -> Self:
|
262
|
-
"""Provide this workflow's tools to all steps in the workflow.
|
263
|
-
|
264
|
-
Returns:
|
265
|
-
Self: The workflow instance for method chaining.
|
266
|
-
"""
|
267
|
-
self.provide_tools_to(i for i in self._instances if isinstance(i, ToolBoxUsage))
|
268
|
-
return self
|
269
|
-
|
270
255
|
def update_init_context(self, /, **kwargs) -> Self:
|
271
256
|
"""Update the initial context with additional key-value pairs.
|
272
257
|
|
fabricatio/models/generic.py
CHANGED
@@ -7,12 +7,10 @@ from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Self,
|
|
7
7
|
|
8
8
|
import ujson
|
9
9
|
from fabricatio.rust import CONFIG, TEMPLATE_MANAGER, blake3_hash, detect_language
|
10
|
-
from litellm.utils import token_counter
|
11
10
|
from pydantic import (
|
12
11
|
BaseModel,
|
13
12
|
ConfigDict,
|
14
13
|
Field,
|
15
|
-
HttpUrl,
|
16
14
|
NonNegativeFloat,
|
17
15
|
PositiveFloat,
|
18
16
|
PositiveInt,
|
@@ -24,7 +22,6 @@ from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
|
|
24
22
|
from fabricatio.fs import dump_text
|
25
23
|
from fabricatio.fs.readers import safe_text_read
|
26
24
|
from fabricatio.journal import logger
|
27
|
-
from fabricatio.parser import JsonCapture
|
28
25
|
from fabricatio.utils import ok
|
29
26
|
|
30
27
|
|
@@ -497,6 +494,8 @@ class InstantiateFromString(Base):
|
|
497
494
|
Returns:
|
498
495
|
Self | None: The instance of the class or None if the string is not valid.
|
499
496
|
"""
|
497
|
+
from fabricatio.parser import JsonCapture
|
498
|
+
|
500
499
|
obj = JsonCapture.convert_with(string, cls.model_validate_json)
|
501
500
|
logger.debug(f"Instantiate `{cls.__name__}` from string, {'Failed' if obj is None else 'Success'}.")
|
502
501
|
return obj
|
@@ -666,6 +665,8 @@ class Vectorizable:
|
|
666
665
|
Raises:
|
667
666
|
ValueError: If the chunk exceeds the maximum sequence length.
|
668
667
|
"""
|
668
|
+
from litellm.utils import token_counter
|
669
|
+
|
669
670
|
max_length = max_length or CONFIG.embedding.max_sequence_length
|
670
671
|
chunk = self._prepare_vectorization_inner()
|
671
672
|
if max_length and (length := token_counter(text=chunk)) > max_length:
|
@@ -681,7 +682,7 @@ class ScopedConfig(Base):
|
|
681
682
|
Allows configuration values to be overridden in a hierarchical manner.
|
682
683
|
"""
|
683
684
|
|
684
|
-
llm_api_endpoint: Optional[
|
685
|
+
llm_api_endpoint: Optional[str] = None
|
685
686
|
"""The OpenAI API endpoint."""
|
686
687
|
|
687
688
|
llm_api_key: Optional[SecretStr] = None
|
@@ -726,7 +727,7 @@ class ScopedConfig(Base):
|
|
726
727
|
llm_frequency_penalty: Optional[PositiveFloat] = None
|
727
728
|
"""The frequency penalty of the LLM model."""
|
728
729
|
|
729
|
-
embedding_api_endpoint: Optional[
|
730
|
+
embedding_api_endpoint: Optional[str] = None
|
730
731
|
"""The OpenAI API endpoint."""
|
731
732
|
|
732
733
|
embedding_api_key: Optional[SecretStr] = None
|
@@ -747,7 +748,7 @@ class ScopedConfig(Base):
|
|
747
748
|
embedding_caching: Optional[bool] = False
|
748
749
|
"""Whether to cache the embedding result."""
|
749
750
|
|
750
|
-
milvus_uri: Optional[
|
751
|
+
milvus_uri: Optional[str] = Field(default=None)
|
751
752
|
"""The URI of the Milvus server."""
|
752
753
|
|
753
754
|
milvus_token: Optional[SecretStr] = Field(default=None)
|
@@ -1,9 +1,6 @@
|
|
1
1
|
"""This module contains the types for the keyword arguments of the methods in the models module."""
|
2
2
|
|
3
|
-
from typing import
|
4
|
-
|
5
|
-
from litellm.caching.caching import CacheMode
|
6
|
-
from litellm.types.caching import CachingSupportedCallTypes
|
3
|
+
from typing import Dict, List, Literal, NotRequired, Optional, Required, TypedDict
|
7
4
|
|
8
5
|
|
9
6
|
class ChunkKwargs(TypedDict):
|
@@ -70,7 +67,6 @@ class ValidateKwargs[T](GenerateKwargs, total=False):
|
|
70
67
|
max_validations: int
|
71
68
|
|
72
69
|
|
73
|
-
|
74
70
|
class CompositeScoreKwargs(ValidateKwargs[List[Dict[str, float]]], total=False):
|
75
71
|
"""Arguments for composite score generation operations.
|
76
72
|
|
@@ -125,47 +121,6 @@ class ChooseKwargs[T](ValidateKwargs[T], total=False):
|
|
125
121
|
k: int
|
126
122
|
|
127
123
|
|
128
|
-
class CacheKwargs(TypedDict, total=False):
|
129
|
-
"""Configuration parameters for the caching system.
|
130
|
-
|
131
|
-
These arguments control the behavior of various caching backends,
|
132
|
-
including in-memory, Redis, S3, and vector database caching options.
|
133
|
-
"""
|
134
|
-
|
135
|
-
mode: CacheMode # when default_on cache is always on, when default_off cache is opt in
|
136
|
-
host: str
|
137
|
-
port: str
|
138
|
-
password: str
|
139
|
-
namespace: str
|
140
|
-
ttl: float
|
141
|
-
default_in_memory_ttl: float
|
142
|
-
default_in_redis_ttl: float
|
143
|
-
similarity_threshold: float
|
144
|
-
supported_call_types: list[CachingSupportedCallTypes]
|
145
|
-
# s3 Bucket, boto3 configuration
|
146
|
-
s3_bucket_name: str
|
147
|
-
s3_region_name: str
|
148
|
-
s3_api_version: str
|
149
|
-
s3_use_ssl: bool
|
150
|
-
s3_verify: bool | str
|
151
|
-
s3_endpoint_url: str
|
152
|
-
s3_aws_access_key_id: str
|
153
|
-
s3_aws_secret_access_key: str
|
154
|
-
s3_aws_session_token: str
|
155
|
-
s3_config: Any
|
156
|
-
s3_path: str
|
157
|
-
redis_semantic_cache_use_async: bool
|
158
|
-
redis_semantic_cache_embedding_model: str
|
159
|
-
redis_flush_size: int
|
160
|
-
redis_startup_nodes: list
|
161
|
-
disk_cache_dir: Any
|
162
|
-
qdrant_api_base: str
|
163
|
-
qdrant_api_key: str
|
164
|
-
qdrant_collection_name: str
|
165
|
-
qdrant_quantization_config: str
|
166
|
-
qdrant_semantic_cache_embedding_model: str
|
167
|
-
|
168
|
-
|
169
124
|
class RerankOptions(TypedDict, total=False):
|
170
125
|
"""Optional keyword arguments for the rerank method."""
|
171
126
|
|
fabricatio/models/role.py
CHANGED
@@ -1,40 +1,35 @@
|
|
1
1
|
"""Module that contains the Role class for managing workflows and their event registrations."""
|
2
|
-
|
3
|
-
from typing import Any,
|
2
|
+
from functools import partial
|
3
|
+
from typing import Any, Dict, Self
|
4
4
|
|
5
5
|
from fabricatio.rust import Event
|
6
|
-
from pydantic import
|
6
|
+
from pydantic import ConfigDict, Field
|
7
7
|
|
8
|
-
from fabricatio.capabilities.propose import Propose
|
9
8
|
from fabricatio.core import env
|
10
9
|
from fabricatio.journal import logger
|
11
10
|
from fabricatio.models.action import WorkFlow
|
12
11
|
from fabricatio.models.generic import WithBriefing
|
13
|
-
from fabricatio.
|
14
|
-
|
12
|
+
from fabricatio.utils import is_subclass_of_base
|
13
|
+
|
14
|
+
is_toolbox_usage = partial(is_subclass_of_base, base_module="fabricatio.models.usages",
|
15
|
+
base_name="ToolBoxUsage")
|
16
|
+
is_scoped_config = partial(is_subclass_of_base, base_module="fabricatio.models.generic",
|
17
|
+
base_name="ScopedConfig")
|
15
18
|
|
16
19
|
|
17
|
-
class Role(WithBriefing
|
20
|
+
class Role(WithBriefing):
|
18
21
|
"""Class that represents a role with a registry of events and workflows.
|
19
22
|
|
20
23
|
A Role serves as a container for workflows, managing their registration to events
|
21
24
|
and providing them with shared configuration like tools and personality.
|
22
|
-
|
23
|
-
Attributes:
|
24
|
-
registry: Mapping of events to workflows that handle them
|
25
|
-
toolboxes: Set of toolboxes available to this role and its workflows
|
26
25
|
"""
|
27
|
-
# fixme: not use arbitrary_types_allowed
|
28
26
|
model_config = ConfigDict(use_attribute_docstrings=True, arbitrary_types_allowed=True)
|
29
27
|
description: str = ""
|
30
28
|
"""A brief description of the role's responsibilities and capabilities."""
|
31
29
|
|
32
|
-
registry:
|
30
|
+
registry: Dict[Event, WorkFlow] = Field(default_factory=dict)
|
33
31
|
"""The registry of events and workflows."""
|
34
32
|
|
35
|
-
toolboxes: Set[ToolBox] = Field(default_factory=set)
|
36
|
-
"""Collection of tools available to this role."""
|
37
|
-
|
38
33
|
def model_post_init(self, __context: Any) -> None:
|
39
34
|
"""Initialize the role by resolving configurations and registering workflows.
|
40
35
|
|
@@ -51,7 +46,7 @@ class Role(WithBriefing, Propose, ToolBoxUsage):
|
|
51
46
|
"""
|
52
47
|
for event, workflow in self.registry.items():
|
53
48
|
logger.debug(
|
54
|
-
f"Registering workflow: `{workflow.name}` for event: `{
|
49
|
+
f"Registering workflow: `{workflow.name}` for event: `{event.collapse()}`"
|
55
50
|
)
|
56
51
|
env.on(event, workflow.serve)
|
57
52
|
return self
|
@@ -67,12 +62,33 @@ class Role(WithBriefing, Propose, ToolBoxUsage):
|
|
67
62
|
"""
|
68
63
|
for workflow in self.registry.values():
|
69
64
|
logger.debug(f"Resolving config for workflow: `{workflow.name}`")
|
70
|
-
(
|
71
|
-
|
72
|
-
|
73
|
-
.inject_personality(self.briefing)
|
74
|
-
.supply_tools_from(self)
|
75
|
-
.steps_supply_tools_from_self()
|
76
|
-
)
|
77
|
-
|
65
|
+
self._configure_scoped_config(workflow)
|
66
|
+
self._configure_toolbox_usage(workflow)
|
67
|
+
workflow.inject_personality(self.briefing)
|
78
68
|
return self
|
69
|
+
|
70
|
+
def _configure_scoped_config(self, workflow) -> None:
|
71
|
+
"""Configure scoped configuration for workflow and its actions."""
|
72
|
+
if not is_scoped_config(self.__class__):
|
73
|
+
return
|
74
|
+
|
75
|
+
fallback_target = self
|
76
|
+
if is_scoped_config(workflow):
|
77
|
+
workflow.fallback_to(self)
|
78
|
+
fallback_target = workflow
|
79
|
+
|
80
|
+
for action in (a for a in workflow.iter_actions() if is_scoped_config(a)):
|
81
|
+
action.fallback_to(fallback_target)
|
82
|
+
|
83
|
+
def _configure_toolbox_usage(self, workflow) -> None:
|
84
|
+
"""Configure toolbox usage for workflow and its actions."""
|
85
|
+
if not is_toolbox_usage(self.__class__):
|
86
|
+
return
|
87
|
+
|
88
|
+
supply_target = self
|
89
|
+
if is_toolbox_usage(workflow):
|
90
|
+
workflow.supply_tools_from(self)
|
91
|
+
supply_target = workflow
|
92
|
+
|
93
|
+
for action in (a for a in workflow.iter_actions() if is_toolbox_usage(a)):
|
94
|
+
action.supply_tools_from(supply_target)
|
fabricatio/models/usages.py
CHANGED
@@ -26,8 +26,7 @@ from fabricatio.models.generic import ScopedConfig, WithBriefing
|
|
26
26
|
from fabricatio.models.kwargs_types import ChooseKwargs, EmbeddingKwargs, GenerateKwargs, LLMKwargs, ValidateKwargs
|
27
27
|
from fabricatio.models.task import Task
|
28
28
|
from fabricatio.models.tool import Tool, ToolBox
|
29
|
-
from fabricatio.
|
30
|
-
from fabricatio.utils import ok
|
29
|
+
from fabricatio.utils import first_available, ok
|
31
30
|
|
32
31
|
ROUTER = Router(
|
33
32
|
routing_strategy="usage-based-routing-v2",
|
@@ -91,7 +90,7 @@ class LLMUsage(ScopedConfig):
|
|
91
90
|
api_base=ok(
|
92
91
|
self.llm_api_endpoint or CONFIG.llm.api_endpoint,
|
93
92
|
"llm api endpoint is not set at any place",
|
94
|
-
)
|
93
|
+
),
|
95
94
|
model=m_name,
|
96
95
|
tpm=self.llm_tpm or CONFIG.llm.tpm,
|
97
96
|
rpm=self.llm_rpm or CONFIG.llm.rpm,
|
@@ -109,7 +108,8 @@ class LLMUsage(ScopedConfig):
|
|
109
108
|
stop=kwargs.get("stop") or self.llm_stop_sign or CONFIG.llm.stop_sign,
|
110
109
|
top_p=kwargs.get("top_p") or self.llm_top_p or CONFIG.llm.top_p,
|
111
110
|
max_tokens=kwargs.get("max_tokens") or self.llm_max_tokens or CONFIG.llm.max_tokens,
|
112
|
-
stream=
|
111
|
+
stream=first_available((kwargs.get("stream"), self.llm_stream, CONFIG.llm.stream),
|
112
|
+
"stream is not set at any place"),
|
113
113
|
cache={
|
114
114
|
"no-cache": kwargs.get("no_cache"),
|
115
115
|
"no-store": kwargs.get("no_store"),
|
@@ -337,6 +337,8 @@ class LLMUsage(ScopedConfig):
|
|
337
337
|
Returns:
|
338
338
|
Optional[List[str]]: The validated response as a list of strings.
|
339
339
|
"""
|
340
|
+
from fabricatio.parser import JsonCapture
|
341
|
+
|
340
342
|
return await self.aask_validate(
|
341
343
|
TEMPLATE_MANAGER.render_template(
|
342
344
|
CONFIG.templates.liststr_template,
|
@@ -393,6 +395,8 @@ class LLMUsage(ScopedConfig):
|
|
393
395
|
Returns:
|
394
396
|
Optional[str]: The generated string.
|
395
397
|
"""
|
398
|
+
from fabricatio.parser import GenericCapture
|
399
|
+
|
396
400
|
return await self.aask_validate( # pyright: ignore [reportReturnType]
|
397
401
|
TEMPLATE_MANAGER.render_template(
|
398
402
|
CONFIG.templates.generic_string_template,
|
@@ -420,6 +424,8 @@ class LLMUsage(ScopedConfig):
|
|
420
424
|
Returns:
|
421
425
|
Optional[List[T]]: The final validated selection result list, with element types matching the input `choices`.
|
422
426
|
"""
|
427
|
+
from fabricatio.parser import JsonCapture
|
428
|
+
|
423
429
|
if dup := duplicates_everseen(choices, key=lambda x: x.name):
|
424
430
|
logger.error(err := f"Redundant choices: {dup}")
|
425
431
|
raise ValueError(err)
|
@@ -495,6 +501,8 @@ class LLMUsage(ScopedConfig):
|
|
495
501
|
Returns:
|
496
502
|
bool: The judgment result (True or False) based on the AI's response.
|
497
503
|
"""
|
504
|
+
from fabricatio.parser import JsonCapture
|
505
|
+
|
498
506
|
return await self.aask_validate(
|
499
507
|
question=TEMPLATE_MANAGER.render_template(
|
500
508
|
CONFIG.templates.make_judgment_template,
|
@@ -556,7 +564,6 @@ class EmbeddingUsage(LLMUsage):
|
|
556
564
|
or self.llm_api_endpoint
|
557
565
|
or CONFIG.llm.api_endpoint
|
558
566
|
)
|
559
|
-
.unicode_string()
|
560
567
|
.rstrip("/"),
|
561
568
|
# seems embedding function takes no base_url end with a slash
|
562
569
|
)
|
Binary file
|
fabricatio/rust.pyi
CHANGED
@@ -11,7 +11,7 @@ Key Features:
|
|
11
11
|
- Text utilities: Word boundary splitting and word counting.
|
12
12
|
"""
|
13
13
|
from enum import StrEnum
|
14
|
-
from typing import Any, Dict, List, Optional, Self, Tuple,
|
14
|
+
from typing import Any, Dict, List, Optional, Self, Tuple, Union, overload
|
15
15
|
|
16
16
|
from pydantic import JsonValue
|
17
17
|
|
@@ -724,7 +724,7 @@ class SecretStr:
|
|
724
724
|
|
725
725
|
def __init__(self, source: str) -> None: ...
|
726
726
|
|
727
|
-
def
|
727
|
+
def get_secret_value(self) -> str:
|
728
728
|
"""Expose the secret string."""
|
729
729
|
|
730
730
|
|
fabricatio/utils.py
CHANGED
@@ -1,15 +1,46 @@
|
|
1
1
|
"""A collection of utility functions for the fabricatio package."""
|
2
2
|
|
3
|
-
from typing import Any, Dict, List, Mapping, Optional, TypedDict, Unpack, overload
|
4
|
-
|
5
|
-
import aiohttp
|
6
|
-
import requests
|
3
|
+
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Type, TypedDict, Unpack, overload
|
7
4
|
|
8
5
|
from fabricatio.decorators import precheck_package
|
9
6
|
from fabricatio.journal import logger
|
10
7
|
from fabricatio.models.kwargs_types import RerankOptions
|
11
8
|
|
12
9
|
|
10
|
+
def is_subclass_of_base(cls: Type, base_module: str, base_name: str) -> bool:
|
11
|
+
"""Determines if the given class is a subclass of an unimported base class.
|
12
|
+
|
13
|
+
Args:
|
14
|
+
cls: The class to check
|
15
|
+
base_module: The module name of the base class
|
16
|
+
base_name: The class name of the base class
|
17
|
+
|
18
|
+
Returns:
|
19
|
+
bool: True if cls is a subclass of the specified base class, False otherwise
|
20
|
+
"""
|
21
|
+
for ancestor in cls.__mro__:
|
22
|
+
if ancestor.__module__ == base_module and ancestor.__name__ == base_name:
|
23
|
+
return True
|
24
|
+
return False
|
25
|
+
|
26
|
+
|
27
|
+
def is_subclass_of_any_base(cls: Type, bases: List[Tuple[str, str]]) -> bool:
|
28
|
+
"""Determines if the given class is a subclass of the candidate base classes.
|
29
|
+
|
30
|
+
Args:
|
31
|
+
cls: The class to check
|
32
|
+
bases: A list of tuples where each tuple contains (module_name, class_name)
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
bool: True if cls is a subclass of the specified base classes, False otherwise
|
36
|
+
"""
|
37
|
+
for ancestor in cls.__mro__:
|
38
|
+
for base_module, base_name in bases:
|
39
|
+
if ancestor.__module__ == base_module and ancestor.__name__ == base_name:
|
40
|
+
return True
|
41
|
+
return False
|
42
|
+
|
43
|
+
|
13
44
|
@precheck_package(
|
14
45
|
"questionary", "'questionary' is required to run this function. Have you installed `fabricatio[qa]`?."
|
15
46
|
)
|
@@ -85,6 +116,37 @@ def ok[T](val: Optional[T], msg: str = "Value is None") -> T:
|
|
85
116
|
return val
|
86
117
|
|
87
118
|
|
119
|
+
def first_available[T](iterable: Iterable[T], msg: str = "No available item found in the iterable.") -> T:
|
120
|
+
"""Return the first available item in the iterable that's not None.
|
121
|
+
|
122
|
+
This function searches through the provided iterable and returns the first
|
123
|
+
item that is not None. If all items are None or the iterable is empty,
|
124
|
+
it raises a ValueError.
|
125
|
+
|
126
|
+
Args:
|
127
|
+
iterable: The iterable collection to search through.
|
128
|
+
msg: The message to include in the ValueError if no non-None item is found.
|
129
|
+
|
130
|
+
Returns:
|
131
|
+
T: The first non-None item found in the iterable.
|
132
|
+
If no non-None item is found, it raises a ValueError.
|
133
|
+
|
134
|
+
Raises:
|
135
|
+
ValueError: If no non-None item is found in the iterable.
|
136
|
+
|
137
|
+
Examples:
|
138
|
+
>>> first_available([None, None, "value", "another"])
|
139
|
+
'value'
|
140
|
+
>>> first_available([1, 2, 3])
|
141
|
+
1
|
142
|
+
>>> assert (first_available([None, None]))
|
143
|
+
ValueError: No available item found in the iterable.
|
144
|
+
"""
|
145
|
+
if (first := next((item for item in iterable if item is not None), None)) is not None:
|
146
|
+
return first
|
147
|
+
raise ValueError(msg)
|
148
|
+
|
149
|
+
|
88
150
|
def wrapp_in_block(string: str, title: str, style: str = "-") -> str:
|
89
151
|
"""Wraps a string in a block with a title.
|
90
152
|
|
@@ -164,6 +226,7 @@ class RerankerAPI:
|
|
164
226
|
ValueError: If input parameters are invalid or the API returns a client-side error.
|
165
227
|
RuntimeError: If the API call fails or returns a server-side error.
|
166
228
|
"""
|
229
|
+
import requests
|
167
230
|
# Validate inputs
|
168
231
|
if not isinstance(query, str) or not query.strip():
|
169
232
|
raise ValueError("Query must be a non-empty string.")
|
@@ -219,6 +282,8 @@ class RerankerAPI:
|
|
219
282
|
ValueError: If input parameters are invalid or the API returns a client-side error.
|
220
283
|
RuntimeError: If the API call fails or returns a server-side error.
|
221
284
|
"""
|
285
|
+
import aiohttp
|
286
|
+
|
222
287
|
# Validate inputs
|
223
288
|
if not isinstance(query, str) or not query.strip():
|
224
289
|
raise ValueError("Query must be a non-empty string.")
|
Binary file
|
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fabricatio
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.14.dev1
|
4
4
|
Classifier: License :: OSI Approved :: MIT License
|
5
5
|
Classifier: Programming Language :: Rust
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -86,7 +86,7 @@ make bdist
|
|
86
86
|
|
87
87
|
```python
|
88
88
|
import asyncio
|
89
|
-
from fabricatio import Action, Role, Task, logger, WorkFlow
|
89
|
+
from fabricatio import Action, Role, Task, logger, WorkFlow, Event
|
90
90
|
from typing import Any
|
91
91
|
|
92
92
|
|
@@ -101,14 +101,14 @@ class Hello(Action):
|
|
101
101
|
|
102
102
|
|
103
103
|
async def main() -> None:
|
104
|
-
|
104
|
+
Role(
|
105
105
|
name="talker",
|
106
106
|
description="talker role",
|
107
|
-
registry={
|
107
|
+
registry={Event.quick_instantiate("talk"): WorkFlow(name="talk", steps=(Hello,))}
|
108
108
|
)
|
109
109
|
|
110
|
-
task = Task(name="say hello", goals="say hello", description="say hello to the world")
|
111
|
-
result = await task.delegate()
|
110
|
+
task = Task(name="say hello", goals=["say hello"], description="say hello to the world")
|
111
|
+
result = await task.delegate("talk")
|
112
112
|
logger.success(f"Result: {result}")
|
113
113
|
|
114
114
|
|
@@ -163,11 +163,11 @@ max_tokens = 8192
|
|
163
163
|
```bash
|
164
164
|
make test
|
165
165
|
```
|
166
|
+
|
166
167
|
## TODO
|
167
168
|
|
168
169
|
- Add an element based format strategy
|
169
170
|
|
170
|
-
|
171
171
|
## Contributing
|
172
172
|
|
173
173
|
Contributions are welcome! Follow these steps:
|
@@ -1,6 +1,6 @@
|
|
1
|
-
fabricatio-0.3.
|
2
|
-
fabricatio-0.3.
|
3
|
-
fabricatio-0.3.
|
1
|
+
fabricatio-0.3.14.dev1.dist-info/METADATA,sha256=5QIUicxysjjn6QSz0GU63RK1HcmkwBuIZ0-Ukf8VAao,5120
|
2
|
+
fabricatio-0.3.14.dev1.dist-info/WHEEL,sha256=7FgAcpQES0h1xhfN9Ugve9FTUilU6sRAr1WJ5ph2cuw,108
|
3
|
+
fabricatio-0.3.14.dev1.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
|
4
4
|
fabricatio/capabilities/check.py,sha256=lKCSWVe_mmwi8pZaQx1KZ8TOWuVhGAySUxGH8slXojY,8451
|
5
5
|
fabricatio/capabilities/propose.py,sha256=vOJvmmnMBHUQB6N1AmZNFw42jf7Bl2mBRNlBK15TpNI,1942
|
6
6
|
fabricatio/capabilities/correct.py,sha256=S9fGdir8LlbmBj68pDunohjJ14ssfJrQfy9HagdFm6Y,10217
|
@@ -14,7 +14,7 @@ fabricatio/capabilities/advanced_judge.py,sha256=bvb8fYoiKoGlBwMZVMflVE9R2MoS1Vt
|
|
14
14
|
fabricatio/capabilities/review.py,sha256=oBbtrdX7U2brHSKJjROt2kXxJEJVEsedKH1DBcP0Xfc,4947
|
15
15
|
fabricatio/capabilities/__init__.py,sha256=skaJ43CqAQaZMH-mCRzF4Fps3x99P2SwJ8vSM9pInX8,56
|
16
16
|
fabricatio/parser.py,sha256=fFuVZJDhYjre3bGan4cCYxAezb33GhLLMSIbvC9mX-E,6479
|
17
|
-
fabricatio/models/action.py,sha256=
|
17
|
+
fabricatio/models/action.py,sha256=EffipgtR8Y2pz_ZDdXmbV3nMg2FMx9x6y2ytKHD4avM,9819
|
18
18
|
fabricatio/models/extra/article_outline.py,sha256=K3Ajb86JQSsjo61briVCkIJkqRwvJ46uNU94NCrW-cY,1584
|
19
19
|
fabricatio/models/extra/article_essence.py,sha256=zUfZ2_bX3h__RaVPwJlxQ-tkFyfSV8SdX8DsmFX6v_w,2649
|
20
20
|
fabricatio/models/extra/article_main.py,sha256=hr3MK_1D87DHv_kopvdRvXfQETbeJUMiknO2kVs8lzs,10937
|
@@ -27,16 +27,16 @@ fabricatio/models/extra/patches.py,sha256=_ghmnlvTZQq7UJyaH77mTZE9abjvxRJ2mgWHUb
|
|
27
27
|
fabricatio/models/extra/advanced_judge.py,sha256=CKPP4Lseb_Ey8Y7i2V9HJfB-mZgCknFdqq7Zo41o6s4,1060
|
28
28
|
fabricatio/models/extra/aricle_rag.py,sha256=3gxl5_j6-BGsUTwyY6a5m2CMaWJTp9aT79OEuev9GQU,11426
|
29
29
|
fabricatio/models/extra/__init__.py,sha256=0R9eZsCNu6OV-Xtf15H7FrqhfHTFBFf3fBrcd7ChsJ0,53
|
30
|
-
fabricatio/models/usages.py,sha256=
|
31
|
-
fabricatio/models/generic.py,sha256=
|
30
|
+
fabricatio/models/usages.py,sha256=xCJK-k4DWywHv5E-P2bfCbyK-47eeZLM4ldX0Iguc8E,32845
|
31
|
+
fabricatio/models/generic.py,sha256=t9iigj64ibxPkVPKL3QQd3bDXPQ3AYbjaBEJpTDkJqs,29513
|
32
32
|
fabricatio/models/adv_kwargs_types.py,sha256=nmj1D0GVosZxKcdiw-B5vJB04Whr5zh30ZBJntSZUpY,2034
|
33
|
-
fabricatio/models/role.py,sha256=
|
33
|
+
fabricatio/models/role.py,sha256=JqD4uIK5qe1OTmuH-t7erhSWNM_FqWcE73dm6bXQ5pg,3712
|
34
34
|
fabricatio/models/task.py,sha256=KkEanhH4JSUmnevoxsR4LF23NOdQ5Zj_065pxgSsuW4,10721
|
35
|
-
fabricatio/models/kwargs_types.py,sha256=
|
35
|
+
fabricatio/models/kwargs_types.py,sha256=MG2CPM3CiCO-R8aQitTkSyXHKgbqu6ekhIMGHjoRDZg,3490
|
36
36
|
fabricatio/models/tool.py,sha256=tRBOJqX4p_OY5j_dPyTAHvzI15bnTNMePdwLqbi6SOA,12174
|
37
37
|
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
38
|
fabricatio/core.py,sha256=AAbp-mMqhXLs3xpljChLkXuJYH9uAXbUpe05yjASZlc,6306
|
39
|
-
fabricatio/rust.pyi,sha256=
|
39
|
+
fabricatio/rust.pyi,sha256=03K4aeAtgLk19rVDbAzmEPp_rHM-9MSy2BSaOR2yBwM,24365
|
40
40
|
fabricatio/actions/article.py,sha256=ZWPhIoQlwmnvSHypaSDabdEwU67Y5_wx4Jj2w0NKPgE,12308
|
41
41
|
fabricatio/actions/rules.py,sha256=07ILsiwR250AUcKLPHTUPpWD_mPhPCfWKSkEAKcPv3A,3557
|
42
42
|
fabricatio/actions/output.py,sha256=2Yn_wfPq07tvwCBPmuCHoUfL3zJ9oGx6BcOmh3elG_M,8175
|
@@ -54,10 +54,10 @@ fabricatio/workflows/__init__.py,sha256=Lq9pFo2cudwFCrQUUNgSTr1CoU0J1Nw-HNEQN7cH
|
|
54
54
|
fabricatio/toolboxes/arithmetic.py,sha256=sSTPkKI6-mb278DwQKFO9jKyzc9kCx45xNH7V6bGBpE,1307
|
55
55
|
fabricatio/toolboxes/fs.py,sha256=OQMdeokYxSNVrCZJAweJ0cYiK4k2QuEiNdIbS5IHIV8,705
|
56
56
|
fabricatio/toolboxes/__init__.py,sha256=dYm_Gd8XolSU_h4wnkA09dlaLDK146eeFz0CUgPZ8_c,380
|
57
|
-
fabricatio/utils.py,sha256=
|
58
|
-
fabricatio/journal.py,sha256=
|
59
|
-
fabricatio/__init__.py,sha256=
|
60
|
-
fabricatio/rust.cpython-312-x86_64-linux-gnu.so,sha256=
|
61
|
-
fabricatio-0.3.
|
62
|
-
fabricatio-0.3.
|
63
|
-
fabricatio-0.3.
|
57
|
+
fabricatio/utils.py,sha256=FRUJMDcjt0sd9JYsg-mAATTOyKUz9WAot3T97GNIfwk,12420
|
58
|
+
fabricatio/journal.py,sha256=KDUZLV0Nt-yTLkJcyaG_XhwsUxXe0bi-gOwYktkhPZE,203
|
59
|
+
fabricatio/__init__.py,sha256=7tiCIRK78lUy5Lvt-Z74575VrZfUO1t_lN2WtPXKyY4,756
|
60
|
+
fabricatio/rust.cpython-312-x86_64-linux-gnu.so,sha256=xo7QZKAScYEdLcPQE6_vwslqpzKIk-44Xs89xquAOhc,6140296
|
61
|
+
fabricatio-0.3.14.dev1.data/scripts/tdown,sha256=bv9SLueCt6hzDc49AXeBHTX7kC9M_Sxg1rodVLnhH6U,4590160
|
62
|
+
fabricatio-0.3.14.dev1.data/scripts/ttm,sha256=yIlUVWFZNYg4uDBrohdzzmnXXcclkc3B26XkEzloqc0,3920472
|
63
|
+
fabricatio-0.3.14.dev1.dist-info/RECORD,,
|
File without changes
|
File without changes
|