isa-model 0.3.9__py3-none-any.whl → 0.4.0__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 +1 -1
- isa_model/client.py +732 -565
- isa_model/core/cache/redis_cache.py +401 -0
- isa_model/core/config/config_manager.py +53 -10
- isa_model/core/config.py +1 -1
- isa_model/core/database/__init__.py +1 -0
- isa_model/core/database/migrations.py +277 -0
- isa_model/core/database/supabase_client.py +123 -0
- isa_model/core/models/__init__.py +37 -0
- isa_model/core/models/model_billing_tracker.py +60 -88
- isa_model/core/models/model_manager.py +36 -18
- isa_model/core/models/model_repo.py +44 -38
- isa_model/core/models/model_statistics_tracker.py +234 -0
- isa_model/core/models/model_storage.py +0 -1
- isa_model/core/models/model_version_manager.py +959 -0
- isa_model/core/pricing_manager.py +2 -249
- isa_model/core/resilience/circuit_breaker.py +366 -0
- isa_model/core/security/secrets.py +358 -0
- isa_model/core/services/__init__.py +2 -4
- isa_model/core/services/intelligent_model_selector.py +101 -370
- isa_model/core/storage/hf_storage.py +1 -1
- isa_model/core/types.py +7 -0
- isa_model/deployment/cloud/modal/isa_audio_chatTTS_service.py +520 -0
- isa_model/deployment/cloud/modal/isa_audio_fish_service.py +0 -0
- isa_model/deployment/cloud/modal/isa_audio_openvoice_service.py +758 -0
- isa_model/deployment/cloud/modal/isa_audio_service_v2.py +1044 -0
- isa_model/deployment/cloud/modal/isa_embed_rerank_service.py +296 -0
- isa_model/deployment/cloud/modal/isa_video_hunyuan_service.py +423 -0
- isa_model/deployment/cloud/modal/isa_vision_ocr_service.py +519 -0
- isa_model/deployment/cloud/modal/isa_vision_qwen25_service.py +709 -0
- isa_model/deployment/cloud/modal/isa_vision_table_service.py +467 -323
- isa_model/deployment/cloud/modal/isa_vision_ui_service.py +607 -180
- isa_model/deployment/cloud/modal/isa_vision_ui_service_optimized.py +660 -0
- isa_model/deployment/core/deployment_manager.py +6 -4
- isa_model/deployment/services/auto_hf_modal_deployer.py +894 -0
- isa_model/eval/benchmarks/__init__.py +27 -0
- isa_model/eval/benchmarks/multimodal_datasets.py +460 -0
- isa_model/eval/benchmarks.py +244 -12
- isa_model/eval/evaluators/__init__.py +8 -2
- isa_model/eval/evaluators/audio_evaluator.py +727 -0
- isa_model/eval/evaluators/embedding_evaluator.py +742 -0
- isa_model/eval/evaluators/vision_evaluator.py +564 -0
- isa_model/eval/example_evaluation.py +395 -0
- isa_model/eval/factory.py +272 -5
- isa_model/eval/isa_benchmarks.py +700 -0
- isa_model/eval/isa_integration.py +582 -0
- isa_model/eval/metrics.py +159 -6
- isa_model/eval/tests/unit/test_basic.py +396 -0
- isa_model/inference/ai_factory.py +44 -8
- isa_model/inference/services/audio/__init__.py +21 -0
- isa_model/inference/services/audio/base_realtime_service.py +225 -0
- isa_model/inference/services/audio/isa_tts_service.py +0 -0
- isa_model/inference/services/audio/openai_realtime_service.py +320 -124
- isa_model/inference/services/audio/openai_stt_service.py +32 -6
- isa_model/inference/services/base_service.py +17 -1
- isa_model/inference/services/embedding/__init__.py +13 -0
- isa_model/inference/services/embedding/base_embed_service.py +111 -8
- isa_model/inference/services/embedding/isa_embed_service.py +305 -0
- isa_model/inference/services/embedding/openai_embed_service.py +2 -4
- isa_model/inference/services/embedding/tests/test_embedding.py +222 -0
- isa_model/inference/services/img/__init__.py +2 -2
- isa_model/inference/services/img/base_image_gen_service.py +24 -7
- isa_model/inference/services/img/replicate_image_gen_service.py +84 -422
- isa_model/inference/services/img/services/replicate_face_swap.py +193 -0
- isa_model/inference/services/img/services/replicate_flux.py +226 -0
- isa_model/inference/services/img/services/replicate_flux_kontext.py +219 -0
- isa_model/inference/services/img/services/replicate_sticker_maker.py +249 -0
- isa_model/inference/services/img/tests/test_img_client.py +297 -0
- isa_model/inference/services/llm/base_llm_service.py +30 -6
- isa_model/inference/services/llm/helpers/llm_adapter.py +63 -9
- isa_model/inference/services/llm/ollama_llm_service.py +2 -1
- isa_model/inference/services/llm/openai_llm_service.py +652 -55
- isa_model/inference/services/llm/yyds_llm_service.py +2 -1
- isa_model/inference/services/vision/__init__.py +5 -5
- isa_model/inference/services/vision/base_vision_service.py +118 -185
- isa_model/inference/services/vision/helpers/image_utils.py +11 -5
- isa_model/inference/services/vision/isa_vision_service.py +573 -0
- isa_model/inference/services/vision/tests/test_ocr_client.py +284 -0
- isa_model/serving/api/fastapi_server.py +88 -16
- isa_model/serving/api/middleware/auth.py +311 -0
- isa_model/serving/api/middleware/security.py +278 -0
- isa_model/serving/api/routes/analytics.py +486 -0
- isa_model/serving/api/routes/deployments.py +339 -0
- isa_model/serving/api/routes/evaluations.py +579 -0
- isa_model/serving/api/routes/logs.py +430 -0
- isa_model/serving/api/routes/settings.py +582 -0
- isa_model/serving/api/routes/unified.py +324 -165
- isa_model/serving/api/startup.py +304 -0
- isa_model/serving/modal_proxy_server.py +249 -0
- isa_model/training/__init__.py +100 -6
- isa_model/training/core/__init__.py +4 -1
- isa_model/training/examples/intelligent_training_example.py +281 -0
- isa_model/training/intelligent/__init__.py +25 -0
- isa_model/training/intelligent/decision_engine.py +643 -0
- isa_model/training/intelligent/intelligent_factory.py +888 -0
- isa_model/training/intelligent/knowledge_base.py +751 -0
- isa_model/training/intelligent/resource_optimizer.py +839 -0
- isa_model/training/intelligent/task_classifier.py +576 -0
- isa_model/training/storage/__init__.py +24 -0
- isa_model/training/storage/core_integration.py +439 -0
- isa_model/training/storage/training_repository.py +552 -0
- isa_model/training/storage/training_storage.py +628 -0
- {isa_model-0.3.9.dist-info → isa_model-0.4.0.dist-info}/METADATA +13 -1
- isa_model-0.4.0.dist-info/RECORD +182 -0
- isa_model/deployment/cloud/modal/isa_vision_doc_service.py +0 -766
- isa_model/deployment/cloud/modal/register_models.py +0 -321
- isa_model/inference/adapter/unified_api.py +0 -248
- isa_model/inference/services/helpers/stacked_config.py +0 -148
- isa_model/inference/services/img/flux_professional_service.py +0 -603
- isa_model/inference/services/img/helpers/base_stacked_service.py +0 -274
- isa_model/inference/services/others/table_transformer_service.py +0 -61
- isa_model/inference/services/vision/doc_analysis_service.py +0 -640
- isa_model/inference/services/vision/helpers/base_stacked_service.py +0 -274
- isa_model/inference/services/vision/ui_analysis_service.py +0 -823
- isa_model/scripts/inference_tracker.py +0 -283
- isa_model/scripts/mlflow_manager.py +0 -379
- isa_model/scripts/model_registry.py +0 -465
- isa_model/scripts/register_models.py +0 -370
- isa_model/scripts/register_models_with_embeddings.py +0 -510
- isa_model/scripts/start_mlflow.py +0 -95
- isa_model/scripts/training_tracker.py +0 -257
- isa_model-0.3.9.dist-info/RECORD +0 -138
- {isa_model-0.3.9.dist-info → isa_model-0.4.0.dist-info}/WHEEL +0 -0
- {isa_model-0.3.9.dist-info → isa_model-0.4.0.dist-info}/top_level.txt +0 -0
@@ -1,274 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Base Stacked Service for orchestrating multiple AI models
|
3
|
-
"""
|
4
|
-
|
5
|
-
from abc import ABC, abstractmethod
|
6
|
-
from typing import Dict, Any, List, Optional, Union, Callable
|
7
|
-
import time
|
8
|
-
import asyncio
|
9
|
-
import logging
|
10
|
-
from dataclasses import dataclass
|
11
|
-
from enum import Enum
|
12
|
-
|
13
|
-
# Import shared types from helpers
|
14
|
-
try:
|
15
|
-
from ..helpers.stacked_config import StackedLayerType as LayerType, LayerConfig, LayerResult
|
16
|
-
except ImportError:
|
17
|
-
# Fallback definitions if shared config is not available
|
18
|
-
class LayerType(Enum):
|
19
|
-
"""Types of processing layers"""
|
20
|
-
INTELLIGENCE = "intelligence"
|
21
|
-
DETECTION = "detection"
|
22
|
-
CLASSIFICATION = "classification"
|
23
|
-
VALIDATION = "validation"
|
24
|
-
TRANSFORMATION = "transformation"
|
25
|
-
GENERATION = "generation"
|
26
|
-
ENHANCEMENT = "enhancement"
|
27
|
-
CONTROL = "control"
|
28
|
-
UPSCALING = "upscaling"
|
29
|
-
|
30
|
-
@dataclass
|
31
|
-
class LayerConfig:
|
32
|
-
"""Configuration for a processing layer"""
|
33
|
-
name: str
|
34
|
-
layer_type: LayerType
|
35
|
-
service_type: str
|
36
|
-
model_name: str
|
37
|
-
parameters: Dict[str, Any]
|
38
|
-
depends_on: List[str]
|
39
|
-
timeout: float = 30.0
|
40
|
-
retry_count: int = 1
|
41
|
-
fallback_enabled: bool = True
|
42
|
-
|
43
|
-
@dataclass
|
44
|
-
class LayerResult:
|
45
|
-
"""Result from a processing layer"""
|
46
|
-
layer_name: str
|
47
|
-
success: bool
|
48
|
-
data: Any
|
49
|
-
metadata: Dict[str, Any]
|
50
|
-
execution_time: float
|
51
|
-
error: Optional[str] = None
|
52
|
-
|
53
|
-
logger = logging.getLogger(__name__)
|
54
|
-
|
55
|
-
class BaseStackedService(ABC):
|
56
|
-
"""
|
57
|
-
Base class for stacked services that orchestrate multiple AI models
|
58
|
-
"""
|
59
|
-
|
60
|
-
def __init__(self, ai_factory, service_name: str):
|
61
|
-
self.ai_factory = ai_factory
|
62
|
-
self.service_name = service_name
|
63
|
-
self.layers: List[LayerConfig] = []
|
64
|
-
self.services: Dict[str, Any] = {}
|
65
|
-
self.results: Dict[str, LayerResult] = {}
|
66
|
-
|
67
|
-
def add_layer(self, config: LayerConfig):
|
68
|
-
"""Add a processing layer to the stack"""
|
69
|
-
self.layers.append(config)
|
70
|
-
logger.info(f"Added layer {config.name} ({config.layer_type.value}) to {self.service_name}")
|
71
|
-
|
72
|
-
async def initialize_services(self):
|
73
|
-
"""Initialize all required services"""
|
74
|
-
for layer in self.layers:
|
75
|
-
service_key = f"{layer.service_type}_{layer.model_name}"
|
76
|
-
|
77
|
-
if service_key not in self.services:
|
78
|
-
if layer.service_type == 'vision':
|
79
|
-
if layer.model_name == "default":
|
80
|
-
# 使用默认vision服务
|
81
|
-
service = self.ai_factory.get_vision()
|
82
|
-
elif layer.model_name == "omniparser":
|
83
|
-
# 使用replicate omniparser
|
84
|
-
service = self.ai_factory.get_vision(model_name="omniparser", provider="replicate")
|
85
|
-
else:
|
86
|
-
# 其他指定模型
|
87
|
-
service = self.ai_factory.get_vision(model_name=layer.model_name)
|
88
|
-
elif layer.service_type == 'llm':
|
89
|
-
if layer.model_name == "default":
|
90
|
-
service = self.ai_factory.get_llm()
|
91
|
-
else:
|
92
|
-
service = self.ai_factory.get_llm(model_name=layer.model_name)
|
93
|
-
elif layer.service_type == 'image_gen':
|
94
|
-
if layer.model_name == "default":
|
95
|
-
service = self.ai_factory.get_image_gen()
|
96
|
-
else:
|
97
|
-
service = self.ai_factory.get_image_gen(model_name=layer.model_name)
|
98
|
-
else:
|
99
|
-
raise ValueError(f"Unsupported service type: {layer.service_type}")
|
100
|
-
|
101
|
-
self.services[service_key] = service
|
102
|
-
logger.info(f"Initialized {service_key} service")
|
103
|
-
|
104
|
-
async def execute_layer(self, layer: LayerConfig, context: Dict[str, Any]) -> LayerResult:
|
105
|
-
"""Execute a single layer"""
|
106
|
-
start_time = time.time()
|
107
|
-
|
108
|
-
try:
|
109
|
-
# Check dependencies
|
110
|
-
for dep in layer.depends_on:
|
111
|
-
if dep not in self.results or not self.results[dep].success:
|
112
|
-
raise ValueError(f"Dependency {dep} failed or not executed")
|
113
|
-
|
114
|
-
# Get the service
|
115
|
-
service_key = f"{layer.service_type}_{layer.model_name}"
|
116
|
-
service = self.services[service_key]
|
117
|
-
|
118
|
-
# Execute layer with timeout
|
119
|
-
data = await asyncio.wait_for(
|
120
|
-
self.execute_layer_logic(layer, service, context),
|
121
|
-
timeout=layer.timeout
|
122
|
-
)
|
123
|
-
|
124
|
-
execution_time = time.time() - start_time
|
125
|
-
|
126
|
-
result = LayerResult(
|
127
|
-
layer_name=layer.name,
|
128
|
-
success=True,
|
129
|
-
data=data,
|
130
|
-
metadata={
|
131
|
-
"layer_type": layer.layer_type.value,
|
132
|
-
"model": layer.model_name,
|
133
|
-
"parameters": layer.parameters
|
134
|
-
},
|
135
|
-
execution_time=execution_time
|
136
|
-
)
|
137
|
-
|
138
|
-
logger.info(f"Layer {layer.name} completed in {execution_time:.2f}s")
|
139
|
-
return result
|
140
|
-
|
141
|
-
except Exception as e:
|
142
|
-
execution_time = time.time() - start_time
|
143
|
-
error_msg = str(e)
|
144
|
-
|
145
|
-
logger.error(f"Layer {layer.name} failed after {execution_time:.2f}s: {error_msg}")
|
146
|
-
|
147
|
-
result = LayerResult(
|
148
|
-
layer_name=layer.name,
|
149
|
-
success=False,
|
150
|
-
data=None,
|
151
|
-
metadata={
|
152
|
-
"layer_type": layer.layer_type.value,
|
153
|
-
"model": layer.model_name,
|
154
|
-
"parameters": layer.parameters
|
155
|
-
},
|
156
|
-
execution_time=execution_time,
|
157
|
-
error=error_msg
|
158
|
-
)
|
159
|
-
|
160
|
-
# Try fallback if enabled
|
161
|
-
if layer.fallback_enabled:
|
162
|
-
fallback_result = await self.execute_fallback(layer, context, error_msg)
|
163
|
-
if fallback_result:
|
164
|
-
result.data = fallback_result
|
165
|
-
result.success = True
|
166
|
-
result.error = f"Fallback used: {error_msg}"
|
167
|
-
|
168
|
-
return result
|
169
|
-
|
170
|
-
@abstractmethod
|
171
|
-
async def execute_layer_logic(self, layer: LayerConfig, service: Any, context: Dict[str, Any]) -> Any:
|
172
|
-
"""Execute the specific logic for a layer - to be implemented by subclasses"""
|
173
|
-
pass
|
174
|
-
|
175
|
-
async def execute_fallback(self, layer: LayerConfig, context: Dict[str, Any], error: str) -> Optional[Any]:
|
176
|
-
"""Execute fallback logic for a failed layer - can be overridden by subclasses"""
|
177
|
-
return None
|
178
|
-
|
179
|
-
async def invoke(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
180
|
-
"""Invoke the entire stack of layers"""
|
181
|
-
logger.info(f"Starting {self.service_name} stack invocation")
|
182
|
-
stack_start_time = time.time()
|
183
|
-
|
184
|
-
# Initialize services if not done
|
185
|
-
if not self.services:
|
186
|
-
await self.initialize_services()
|
187
|
-
|
188
|
-
# Clear previous results
|
189
|
-
self.results.clear()
|
190
|
-
|
191
|
-
# Build execution order based on dependencies
|
192
|
-
execution_order = self._build_execution_order()
|
193
|
-
|
194
|
-
# Execute layers in order
|
195
|
-
context = {"input": input_data, "results": self.results}
|
196
|
-
|
197
|
-
for layer in execution_order:
|
198
|
-
result = await self.execute_layer(layer, context)
|
199
|
-
self.results[layer.name] = result
|
200
|
-
|
201
|
-
# Update context with result
|
202
|
-
context["results"] = self.results
|
203
|
-
|
204
|
-
# Stop if critical layer fails
|
205
|
-
if not result.success and not layer.fallback_enabled:
|
206
|
-
logger.error(f"Critical layer {layer.name} failed, stopping execution")
|
207
|
-
break
|
208
|
-
|
209
|
-
total_time = time.time() - stack_start_time
|
210
|
-
|
211
|
-
# Generate final result
|
212
|
-
final_result = {
|
213
|
-
"service": self.service_name,
|
214
|
-
"success": all(r.success for r in self.results.values()),
|
215
|
-
"total_execution_time": total_time,
|
216
|
-
"layer_results": {name: result for name, result in self.results.items()},
|
217
|
-
"final_output": self.generate_final_output(self.results)
|
218
|
-
}
|
219
|
-
|
220
|
-
logger.info(f"{self.service_name} stack invocation completed in {total_time:.2f}s")
|
221
|
-
return final_result
|
222
|
-
|
223
|
-
def _build_execution_order(self) -> List[LayerConfig]:
|
224
|
-
"""Build execution order based on dependencies"""
|
225
|
-
# Simple topological sort
|
226
|
-
ordered = []
|
227
|
-
remaining = self.layers.copy()
|
228
|
-
|
229
|
-
while remaining:
|
230
|
-
# Find layers with no unmet dependencies
|
231
|
-
ready = []
|
232
|
-
for layer in remaining:
|
233
|
-
deps_met = all(dep in [l.name for l in ordered] for dep in layer.depends_on)
|
234
|
-
if deps_met:
|
235
|
-
ready.append(layer)
|
236
|
-
|
237
|
-
if not ready:
|
238
|
-
raise ValueError("Circular dependency detected in layer configuration")
|
239
|
-
|
240
|
-
# Add ready layers to order
|
241
|
-
ordered.extend(ready)
|
242
|
-
for layer in ready:
|
243
|
-
remaining.remove(layer)
|
244
|
-
|
245
|
-
return ordered
|
246
|
-
|
247
|
-
@abstractmethod
|
248
|
-
def generate_final_output(self, results: Dict[str, LayerResult]) -> Any:
|
249
|
-
"""Generate final output from all layer results - to be implemented by subclasses"""
|
250
|
-
pass
|
251
|
-
|
252
|
-
async def close(self):
|
253
|
-
"""Close all services"""
|
254
|
-
for service in self.services.values():
|
255
|
-
if hasattr(service, 'close'):
|
256
|
-
await service.close()
|
257
|
-
self.services.clear()
|
258
|
-
logger.info(f"Closed all services for {self.service_name}")
|
259
|
-
|
260
|
-
def get_performance_metrics(self) -> Dict[str, Any]:
|
261
|
-
"""Get performance metrics for the stack"""
|
262
|
-
if not self.results:
|
263
|
-
return {}
|
264
|
-
|
265
|
-
metrics = {
|
266
|
-
"total_layers": len(self.results),
|
267
|
-
"successful_layers": sum(1 for r in self.results.values() if r.success),
|
268
|
-
"failed_layers": sum(1 for r in self.results.values() if not r.success),
|
269
|
-
"total_execution_time": sum(r.execution_time for r in self.results.values()),
|
270
|
-
"layer_times": {name: r.execution_time for name, r in self.results.items()},
|
271
|
-
"layer_success": {name: r.success for name, r in self.results.items()}
|
272
|
-
}
|
273
|
-
|
274
|
-
return metrics
|