swarmauri-core 0.6.0.dev130__tar.gz → 0.6.0.dev132__tar.gz
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.
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/PKG-INFO +1 -1
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/pyproject.toml +1 -1
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/ComponentBase.py +114 -124
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/README.md +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/README.md +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agent_apis/IAgentCommands.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agent_apis/IAgentRouterCRUD.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agent_apis/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agent_factories/IExportConf.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agent_factories/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgent.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentConversation.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentParser.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentRetrieve.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentSystemContext.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentToolkit.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentVectorStore.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/ICallableChain.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChain.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChainContext.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChainContextLoader.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChainDependencyResolver.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChainFactory.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChainStep.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chunkers/IChunker.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chunkers/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/control_panels/IControlPanel.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/control_panels/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/conversations/IConversation.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/conversations/IMaxSize.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/conversations/ISystemContext.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/conversations/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/dataconnectors/IDataConnector.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/dataconnectors/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/distances/IDistanceSimilarity.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/distances/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/document_stores/IDocumentRetrieve.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/document_stores/IDocumentStore.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/document_stores/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/documents/IDocument.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/documents/IExperimentDocument.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/documents/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/embeddings/IFeature.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/embeddings/ISaveModel.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/embeddings/IVectorize.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/embeddings/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/experiment_stores/IExperimentStore.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/experiment_stores/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/factories/IFactory.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/factories/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/image_gens/IGenImage.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/image_gens/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/llms/IFit.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/llms/IPredict.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/llms/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/measurements/IMeasurement.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/measurements/IMeasurementAggregate.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/measurements/IMeasurementCalculate.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/measurements/IThreshold.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/measurements/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/messages/IMessage.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/messages/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/parsers/IParser.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/parsers/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/pipelines/IPipeline.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/pipelines/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/prompts/IPrompt.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/prompts/IPromptMatrix.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/prompts/ITemplate.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/prompts/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/schema_converters/ISchemaConvert.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/schema_converters/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/service_registries/IServiceRegistry.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/service_registries/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/state/IState.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/swarm_apis/IAgentRegistrationAPI.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/swarm_apis/ISwarmAPI.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/swarm_apis/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/swarms/ISwarm.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/swarms/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/task_mgmt_strategies/ITaskMgmtStrategy.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/task_mgmt_strategies/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/toolkits/IToolkit.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/toolkits/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tools/IParameter.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tools/ITool.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tools/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tracing/IChainTracer.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tracing/ITraceContext.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tracing/ITracer.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tracing/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/transports/ITransport.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/transports/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/utils/ITransactional.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/utils/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vcms/IPredictVision.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vcms/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/ICloudVectorStore.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/IPersistentVectorStore.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/ISimilarity.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/IVectorNorm.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/IVectorStore.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/IVectorStoreRetrieve.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/IVectorStoreSaveLoad.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/__init__.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/IVector.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/IVectorMeta.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/IVectorProduct.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/IVectorTransform.py +0 -0
- {swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/__init__.py +0 -0
|
@@ -21,6 +21,7 @@ from typing import (
|
|
|
21
21
|
Type,
|
|
22
22
|
TypeVar,
|
|
23
23
|
Union,
|
|
24
|
+
Tuple,
|
|
24
25
|
get_args,
|
|
25
26
|
get_origin,
|
|
26
27
|
)
|
|
@@ -28,6 +29,13 @@ from typing import (
|
|
|
28
29
|
logger = logging.getLogger(__name__)
|
|
29
30
|
T = TypeVar("T", bound="ComponentBase")
|
|
30
31
|
|
|
32
|
+
class ResourceType:
|
|
33
|
+
"""
|
|
34
|
+
Metadata class to hold resource type information for Annotated fields.
|
|
35
|
+
"""
|
|
36
|
+
def __init__(self, resource_type: Type['ComponentBase']):
|
|
37
|
+
self.resource_type = resource_type
|
|
38
|
+
|
|
31
39
|
class SubclassUnion(type):
|
|
32
40
|
"""
|
|
33
41
|
A generic class to create discriminated unions based on resource types.
|
|
@@ -45,10 +53,10 @@ class SubclassUnion(type):
|
|
|
45
53
|
registered_classes = list(ComponentBase.TYPE_REGISTRY.get(resource_type, {}).values())
|
|
46
54
|
if not registered_classes:
|
|
47
55
|
logger.debug(f"No subclasses registered for resource type '{resource_type.__name__}'. Using 'Any' as a placeholder.")
|
|
48
|
-
return Annotated[Any, Field(...)]
|
|
56
|
+
return Annotated[Any, Field(...), ResourceType(resource_type)]
|
|
49
57
|
else:
|
|
50
58
|
union_type = Union[tuple(registered_classes)]
|
|
51
|
-
return Annotated[union_type, Field(discriminator='type')]
|
|
59
|
+
return Annotated[union_type, Field(discriminator='type'), ResourceType(resource_type)]
|
|
52
60
|
|
|
53
61
|
class ResourceTypes(Enum):
|
|
54
62
|
UNIVERSAL_BASE = "ComponentBase"
|
|
@@ -229,37 +237,49 @@ class ComponentBase(BaseModel):
|
|
|
229
237
|
@classmethod
|
|
230
238
|
def field_contains_subclass_union(cls, field_annotation) -> bool:
|
|
231
239
|
"""
|
|
232
|
-
Check if the field annotation contains a SubclassUnion.
|
|
240
|
+
Check if the field annotation contains a SubclassUnion or associated ResourceType metadata.
|
|
233
241
|
|
|
234
242
|
Parameters:
|
|
235
243
|
- field_annotation: The type annotation of the field.
|
|
236
244
|
|
|
237
245
|
Returns:
|
|
238
|
-
- True if SubclassUnion is present, False otherwise.
|
|
246
|
+
- True if SubclassUnion or ResourceType is present, False otherwise.
|
|
239
247
|
"""
|
|
240
|
-
logger.debug(f"Checking if field annotation '{field_annotation}' contains a SubclassUnion")
|
|
241
|
-
|
|
248
|
+
logger.debug(f"Checking if field annotation '{field_annotation}' contains a SubclassUnion or ResourceType")
|
|
249
|
+
|
|
250
|
+
origin = get_origin(field_annotation)
|
|
251
|
+
args = get_args(field_annotation)
|
|
252
|
+
|
|
253
|
+
# Check for direct SubclassUnion match
|
|
254
|
+
if inspect.isclass(field_annotation) and issubclass(field_annotation, SubclassUnion):
|
|
242
255
|
logger.debug(f"Field annotation '{field_annotation}' is directly a SubclassUnion")
|
|
243
256
|
return True
|
|
244
|
-
|
|
257
|
+
|
|
258
|
+
# Check for Annotated fields
|
|
245
259
|
if origin is Annotated:
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
260
|
+
for arg in args:
|
|
261
|
+
if isinstance(arg, ResourceType):
|
|
262
|
+
logger.debug(f"Annotated field contains ResourceType metadata for resource '{arg.resource_type.__name__}'")
|
|
263
|
+
return True
|
|
264
|
+
if cls.field_contains_subclass_union(arg):
|
|
265
|
+
logger.debug(f"Annotated field contains SubclassUnion in '{arg}'")
|
|
266
|
+
return True
|
|
267
|
+
|
|
268
|
+
# Check for container types (List, Union, Dict)
|
|
269
|
+
if origin in {Union, List, Dict}:
|
|
270
|
+
for arg in args:
|
|
271
|
+
if cls.field_contains_subclass_union(arg):
|
|
272
|
+
logger.debug(f"Container field '{field_annotation}' contains SubclassUnion in its arguments")
|
|
273
|
+
return True
|
|
274
|
+
|
|
275
|
+
logger.debug(f"Field annotation '{field_annotation}' does not contain SubclassUnion or ResourceType")
|
|
256
276
|
return False
|
|
257
277
|
|
|
258
278
|
|
|
259
279
|
@classmethod
|
|
260
280
|
def extract_resource_types_from_field(cls, field_annotation) -> List[Type['ComponentBase']]:
|
|
261
281
|
"""
|
|
262
|
-
Extracts all resource types from a field annotation
|
|
282
|
+
Extracts all resource types from a field annotation using SubclassUnion.
|
|
263
283
|
|
|
264
284
|
Parameters:
|
|
265
285
|
- field_annotation: The type annotation of the field.
|
|
@@ -269,46 +289,35 @@ class ComponentBase(BaseModel):
|
|
|
269
289
|
"""
|
|
270
290
|
logger.debug(f"Extracting resource types from field annotation '{field_annotation}'")
|
|
271
291
|
resource_types = []
|
|
272
|
-
|
|
273
|
-
origin = get_origin(field_annotation)
|
|
274
|
-
args = get_args(field_annotation)
|
|
275
|
-
|
|
276
|
-
if origin is Annotated:
|
|
277
|
-
# Extract the actual type from Annotated
|
|
278
|
-
logger.debug(f"Field annotation '{field_annotation}' is Annotated")
|
|
279
|
-
field_annotation = args[0]
|
|
292
|
+
try:
|
|
280
293
|
origin = get_origin(field_annotation)
|
|
281
294
|
args = get_args(field_annotation)
|
|
282
295
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
296
|
+
if origin is Annotated:
|
|
297
|
+
for arg in args[1:]: # Skip the first argument which is the main type
|
|
298
|
+
if isinstance(arg, ResourceType):
|
|
299
|
+
resource_types.append(arg.resource_type)
|
|
300
|
+
logger.debug(f"Found ResourceType metadata with resource type '{arg.resource_type.__name__}'")
|
|
301
|
+
else:
|
|
302
|
+
resource_types.extend(cls.extract_resource_types_from_field(arg))
|
|
303
|
+
|
|
304
|
+
elif inspect.isclass(field_annotation) and issubclass(field_annotation, SubclassUnion):
|
|
305
|
+
subclass_args = get_args(field_annotation)
|
|
306
|
+
if subclass_args:
|
|
307
|
+
# Assuming the first argument is the resource type
|
|
308
|
+
resource_types.append(subclass_args[0])
|
|
309
|
+
logger.debug(f"Extracted resource type '{subclass_args[0].__name__}' from SubclassUnion")
|
|
310
|
+
else:
|
|
311
|
+
logger.warning(f"SubclassUnion '{field_annotation}' has no type arguments")
|
|
312
|
+
elif origin in {Union, List, Dict, Set, Tuple, Optional}:
|
|
313
|
+
for arg in args:
|
|
288
314
|
resource_types.extend(cls.extract_resource_types_from_field(arg))
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
logger.debug(f"Extracted resource type '{resource_type.__name__}' from SubclassUnion")
|
|
296
|
-
resource_types.append(resource_type)
|
|
297
|
-
elif origin in {list, List}:
|
|
298
|
-
# Handle List[SubclassUnion[ResourceType]]
|
|
299
|
-
item_type = args[0]
|
|
300
|
-
logger.debug(f"Field annotation '{field_annotation}' is a List with item type '{item_type}'")
|
|
301
|
-
resource_types.extend(cls.extract_resource_types_from_field(item_type))
|
|
302
|
-
elif origin in {dict, Dict}:
|
|
303
|
-
# Handle Dict[key_type, SubclassUnion[ResourceType]]
|
|
304
|
-
value_type = args[1]
|
|
305
|
-
logger.debug(f"Field annotation '{field_annotation}' is a Dict with value type '{value_type}'")
|
|
306
|
-
resource_types.extend(cls.extract_resource_types_from_field(value_type))
|
|
307
|
-
else:
|
|
308
|
-
logger.debug(f"Field annotation '{field_annotation}' does not match any known patterns for SubclassUnion")
|
|
309
|
-
|
|
310
|
-
logger.debug(f"Extracted resource types: {[rt.__name__ for rt in resource_types]}")
|
|
311
|
-
return resource_types
|
|
315
|
+
|
|
316
|
+
return resource_types
|
|
317
|
+
except TypeError as e:
|
|
318
|
+
logger.error(f"TypeError while extracting resource types from field annotation '{field_annotation}': {e}")
|
|
319
|
+
return resource_types
|
|
320
|
+
|
|
312
321
|
|
|
313
322
|
@classmethod
|
|
314
323
|
def determine_new_type(cls, field_annotation, resource_type):
|
|
@@ -323,81 +332,49 @@ class ComponentBase(BaseModel):
|
|
|
323
332
|
- The updated type annotation incorporating SubclassUnion.
|
|
324
333
|
"""
|
|
325
334
|
logger.debug(f"Determining new type for field annotation '{field_annotation}' with resource type '{resource_type.__name__}'")
|
|
326
|
-
|
|
327
|
-
args = get_args(field_annotation)
|
|
328
|
-
|
|
329
|
-
is_optional = False
|
|
330
|
-
|
|
331
|
-
if origin is Union and type(None) in args:
|
|
332
|
-
# Handle Optional and Union types
|
|
333
|
-
non_none_args = [arg for arg in args if arg is not type(None)]
|
|
334
|
-
logger.debug(f"Field annotation '{field_annotation}' is Optional/Union with non-None args {non_none_args}")
|
|
335
|
-
if len(non_none_args) == 1:
|
|
336
|
-
field_annotation = non_none_args[0]
|
|
337
|
-
origin = get_origin(field_annotation)
|
|
338
|
-
args = get_args(field_annotation)
|
|
339
|
-
is_optional = True
|
|
340
|
-
logger.debug(f"Field is Optional with single non-None type '{field_annotation}'")
|
|
341
|
-
else:
|
|
342
|
-
field_annotation = Union[tuple(non_none_args)]
|
|
343
|
-
origin = get_origin(field_annotation)
|
|
344
|
-
args = get_args(field_annotation)
|
|
345
|
-
is_optional = True
|
|
346
|
-
logger.debug(f"Field is Optional with multiple non-None types '{field_annotation}'")
|
|
347
|
-
|
|
348
|
-
# Handle Annotated types by extracting the underlying type
|
|
349
|
-
if origin is Annotated:
|
|
350
|
-
# Extract the actual type from Annotated
|
|
351
|
-
logger.debug(f"Field annotation '{field_annotation}' is Annotated")
|
|
352
|
-
field_annotation = args[0]
|
|
335
|
+
try:
|
|
353
336
|
origin = get_origin(field_annotation)
|
|
354
337
|
args = get_args(field_annotation)
|
|
355
338
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
# Handle Union types
|
|
367
|
-
union_types = []
|
|
368
|
-
for arg in args:
|
|
369
|
-
if cls.field_contains_subclass_union(arg):
|
|
370
|
-
union_types.append(SubclassUnion[resource_type])
|
|
371
|
-
logger.debug(f"Added SubclassUnion[{resource_type.__name__}] to Union types")
|
|
339
|
+
is_optional = False
|
|
340
|
+
|
|
341
|
+
# Handle Optional[...] (Union[..., NoneType])
|
|
342
|
+
if origin is Union and type(None) in args:
|
|
343
|
+
non_none_args = [arg for arg in args if arg is not type(None)]
|
|
344
|
+
if len(non_none_args) == 1:
|
|
345
|
+
field_annotation = non_none_args[0]
|
|
346
|
+
origin = get_origin(field_annotation)
|
|
347
|
+
args = get_args(field_annotation)
|
|
348
|
+
is_optional = True
|
|
372
349
|
else:
|
|
373
|
-
|
|
374
|
-
logger.
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
350
|
+
# Multiple non-None types, complex Union
|
|
351
|
+
logger.warning(f"Field annotation '{field_annotation}' has multiple non-None Union types; optionality may not be preserved correctly.")
|
|
352
|
+
|
|
353
|
+
# Handle Annotated
|
|
354
|
+
if origin is Annotated:
|
|
355
|
+
base_type = args[0]
|
|
356
|
+
metadata = [arg for arg in args[1:] if not isinstance(arg, ResourceType)]
|
|
357
|
+
# Append the new ResourceType
|
|
358
|
+
metadata.append(ResourceType(resource_type))
|
|
359
|
+
logger.debug(f"Preserving existing metadata and adding ResourceType for resource '{resource_type.__name__}'")
|
|
360
|
+
field_annotation = Annotated[base_type, *metadata]
|
|
361
|
+
|
|
362
|
+
# Construct the new type with SubclassUnion and discriminated Union
|
|
363
|
+
subclass_union = SubclassUnion[resource_type]
|
|
364
|
+
annotated_union = Annotated[Union[tuple(ComponentBase.TYPE_REGISTRY.get(resource_type, {}).values())], Field(discriminator='type'), ResourceType(resource_type)]
|
|
365
|
+
|
|
366
|
+
# Preserve Optionality if necessary
|
|
367
|
+
if is_optional:
|
|
368
|
+
new_type = Union[annotated_union, type(None)]
|
|
389
369
|
else:
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
new_type
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
logger.debug(f"Determined new type for field: '{new_type}'")
|
|
400
|
-
return new_type
|
|
370
|
+
new_type = annotated_union
|
|
371
|
+
|
|
372
|
+
logger.debug(f"New type for field: {new_type}")
|
|
373
|
+
return new_type
|
|
374
|
+
except TypeError as e:
|
|
375
|
+
logger.error(f"TypeError while determining new type for field annotation '{field_annotation}': {e}")
|
|
376
|
+
return field_annotation # Fallback to original type if error occurs
|
|
377
|
+
|
|
401
378
|
|
|
402
379
|
|
|
403
380
|
@classmethod
|
|
@@ -408,24 +385,37 @@ class ComponentBase(BaseModel):
|
|
|
408
385
|
Returns:
|
|
409
386
|
- A dictionary mapping model classes to their fields and corresponding resource types.
|
|
410
387
|
"""
|
|
388
|
+
logging.info("Starting generation of models_with_fields")
|
|
389
|
+
|
|
411
390
|
models_with_fields = {}
|
|
412
391
|
for model_cls, resource_types in cls.MODEL_REGISTRY.items():
|
|
392
|
+
logging.debug(f"Processing model: {model_cls.__name__}")
|
|
413
393
|
models_with_fields[model_cls] = {}
|
|
394
|
+
|
|
414
395
|
for field_name, field in model_cls.__fields__.items():
|
|
396
|
+
logging.debug(f"Processing field: {field_name}")
|
|
397
|
+
|
|
415
398
|
field_annotation = model_cls.__annotations__.get(field_name)
|
|
416
399
|
if not field_annotation:
|
|
400
|
+
logging.debug(f"Field {field_name} in model {model_cls.__name__} has no annotation, skipping.")
|
|
417
401
|
continue
|
|
418
402
|
|
|
419
403
|
# Check if SubclassUnion is used in the field type
|
|
420
404
|
if not cls.field_contains_subclass_union(field_annotation):
|
|
405
|
+
logging.debug(f"Field {field_name} does not contain SubclassUnion, skipping.")
|
|
421
406
|
continue # Only process fields that use SubclassUnion
|
|
422
407
|
|
|
423
408
|
# Extract all resource types from the field
|
|
424
409
|
field_resource_types = cls.extract_resource_types_from_field(field_annotation)
|
|
410
|
+
logging.debug(f"Extracted resource types for field {field_name}: {field_resource_types}")
|
|
411
|
+
|
|
425
412
|
for resource_type in field_resource_types:
|
|
426
413
|
new_type = cls.determine_new_type(field_annotation, resource_type)
|
|
414
|
+
logging.debug(f"Determined new type for resource {resource_type}: {new_type}")
|
|
415
|
+
|
|
427
416
|
models_with_fields[model_cls][field_name] = new_type
|
|
428
417
|
|
|
418
|
+
logging.info("Completed generation of models_with_fields")
|
|
429
419
|
return models_with_fields
|
|
430
420
|
|
|
431
421
|
@classmethod
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agent_apis/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentParser.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentRetrieve.py
RENAMED
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/IAgentToolkit.py
RENAMED
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/agents/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/ICallableChain.py
RENAMED
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChainContext.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChainFactory.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/IChainStep.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chains/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chunkers/IChunker.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/chunkers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/conversations/IMaxSize.py
RENAMED
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/conversations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/distances/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/documents/IDocument.py
RENAMED
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/documents/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/embeddings/IFeature.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/embeddings/ISaveModel.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/embeddings/IVectorize.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/embeddings/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/factories/IFactory.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/factories/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/image_gens/IGenImage.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/image_gens/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/measurements/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/messages/IMessage.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/messages/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/parsers/IParser.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/parsers/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/pipelines/IPipeline.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/pipelines/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/prompts/IPrompt.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/prompts/IPromptMatrix.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/prompts/ITemplate.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/prompts/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/swarm_apis/ISwarmAPI.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/swarm_apis/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/swarms/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/toolkits/IToolkit.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/toolkits/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tools/IParameter.py
RENAMED
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tools/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tracing/IChainTracer.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tracing/ITraceContext.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tracing/ITracer.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/tracing/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/transports/ITransport.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/transports/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/utils/ITransactional.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/utils/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vcms/IPredictVision.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vector_stores/__init__.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/IVector.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/IVectorMeta.py
RENAMED
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/IVectorProduct.py
RENAMED
|
File without changes
|
|
File without changes
|
{swarmauri_core-0.6.0.dev130 → swarmauri_core-0.6.0.dev132}/swarmauri_core/vectors/__init__.py
RENAMED
|
File without changes
|