isa-model 0.3.4__py3-none-any.whl → 0.3.6__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 +30 -1
- isa_model/client.py +770 -0
- isa_model/core/config/__init__.py +16 -0
- isa_model/core/config/config_manager.py +514 -0
- isa_model/core/config.py +426 -0
- isa_model/core/models/model_billing_tracker.py +476 -0
- isa_model/core/models/model_manager.py +399 -0
- isa_model/core/models/model_repo.py +343 -0
- isa_model/core/pricing_manager.py +426 -0
- isa_model/core/services/__init__.py +19 -0
- isa_model/core/services/intelligent_model_selector.py +547 -0
- isa_model/core/types.py +291 -0
- isa_model/deployment/__init__.py +2 -0
- isa_model/deployment/cloud/__init__.py +9 -0
- isa_model/deployment/cloud/modal/__init__.py +10 -0
- isa_model/deployment/cloud/modal/isa_vision_doc_service.py +766 -0
- isa_model/deployment/cloud/modal/isa_vision_table_service.py +532 -0
- isa_model/deployment/cloud/modal/isa_vision_ui_service.py +406 -0
- isa_model/deployment/cloud/modal/register_models.py +321 -0
- isa_model/deployment/runtime/deployed_service.py +338 -0
- isa_model/deployment/services/__init__.py +9 -0
- isa_model/deployment/services/auto_deploy_vision_service.py +537 -0
- isa_model/deployment/services/model_service.py +332 -0
- isa_model/deployment/services/service_monitor.py +356 -0
- isa_model/deployment/services/service_registry.py +527 -0
- isa_model/eval/__init__.py +80 -44
- isa_model/eval/config/__init__.py +10 -0
- isa_model/eval/config/evaluation_config.py +108 -0
- isa_model/eval/evaluators/__init__.py +18 -0
- isa_model/eval/evaluators/base_evaluator.py +503 -0
- isa_model/eval/evaluators/llm_evaluator.py +472 -0
- isa_model/eval/factory.py +417 -709
- isa_model/eval/infrastructure/__init__.py +24 -0
- isa_model/eval/infrastructure/experiment_tracker.py +466 -0
- isa_model/eval/metrics.py +191 -21
- isa_model/inference/ai_factory.py +187 -387
- isa_model/inference/providers/modal_provider.py +109 -0
- isa_model/inference/providers/yyds_provider.py +108 -0
- isa_model/inference/services/__init__.py +2 -1
- isa_model/inference/services/audio/base_stt_service.py +65 -1
- isa_model/inference/services/audio/base_tts_service.py +75 -1
- isa_model/inference/services/audio/openai_stt_service.py +189 -151
- isa_model/inference/services/audio/openai_tts_service.py +12 -10
- isa_model/inference/services/audio/replicate_tts_service.py +61 -56
- isa_model/inference/services/base_service.py +55 -55
- isa_model/inference/services/embedding/base_embed_service.py +65 -1
- isa_model/inference/services/embedding/ollama_embed_service.py +103 -43
- isa_model/inference/services/embedding/openai_embed_service.py +8 -10
- isa_model/inference/services/helpers/stacked_config.py +148 -0
- isa_model/inference/services/img/__init__.py +18 -0
- isa_model/inference/services/{vision → img}/base_image_gen_service.py +80 -35
- isa_model/inference/services/img/flux_professional_service.py +603 -0
- isa_model/inference/services/img/helpers/base_stacked_service.py +274 -0
- isa_model/inference/services/{vision → img}/replicate_image_gen_service.py +210 -69
- isa_model/inference/services/llm/__init__.py +3 -3
- isa_model/inference/services/llm/base_llm_service.py +519 -35
- isa_model/inference/services/llm/{llm_adapter.py → helpers/llm_adapter.py} +40 -0
- isa_model/inference/services/llm/helpers/llm_prompts.py +258 -0
- isa_model/inference/services/llm/helpers/llm_utils.py +280 -0
- isa_model/inference/services/llm/ollama_llm_service.py +150 -15
- isa_model/inference/services/llm/openai_llm_service.py +134 -31
- isa_model/inference/services/llm/yyds_llm_service.py +255 -0
- isa_model/inference/services/vision/__init__.py +38 -4
- isa_model/inference/services/vision/base_vision_service.py +241 -96
- isa_model/inference/services/vision/disabled/isA_vision_service.py +500 -0
- isa_model/inference/services/vision/doc_analysis_service.py +640 -0
- isa_model/inference/services/vision/helpers/base_stacked_service.py +274 -0
- isa_model/inference/services/vision/helpers/image_utils.py +272 -3
- isa_model/inference/services/vision/helpers/vision_prompts.py +297 -0
- isa_model/inference/services/vision/openai_vision_service.py +109 -170
- isa_model/inference/services/vision/replicate_vision_service.py +508 -0
- isa_model/inference/services/vision/ui_analysis_service.py +823 -0
- isa_model/scripts/register_models.py +370 -0
- isa_model/scripts/register_models_with_embeddings.py +510 -0
- isa_model/serving/__init__.py +19 -0
- isa_model/serving/api/__init__.py +10 -0
- isa_model/serving/api/fastapi_server.py +89 -0
- isa_model/serving/api/middleware/__init__.py +9 -0
- isa_model/serving/api/middleware/request_logger.py +88 -0
- isa_model/serving/api/routes/__init__.py +5 -0
- isa_model/serving/api/routes/health.py +82 -0
- isa_model/serving/api/routes/llm.py +19 -0
- isa_model/serving/api/routes/ui_analysis.py +223 -0
- isa_model/serving/api/routes/unified.py +202 -0
- isa_model/serving/api/routes/vision.py +19 -0
- isa_model/serving/api/schemas/__init__.py +17 -0
- isa_model/serving/api/schemas/common.py +33 -0
- isa_model/serving/api/schemas/ui_analysis.py +78 -0
- {isa_model-0.3.4.dist-info → isa_model-0.3.6.dist-info}/METADATA +4 -1
- isa_model-0.3.6.dist-info/RECORD +147 -0
- isa_model/core/model_manager.py +0 -208
- isa_model/core/model_registry.py +0 -342
- isa_model/inference/billing_tracker.py +0 -406
- isa_model/inference/services/llm/triton_llm_service.py +0 -481
- isa_model/inference/services/vision/ollama_vision_service.py +0 -194
- isa_model-0.3.4.dist-info/RECORD +0 -91
- /isa_model/core/{model_storage.py → models/model_storage.py} +0 -0
- /isa_model/inference/services/{vision → embedding}/helpers/text_splitter.py +0 -0
- {isa_model-0.3.4.dist-info → isa_model-0.3.6.dist-info}/WHEEL +0 -0
- {isa_model-0.3.4.dist-info → isa_model-0.3.6.dist-info}/top_level.txt +0 -0
isa_model/core/types.py
ADDED
@@ -0,0 +1,291 @@
|
|
1
|
+
"""
|
2
|
+
Unified Type Definitions for ISA Model SDK
|
3
|
+
|
4
|
+
This module contains all the common enums and type definitions used across
|
5
|
+
the entire SDK to ensure consistency and avoid duplication.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from enum import Enum
|
9
|
+
from typing import Dict, List, Optional, Any, Union
|
10
|
+
from dataclasses import dataclass
|
11
|
+
from datetime import datetime
|
12
|
+
|
13
|
+
# ===== MODEL TYPES =====
|
14
|
+
|
15
|
+
class ModelType(str, Enum):
|
16
|
+
"""Types of models in the system"""
|
17
|
+
LLM = "llm"
|
18
|
+
EMBEDDING = "embedding"
|
19
|
+
RERANK = "rerank"
|
20
|
+
IMAGE = "image"
|
21
|
+
AUDIO = "audio"
|
22
|
+
VIDEO = "video"
|
23
|
+
VISION = "vision"
|
24
|
+
IMAGE_GEN = "image_gen" # Added for consistency
|
25
|
+
|
26
|
+
class ModelCapability(str, Enum):
|
27
|
+
"""Model capabilities"""
|
28
|
+
TEXT_GENERATION = "text_generation"
|
29
|
+
CHAT = "chat"
|
30
|
+
EMBEDDING = "embedding"
|
31
|
+
RERANKING = "reranking"
|
32
|
+
REASONING = "reasoning"
|
33
|
+
IMAGE_GENERATION = "image_generation"
|
34
|
+
IMAGE_ANALYSIS = "image_analysis"
|
35
|
+
AUDIO_TRANSCRIPTION = "audio_transcription"
|
36
|
+
IMAGE_UNDERSTANDING = "image_understanding"
|
37
|
+
UI_DETECTION = "ui_detection"
|
38
|
+
OCR = "ocr"
|
39
|
+
TABLE_DETECTION = "table_detection"
|
40
|
+
TABLE_STRUCTURE_RECOGNITION = "table_structure_recognition"
|
41
|
+
|
42
|
+
class ModelStage(str, Enum):
|
43
|
+
"""Model lifecycle stages"""
|
44
|
+
REGISTERED = "registered"
|
45
|
+
TRAINING = "training"
|
46
|
+
EVALUATION = "evaluation"
|
47
|
+
DEPLOYMENT = "deployment"
|
48
|
+
PRODUCTION = "production"
|
49
|
+
RETIRED = "retired"
|
50
|
+
|
51
|
+
# ===== SERVICE TYPES =====
|
52
|
+
|
53
|
+
class ServiceType(str, Enum):
|
54
|
+
"""Types of services available in the platform"""
|
55
|
+
LLM = "llm"
|
56
|
+
EMBEDDING = "embedding"
|
57
|
+
VISION = "vision"
|
58
|
+
AUDIO = "audio"
|
59
|
+
IMAGE_GEN = "image_gen"
|
60
|
+
|
61
|
+
class ServiceStatus(str, Enum):
|
62
|
+
"""Service deployment and health status"""
|
63
|
+
PENDING = "pending"
|
64
|
+
DEPLOYING = "deploying"
|
65
|
+
HEALTHY = "healthy"
|
66
|
+
UNHEALTHY = "unhealthy"
|
67
|
+
STOPPED = "stopped"
|
68
|
+
|
69
|
+
class DeploymentPlatform(str, Enum):
|
70
|
+
"""Supported deployment platforms for self-owned services only"""
|
71
|
+
MODAL = "modal"
|
72
|
+
KUBERNETES = "kubernetes"
|
73
|
+
RUNPOD = "runpod"
|
74
|
+
YYDS = "yyds"
|
75
|
+
OLLAMA = "ollama" # Local deployment
|
76
|
+
|
77
|
+
# ===== OPERATION TYPES =====
|
78
|
+
|
79
|
+
class ModelOperationType(str, Enum):
|
80
|
+
"""Types of model operations that incur costs"""
|
81
|
+
TRAINING = "training"
|
82
|
+
EVALUATION = "evaluation"
|
83
|
+
DEPLOYMENT = "deployment"
|
84
|
+
INFERENCE = "inference"
|
85
|
+
STORAGE = "storage"
|
86
|
+
|
87
|
+
class InferenceOperationType(str, Enum):
|
88
|
+
"""Types of inference operations"""
|
89
|
+
CHAT = "chat"
|
90
|
+
COMPLETION = "completion"
|
91
|
+
EMBEDDING = "embedding"
|
92
|
+
IMAGE_GENERATION = "image_generation"
|
93
|
+
VISION_ANALYSIS = "vision_analysis"
|
94
|
+
AUDIO_TRANSCRIPTION = "audio_transcription"
|
95
|
+
AUDIO_GENERATION = "audio_generation"
|
96
|
+
|
97
|
+
# ===== ROUTING AND LOAD BALANCING =====
|
98
|
+
|
99
|
+
class RoutingStrategy(str, Enum):
|
100
|
+
"""Routing strategies for distributing requests among model replicas"""
|
101
|
+
ROUND_ROBIN = "round_robin"
|
102
|
+
WEIGHTED_ROUND_ROBIN = "weighted_round_robin"
|
103
|
+
LEAST_CONNECTIONS = "least_connections"
|
104
|
+
RESPONSE_TIME = "response_time"
|
105
|
+
RANDOM = "random"
|
106
|
+
CONSISTENT_HASH = "consistent_hash"
|
107
|
+
DYNAMIC_LOAD_BALANCING = "dynamic_load_balancing"
|
108
|
+
|
109
|
+
# ===== EVALUATION AND TRAINING =====
|
110
|
+
|
111
|
+
class MetricType(str, Enum):
|
112
|
+
"""Types of evaluation metrics"""
|
113
|
+
ACCURACY = "accuracy"
|
114
|
+
PRECISION = "precision"
|
115
|
+
RECALL = "recall"
|
116
|
+
F1_SCORE = "f1_score"
|
117
|
+
BLEU = "bleu"
|
118
|
+
ROUGE = "rouge"
|
119
|
+
PERPLEXITY = "perplexity"
|
120
|
+
BERTSCORE = "bertscore"
|
121
|
+
SEMANTIC_SIMILARITY = "semantic_similarity"
|
122
|
+
|
123
|
+
class AnnotationType(str, Enum):
|
124
|
+
"""Types of training data annotations"""
|
125
|
+
TEXT_CLASSIFICATION = "text_classification"
|
126
|
+
NAMED_ENTITY_RECOGNITION = "named_entity_recognition"
|
127
|
+
QUESTION_ANSWERING = "question_answering"
|
128
|
+
SUMMARIZATION = "summarization"
|
129
|
+
TRANSLATION = "translation"
|
130
|
+
IMAGE_CLASSIFICATION = "image_classification"
|
131
|
+
OBJECT_DETECTION = "object_detection"
|
132
|
+
SEMANTIC_SEGMENTATION = "semantic_segmentation"
|
133
|
+
|
134
|
+
class DatasetType(str, Enum):
|
135
|
+
"""Types of training datasets"""
|
136
|
+
TEXT = "text"
|
137
|
+
IMAGE = "image"
|
138
|
+
AUDIO = "audio"
|
139
|
+
VIDEO = "video"
|
140
|
+
MULTIMODAL = "multimodal"
|
141
|
+
|
142
|
+
class DatasetStatus(str, Enum):
|
143
|
+
"""Status of training datasets"""
|
144
|
+
CREATED = "created"
|
145
|
+
UPLOADING = "uploading"
|
146
|
+
PROCESSING = "processing"
|
147
|
+
READY = "ready"
|
148
|
+
ERROR = "error"
|
149
|
+
|
150
|
+
class ExperimentType(str, Enum):
|
151
|
+
"""Types of ML experiments"""
|
152
|
+
TRAINING = "training"
|
153
|
+
EVALUATION = "evaluation"
|
154
|
+
HYPERPARAMETER_TUNING = "hyperparameter_tuning"
|
155
|
+
MODEL_COMPARISON = "model_comparison"
|
156
|
+
|
157
|
+
# ===== STACKED SERVICES =====
|
158
|
+
|
159
|
+
class LayerType(Enum):
|
160
|
+
"""Types of layers in stacked services"""
|
161
|
+
INPUT_PROCESSING = "input_processing"
|
162
|
+
MODEL_INFERENCE = "model_inference"
|
163
|
+
OUTPUT_PROCESSING = "output_processing"
|
164
|
+
VALIDATION = "validation"
|
165
|
+
CACHING = "caching"
|
166
|
+
|
167
|
+
class WorkflowType(Enum):
|
168
|
+
"""Types of workflows"""
|
169
|
+
SEQUENTIAL = "sequential"
|
170
|
+
PARALLEL = "parallel"
|
171
|
+
CONDITIONAL = "conditional"
|
172
|
+
LOOP = "loop"
|
173
|
+
|
174
|
+
# ===== PROVIDER TYPES =====
|
175
|
+
|
176
|
+
class Provider(str, Enum):
|
177
|
+
"""AI service providers"""
|
178
|
+
OPENAI = "openai"
|
179
|
+
REPLICATE = "replicate"
|
180
|
+
OLLAMA = "ollama"
|
181
|
+
ANTHROPIC = "anthropic"
|
182
|
+
GOOGLE = "google"
|
183
|
+
YYDS = "yyds"
|
184
|
+
MODAL = "modal"
|
185
|
+
|
186
|
+
# ===== DATA CLASSES =====
|
187
|
+
|
188
|
+
@dataclass
|
189
|
+
class HealthMetrics:
|
190
|
+
"""Service health metrics"""
|
191
|
+
is_healthy: bool
|
192
|
+
response_time_ms: Optional[int] = None
|
193
|
+
status_code: Optional[int] = None
|
194
|
+
cpu_usage_percent: Optional[float] = None
|
195
|
+
memory_usage_mb: Optional[int] = None
|
196
|
+
gpu_usage_percent: Optional[float] = None
|
197
|
+
error_message: Optional[str] = None
|
198
|
+
checked_at: Optional[datetime] = None
|
199
|
+
|
200
|
+
@dataclass
|
201
|
+
class ServiceMetrics:
|
202
|
+
"""Service runtime metrics"""
|
203
|
+
request_count: int = 0
|
204
|
+
total_processing_time_ms: int = 0
|
205
|
+
error_count: int = 0
|
206
|
+
total_cost_usd: float = 0.0
|
207
|
+
window_start: Optional[datetime] = None
|
208
|
+
window_end: Optional[datetime] = None
|
209
|
+
|
210
|
+
@dataclass
|
211
|
+
class ResourceRequirements:
|
212
|
+
"""Service resource requirements"""
|
213
|
+
gpu_type: Optional[str] = None
|
214
|
+
memory_mb: Optional[int] = None
|
215
|
+
cpu_cores: Optional[int] = None
|
216
|
+
storage_gb: Optional[int] = None
|
217
|
+
min_replicas: int = 0
|
218
|
+
max_replicas: int = 1
|
219
|
+
|
220
|
+
@dataclass
|
221
|
+
class ModelInfo:
|
222
|
+
"""Model information structure"""
|
223
|
+
model_id: str
|
224
|
+
model_type: ModelType
|
225
|
+
capabilities: List[ModelCapability]
|
226
|
+
stage: ModelStage
|
227
|
+
provider: str
|
228
|
+
provider_model_name: str
|
229
|
+
metadata: Dict[str, Any]
|
230
|
+
created_at: Optional[datetime] = None
|
231
|
+
updated_at: Optional[datetime] = None
|
232
|
+
|
233
|
+
@dataclass
|
234
|
+
class UsageData:
|
235
|
+
"""Usage data for billing tracking"""
|
236
|
+
operation_type: ModelOperationType
|
237
|
+
inference_operation: Optional[InferenceOperationType] = None
|
238
|
+
input_tokens: Optional[int] = None
|
239
|
+
output_tokens: Optional[int] = None
|
240
|
+
input_units: Optional[float] = None
|
241
|
+
output_units: Optional[float] = None
|
242
|
+
metadata: Optional[Dict[str, Any]] = None
|
243
|
+
|
244
|
+
# ===== TYPE ALIASES =====
|
245
|
+
|
246
|
+
# Common type aliases for better readability
|
247
|
+
ModelID = str
|
248
|
+
ServiceID = str
|
249
|
+
DeploymentID = str
|
250
|
+
ProviderName = str
|
251
|
+
ModelName = str
|
252
|
+
EndpointURL = str
|
253
|
+
ConfigDict = Dict[str, Any]
|
254
|
+
MetadataDict = Dict[str, Any]
|
255
|
+
|
256
|
+
# ===== BACKWARD COMPATIBILITY =====
|
257
|
+
|
258
|
+
# Legacy aliases for backward compatibility during migration
|
259
|
+
# These should be removed once all modules are updated
|
260
|
+
|
261
|
+
# From inference/billing_tracker.py
|
262
|
+
class LegacyServiceType(Enum):
|
263
|
+
"""Legacy service type - use ServiceType instead"""
|
264
|
+
LLM = "llm"
|
265
|
+
EMBEDDING = "embedding"
|
266
|
+
VISION = "vision"
|
267
|
+
IMAGE_GENERATION = "image_generation"
|
268
|
+
AUDIO_STT = "audio_stt"
|
269
|
+
AUDIO_TTS = "audio_tts"
|
270
|
+
|
271
|
+
# Migration mapping
|
272
|
+
LEGACY_SERVICE_TYPE_MAPPING = {
|
273
|
+
LegacyServiceType.LLM: ServiceType.LLM,
|
274
|
+
LegacyServiceType.EMBEDDING: ServiceType.EMBEDDING,
|
275
|
+
LegacyServiceType.VISION: ServiceType.VISION,
|
276
|
+
LegacyServiceType.IMAGE_GENERATION: ServiceType.IMAGE_GEN,
|
277
|
+
LegacyServiceType.AUDIO_STT: ServiceType.AUDIO,
|
278
|
+
LegacyServiceType.AUDIO_TTS: ServiceType.AUDIO,
|
279
|
+
}
|
280
|
+
|
281
|
+
def migrate_legacy_service_type(legacy_type: Union[LegacyServiceType, str]) -> ServiceType:
|
282
|
+
"""Migrate legacy service type to new unified type"""
|
283
|
+
if isinstance(legacy_type, str):
|
284
|
+
# Try to find matching legacy enum
|
285
|
+
for legacy_enum in LegacyServiceType:
|
286
|
+
if legacy_enum.value == legacy_type:
|
287
|
+
return LEGACY_SERVICE_TYPE_MAPPING[legacy_enum]
|
288
|
+
# Fallback to direct mapping
|
289
|
+
return ServiceType(legacy_type)
|
290
|
+
else:
|
291
|
+
return LEGACY_SERVICE_TYPE_MAPPING.get(legacy_type, ServiceType.LLM)
|
isa_model/deployment/__init__.py
CHANGED
@@ -26,11 +26,13 @@ from .core.deployment_config import (
|
|
26
26
|
create_gemma_runpod_triton_config,
|
27
27
|
create_local_triton_config
|
28
28
|
)
|
29
|
+
from .services import AutoDeployVisionService
|
29
30
|
|
30
31
|
__all__ = [
|
31
32
|
# Main classes
|
32
33
|
"DeploymentManager",
|
33
34
|
"DeploymentConfig",
|
35
|
+
"AutoDeployVisionService",
|
34
36
|
|
35
37
|
# Configuration classes
|
36
38
|
"ModelConfig",
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"""
|
2
|
+
Modal Deployment Module
|
3
|
+
|
4
|
+
Modal.com cloud deployment for ISA Model services
|
5
|
+
"""
|
6
|
+
|
7
|
+
from .ui_analysis_service import UIAnalysisService as UIAnalysisModalService
|
8
|
+
from .deployment_manager import ModalDeployment
|
9
|
+
|
10
|
+
__all__ = ["UIAnalysisModalService", "ModalDeployment"]
|