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