isa-model 0.0.3__py3-none-any.whl → 0.0.4__py3-none-any.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.
isa_model/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  isA_Model - A simple interface for AI model integration
3
3
  """
4
4
 
5
- __version__ = "0.1.0"
5
+ __version__ = "0.0.4"
@@ -3,6 +3,9 @@ from enum import Enum
3
3
  import logging
4
4
  from pathlib import Path
5
5
  import json
6
+ import sqlite3
7
+ from datetime import datetime
8
+ import threading
6
9
 
7
10
  logger = logging.getLogger(__name__)
8
11
 
@@ -29,27 +32,45 @@ class ModelType(str, Enum):
29
32
  VISION = "vision"
30
33
 
31
34
  class ModelRegistry:
32
- """Registry for model metadata and capabilities"""
35
+ """SQLite-based registry for model metadata and capabilities"""
33
36
 
34
- def __init__(self, registry_file: str = "./models/model_registry.json"):
35
- self.registry_file = Path(registry_file)
36
- self.registry: Dict[str, Dict[str, Any]] = {}
37
- self._load_registry()
37
+ def __init__(self, db_path: str = "./models/model_registry.db"):
38
+ self.db_path = Path(db_path)
39
+ self.db_path.parent.mkdir(parents=True, exist_ok=True)
40
+ self._lock = threading.Lock()
41
+ self._initialize_database()
38
42
 
39
- def _load_registry(self):
40
- """Load model registry from file"""
41
- if self.registry_file.exists():
42
- with open(self.registry_file, 'r') as f:
43
- self.registry = json.load(f)
44
- else:
45
- self.registry = {}
46
- self._save_registry()
47
-
48
- def _save_registry(self):
49
- """Save model registry to file"""
50
- self.registry_file.parent.mkdir(parents=True, exist_ok=True)
51
- with open(self.registry_file, 'w') as f:
52
- json.dump(self.registry, f, indent=2)
43
+ def _initialize_database(self):
44
+ """Initialize SQLite database with required tables"""
45
+ with sqlite3.connect(self.db_path) as conn:
46
+ conn.execute("""
47
+ CREATE TABLE IF NOT EXISTS models (
48
+ model_id TEXT PRIMARY KEY,
49
+ model_type TEXT NOT NULL,
50
+ metadata TEXT,
51
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
52
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
53
+ )
54
+ """)
55
+
56
+ conn.execute("""
57
+ CREATE TABLE IF NOT EXISTS model_capabilities (
58
+ model_id TEXT,
59
+ capability TEXT,
60
+ PRIMARY KEY (model_id, capability),
61
+ FOREIGN KEY (model_id) REFERENCES models(model_id) ON DELETE CASCADE
62
+ )
63
+ """)
64
+
65
+ conn.execute("""
66
+ CREATE INDEX IF NOT EXISTS idx_model_type ON models(model_type)
67
+ """)
68
+
69
+ conn.execute("""
70
+ CREATE INDEX IF NOT EXISTS idx_capability ON model_capabilities(capability)
71
+ """)
72
+
73
+ conn.commit()
53
74
 
54
75
  def register_model(self,
55
76
  model_id: str,
@@ -58,14 +79,30 @@ class ModelRegistry:
58
79
  metadata: Dict[str, Any]) -> bool:
59
80
  """Register a model with its capabilities and metadata"""
60
81
  try:
61
- self.registry[model_id] = {
62
- "type": model_type,
63
- "capabilities": [cap.value for cap in capabilities],
64
- "metadata": metadata
65
- }
66
- self._save_registry()
82
+ with self._lock:
83
+ with sqlite3.connect(self.db_path) as conn:
84
+ # Insert or update model
85
+ conn.execute("""
86
+ INSERT OR REPLACE INTO models
87
+ (model_id, model_type, metadata, updated_at)
88
+ VALUES (?, ?, ?, CURRENT_TIMESTAMP)
89
+ """, (model_id, model_type.value, json.dumps(metadata)))
90
+
91
+ # Clear existing capabilities
92
+ conn.execute("DELETE FROM model_capabilities WHERE model_id = ?", (model_id,))
93
+
94
+ # Insert new capabilities
95
+ for capability in capabilities:
96
+ conn.execute("""
97
+ INSERT INTO model_capabilities (model_id, capability)
98
+ VALUES (?, ?)
99
+ """, (model_id, capability.value))
100
+
101
+ conn.commit()
102
+
67
103
  logger.info(f"Registered model {model_id}")
68
104
  return True
105
+
69
106
  except Exception as e:
70
107
  logger.error(f"Failed to register model {model_id}: {e}")
71
108
  return False
@@ -73,43 +110,233 @@ class ModelRegistry:
73
110
  def unregister_model(self, model_id: str) -> bool:
74
111
  """Unregister a model"""
75
112
  try:
76
- if model_id in self.registry:
77
- del self.registry[model_id]
78
- self._save_registry()
79
- logger.info(f"Unregistered model {model_id}")
80
- return True
81
- return False
113
+ with self._lock:
114
+ with sqlite3.connect(self.db_path) as conn:
115
+ cursor = conn.execute("DELETE FROM models WHERE model_id = ?", (model_id,))
116
+ conn.commit()
117
+
118
+ if cursor.rowcount > 0:
119
+ logger.info(f"Unregistered model {model_id}")
120
+ return True
121
+ return False
122
+
82
123
  except Exception as e:
83
124
  logger.error(f"Failed to unregister model {model_id}: {e}")
84
125
  return False
85
126
 
86
127
  def get_model_info(self, model_id: str) -> Optional[Dict[str, Any]]:
87
128
  """Get model information"""
88
- return self.registry.get(model_id)
129
+ try:
130
+ with sqlite3.connect(self.db_path) as conn:
131
+ conn.row_factory = sqlite3.Row
132
+
133
+ # Get model info
134
+ model_row = conn.execute("""
135
+ SELECT model_id, model_type, metadata, created_at, updated_at
136
+ FROM models WHERE model_id = ?
137
+ """, (model_id,)).fetchone()
138
+
139
+ if not model_row:
140
+ return None
141
+
142
+ # Get capabilities
143
+ capabilities = conn.execute("""
144
+ SELECT capability FROM model_capabilities WHERE model_id = ?
145
+ """, (model_id,)).fetchall()
146
+
147
+ model_info = {
148
+ "model_id": model_row["model_id"],
149
+ "type": model_row["model_type"],
150
+ "capabilities": [cap["capability"] for cap in capabilities],
151
+ "metadata": json.loads(model_row["metadata"]) if model_row["metadata"] else {},
152
+ "created_at": model_row["created_at"],
153
+ "updated_at": model_row["updated_at"]
154
+ }
155
+
156
+ return model_info
157
+
158
+ except Exception as e:
159
+ logger.error(f"Failed to get model info for {model_id}: {e}")
160
+ return None
89
161
 
90
162
  def get_models_by_type(self, model_type: ModelType) -> Dict[str, Dict[str, Any]]:
91
163
  """Get all models of a specific type"""
92
- return {
93
- model_id: info
94
- for model_id, info in self.registry.items()
95
- if info["type"] == model_type
96
- }
164
+ try:
165
+ with sqlite3.connect(self.db_path) as conn:
166
+ conn.row_factory = sqlite3.Row
167
+
168
+ models = conn.execute("""
169
+ SELECT model_id, model_type, metadata, created_at, updated_at
170
+ FROM models WHERE model_type = ?
171
+ """, (model_type.value,)).fetchall()
172
+
173
+ result = {}
174
+ for model in models:
175
+ model_id = model["model_id"]
176
+
177
+ # Get capabilities for this model
178
+ capabilities = conn.execute("""
179
+ SELECT capability FROM model_capabilities WHERE model_id = ?
180
+ """, (model_id,)).fetchall()
181
+
182
+ result[model_id] = {
183
+ "type": model["model_type"],
184
+ "capabilities": [cap["capability"] for cap in capabilities],
185
+ "metadata": json.loads(model["metadata"]) if model["metadata"] else {},
186
+ "created_at": model["created_at"],
187
+ "updated_at": model["updated_at"]
188
+ }
189
+
190
+ return result
191
+
192
+ except Exception as e:
193
+ logger.error(f"Failed to get models by type {model_type}: {e}")
194
+ return {}
97
195
 
98
196
  def get_models_by_capability(self, capability: ModelCapability) -> Dict[str, Dict[str, Any]]:
99
197
  """Get all models with a specific capability"""
100
- return {
101
- model_id: info
102
- for model_id, info in self.registry.items()
103
- if capability.value in info["capabilities"]
104
- }
198
+ try:
199
+ with sqlite3.connect(self.db_path) as conn:
200
+ conn.row_factory = sqlite3.Row
201
+
202
+ models = conn.execute("""
203
+ SELECT DISTINCT m.model_id, m.model_type, m.metadata, m.created_at, m.updated_at
204
+ FROM models m
205
+ JOIN model_capabilities mc ON m.model_id = mc.model_id
206
+ WHERE mc.capability = ?
207
+ """, (capability.value,)).fetchall()
208
+
209
+ result = {}
210
+ for model in models:
211
+ model_id = model["model_id"]
212
+
213
+ # Get all capabilities for this model
214
+ capabilities = conn.execute("""
215
+ SELECT capability FROM model_capabilities WHERE model_id = ?
216
+ """, (model_id,)).fetchall()
217
+
218
+ result[model_id] = {
219
+ "type": model["model_type"],
220
+ "capabilities": [cap["capability"] for cap in capabilities],
221
+ "metadata": json.loads(model["metadata"]) if model["metadata"] else {},
222
+ "created_at": model["created_at"],
223
+ "updated_at": model["updated_at"]
224
+ }
225
+
226
+ return result
227
+
228
+ except Exception as e:
229
+ logger.error(f"Failed to get models by capability {capability}: {e}")
230
+ return {}
105
231
 
106
232
  def has_capability(self, model_id: str, capability: ModelCapability) -> bool:
107
233
  """Check if a model has a specific capability"""
108
- model_info = self.get_model_info(model_id)
109
- if not model_info:
234
+ try:
235
+ with sqlite3.connect(self.db_path) as conn:
236
+ result = conn.execute("""
237
+ SELECT 1 FROM model_capabilities
238
+ WHERE model_id = ? AND capability = ?
239
+ """, (model_id, capability.value)).fetchone()
240
+
241
+ return result is not None
242
+
243
+ except Exception as e:
244
+ logger.error(f"Failed to check capability for {model_id}: {e}")
110
245
  return False
111
- return capability.value in model_info["capabilities"]
112
246
 
113
247
  def list_models(self) -> Dict[str, Dict[str, Any]]:
114
248
  """List all registered models"""
115
- return self.registry
249
+ try:
250
+ with sqlite3.connect(self.db_path) as conn:
251
+ conn.row_factory = sqlite3.Row
252
+
253
+ models = conn.execute("""
254
+ SELECT model_id, model_type, metadata, created_at, updated_at
255
+ FROM models ORDER BY created_at DESC
256
+ """).fetchall()
257
+
258
+ result = {}
259
+ for model in models:
260
+ model_id = model["model_id"]
261
+
262
+ # Get capabilities for this model
263
+ capabilities = conn.execute("""
264
+ SELECT capability FROM model_capabilities WHERE model_id = ?
265
+ """, (model_id,)).fetchall()
266
+
267
+ result[model_id] = {
268
+ "type": model["model_type"],
269
+ "capabilities": [cap["capability"] for cap in capabilities],
270
+ "metadata": json.loads(model["metadata"]) if model["metadata"] else {},
271
+ "created_at": model["created_at"],
272
+ "updated_at": model["updated_at"]
273
+ }
274
+
275
+ return result
276
+
277
+ except Exception as e:
278
+ logger.error(f"Failed to list models: {e}")
279
+ return {}
280
+
281
+ def get_stats(self) -> Dict[str, Any]:
282
+ """Get registry statistics"""
283
+ try:
284
+ with sqlite3.connect(self.db_path) as conn:
285
+ # Count total models
286
+ total_models = conn.execute("SELECT COUNT(*) FROM models").fetchone()[0]
287
+
288
+ # Count by type
289
+ type_counts = dict(conn.execute("""
290
+ SELECT model_type, COUNT(*) FROM models GROUP BY model_type
291
+ """).fetchall())
292
+
293
+ # Count by capability
294
+ capability_counts = dict(conn.execute("""
295
+ SELECT capability, COUNT(*) FROM model_capabilities GROUP BY capability
296
+ """).fetchall())
297
+
298
+ return {
299
+ "total_models": total_models,
300
+ "models_by_type": type_counts,
301
+ "models_by_capability": capability_counts
302
+ }
303
+
304
+ except Exception as e:
305
+ logger.error(f"Failed to get stats: {e}")
306
+ return {}
307
+
308
+ def search_models(self, query: str) -> Dict[str, Dict[str, Any]]:
309
+ """Search models by name or metadata"""
310
+ try:
311
+ with sqlite3.connect(self.db_path) as conn:
312
+ conn.row_factory = sqlite3.Row
313
+
314
+ models = conn.execute("""
315
+ SELECT model_id, model_type, metadata, created_at, updated_at
316
+ FROM models
317
+ WHERE model_id LIKE ? OR metadata LIKE ?
318
+ ORDER BY created_at DESC
319
+ """, (f"%{query}%", f"%{query}%")).fetchall()
320
+
321
+ result = {}
322
+ for model in models:
323
+ model_id = model["model_id"]
324
+
325
+ # Get capabilities for this model
326
+ capabilities = conn.execute("""
327
+ SELECT capability FROM model_capabilities WHERE model_id = ?
328
+ """, (model_id,)).fetchall()
329
+
330
+ result[model_id] = {
331
+ "type": model["model_type"],
332
+ "capabilities": [cap["capability"] for cap in capabilities],
333
+ "metadata": json.loads(model["metadata"]) if model["metadata"] else {},
334
+ "created_at": model["created_at"],
335
+ "updated_at": model["updated_at"]
336
+ }
337
+
338
+ return result
339
+
340
+ except Exception as e:
341
+ logger.error(f"Failed to search models with query '{query}': {e}")
342
+ return {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: isa-model
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Unified AI model serving framework
5
5
  Author-email: isA_Model Contributors <your.email@example.com>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
- isa_model/__init__.py,sha256=d63WuNpouABPnomHiQKmPp829-ba-CtKnyefZwgFNsc,87
1
+ isa_model/__init__.py,sha256=wn-CpZFCmR1PBQWrYrp8Y_d2L69Apf41efjn3L5dNGc,87
2
2
  isa_model/core/model_manager.py,sha256=eQp0MV0x5sghL1qliPUWkFX4sEKqInyGLoICfNkJnZM,5275
3
- isa_model/core/model_registry.py,sha256=3K32y9N0M1fXoUH_EBPoFq9Tj1enFgOSx9H57upmsHs,4005
3
+ isa_model/core/model_registry.py,sha256=gT8yFxi1gC-45Bolc9WX19ZvrjuV1xyBgQX6TFhz62k,14032
4
4
  isa_model/core/model_router.py,sha256=WT45wP5Ta-c3QErPGUY86G9-IpWQXjLC5FG8cPI-qK0,8637
5
5
  isa_model/core/model_storage.py,sha256=yMLapW87EY1EPXw6S7H8UQAZh3hJ1KxsEohjgjw-HrA,4507
6
6
  isa_model/core/model_version.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -85,8 +85,8 @@ isa_model/training/llm_model/annotation/tests/test_annotation_flow.py,sha256=DXY
85
85
  isa_model/training/llm_model/annotation/tests/test_minio copy.py,sha256=EI-PlH5xttAZF14Z_xn6LjgIJBkvP2qjLcvbX2hc0RM,3946
86
86
  isa_model/training/llm_model/annotation/tests/test_minio_upload.py,sha256=fL1eMubwR6L9lYc3zEwlWU9yjJuTsIYi93i0l9QUjm0,1109
87
87
  isa_model/training/llm_model/annotation/views/annotation_controller.py,sha256=3VzJ52yI-YIpcaAAXy2qac7sr4hTnFdtn-ZEKTt4IkM,5792
88
- isa_model-0.0.3.dist-info/licenses/LICENSE,sha256=nNPdMBBVrQz3f7AgKFZuyQgdar9d90Vdw51es-P72Dw,1084
89
- isa_model-0.0.3.dist-info/METADATA,sha256=CLDEp-IRBK65F3gunIlaPHAykkcWdunyAB90BxsnOXA,8105
90
- isa_model-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
91
- isa_model-0.0.3.dist-info/top_level.txt,sha256=eHSy_Xb3kNkh2kK11mi1mZh0Wz91AQ5b8k2KFYO-rE8,10
92
- isa_model-0.0.3.dist-info/RECORD,,
88
+ isa_model-0.0.4.dist-info/licenses/LICENSE,sha256=nNPdMBBVrQz3f7AgKFZuyQgdar9d90Vdw51es-P72Dw,1084
89
+ isa_model-0.0.4.dist-info/METADATA,sha256=UVELHwmFbvX2htqfjX4YSwkWS_9Izvp-mWwQaL9vbJI,8105
90
+ isa_model-0.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
91
+ isa_model-0.0.4.dist-info/top_level.txt,sha256=eHSy_Xb3kNkh2kK11mi1mZh0Wz91AQ5b8k2KFYO-rE8,10
92
+ isa_model-0.0.4.dist-info/RECORD,,