claude-mpm 4.13.2__py3-none-any.whl → 4.14.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.
Potentially problematic release.
This version of claude-mpm might be problematic. Click here for more details.
- claude_mpm/VERSION +1 -1
- claude_mpm/cli/__init__.py +10 -0
- claude_mpm/cli/commands/local_deploy.py +536 -0
- claude_mpm/cli/parsers/base_parser.py +7 -0
- claude_mpm/cli/parsers/local_deploy_parser.py +227 -0
- claude_mpm/config/model_config.py +428 -0
- claude_mpm/core/interactive_session.py +3 -0
- claude_mpm/services/core/interfaces/__init__.py +74 -2
- claude_mpm/services/core/interfaces/health.py +172 -0
- claude_mpm/services/core/interfaces/model.py +281 -0
- claude_mpm/services/core/interfaces/process.py +372 -0
- claude_mpm/services/core/interfaces/restart.py +307 -0
- claude_mpm/services/core/interfaces/stability.py +260 -0
- claude_mpm/services/core/models/__init__.py +35 -0
- claude_mpm/services/core/models/health.py +189 -0
- claude_mpm/services/core/models/process.py +258 -0
- claude_mpm/services/core/models/restart.py +302 -0
- claude_mpm/services/core/models/stability.py +264 -0
- claude_mpm/services/local_ops/__init__.py +163 -0
- claude_mpm/services/local_ops/crash_detector.py +257 -0
- claude_mpm/services/local_ops/health_checks/__init__.py +28 -0
- claude_mpm/services/local_ops/health_checks/http_check.py +223 -0
- claude_mpm/services/local_ops/health_checks/process_check.py +235 -0
- claude_mpm/services/local_ops/health_checks/resource_check.py +254 -0
- claude_mpm/services/local_ops/health_manager.py +430 -0
- claude_mpm/services/local_ops/log_monitor.py +396 -0
- claude_mpm/services/local_ops/memory_leak_detector.py +294 -0
- claude_mpm/services/local_ops/process_manager.py +595 -0
- claude_mpm/services/local_ops/resource_monitor.py +331 -0
- claude_mpm/services/local_ops/restart_manager.py +401 -0
- claude_mpm/services/local_ops/restart_policy.py +387 -0
- claude_mpm/services/local_ops/state_manager.py +371 -0
- claude_mpm/services/local_ops/unified_manager.py +600 -0
- claude_mpm/services/model/__init__.py +147 -0
- claude_mpm/services/model/base_provider.py +365 -0
- claude_mpm/services/model/claude_provider.py +412 -0
- claude_mpm/services/model/model_router.py +453 -0
- claude_mpm/services/model/ollama_provider.py +415 -0
- {claude_mpm-4.13.2.dist-info → claude_mpm-4.14.0.dist-info}/METADATA +1 -1
- {claude_mpm-4.13.2.dist-info → claude_mpm-4.14.0.dist-info}/RECORD +44 -12
- {claude_mpm-4.13.2.dist-info → claude_mpm-4.14.0.dist-info}/WHEEL +0 -0
- {claude_mpm-4.13.2.dist-info → claude_mpm-4.14.0.dist-info}/entry_points.txt +0 -0
- {claude_mpm-4.13.2.dist-info → claude_mpm-4.14.0.dist-info}/licenses/LICENSE +0 -0
- {claude_mpm-4.13.2.dist-info → claude_mpm-4.14.0.dist-info}/top_level.txt +0 -0
|
@@ -43,6 +43,12 @@ from .communication import ( # WebSocket/SocketIO; Project analysis; Ticket man
|
|
|
43
43
|
TicketManagerInterface,
|
|
44
44
|
)
|
|
45
45
|
|
|
46
|
+
# Health interfaces (health monitoring)
|
|
47
|
+
from .health import ( # Health checks; Health monitoring
|
|
48
|
+
IHealthCheck,
|
|
49
|
+
IHealthCheckManager,
|
|
50
|
+
)
|
|
51
|
+
|
|
46
52
|
# Infrastructure interfaces (core framework services)
|
|
47
53
|
from .infrastructure import ( # Type variables; Core dependency injection; Configuration management; Caching; Health monitoring; Template management; Service factory; Logging; Service lifecycle; Error handling; Performance monitoring; Event system
|
|
48
54
|
CacheEntry,
|
|
@@ -65,11 +71,33 @@ from .infrastructure import ( # Type variables; Core dependency injection; Conf
|
|
|
65
71
|
TemplateRenderContext,
|
|
66
72
|
)
|
|
67
73
|
|
|
74
|
+
# Model interfaces (content processing and model providers)
|
|
75
|
+
from .model import ( # Model providers; Routing
|
|
76
|
+
IModelProvider,
|
|
77
|
+
IModelRouter,
|
|
78
|
+
ModelCapability,
|
|
79
|
+
ModelProvider,
|
|
80
|
+
ModelResponse,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Process interfaces (local process management)
|
|
84
|
+
from .process import ( # Process lifecycle; State persistence
|
|
85
|
+
IDeploymentStateManager,
|
|
86
|
+
ILocalProcessManager,
|
|
87
|
+
)
|
|
88
|
+
|
|
68
89
|
# Project interfaces (project analysis and toolchain detection)
|
|
69
90
|
from .project import ( # Toolchain analysis
|
|
70
91
|
IToolchainAnalyzer,
|
|
71
92
|
)
|
|
72
93
|
|
|
94
|
+
# Restart interfaces (auto-restart management)
|
|
95
|
+
from .restart import ( # Crash detection; Restart policy; Restart orchestration
|
|
96
|
+
ICrashDetector,
|
|
97
|
+
IRestartManager,
|
|
98
|
+
IRestartPolicy,
|
|
99
|
+
)
|
|
100
|
+
|
|
73
101
|
# Service interfaces (business services)
|
|
74
102
|
from .service import ( # Version service; Command handling; Memory management; Session management; Utilities; Hook service
|
|
75
103
|
CommandHandlerInterface,
|
|
@@ -81,6 +109,13 @@ from .service import ( # Version service; Command handling; Memory management;
|
|
|
81
109
|
VersionServiceInterface,
|
|
82
110
|
)
|
|
83
111
|
|
|
112
|
+
# Stability interfaces (proactive monitoring and crash prevention)
|
|
113
|
+
from .stability import ( # Memory leak detection; Log monitoring; Resource monitoring
|
|
114
|
+
ILogMonitor,
|
|
115
|
+
IMemoryLeakDetector,
|
|
116
|
+
IResourceMonitor,
|
|
117
|
+
)
|
|
118
|
+
|
|
84
119
|
|
|
85
120
|
# Interface registry for dependency injection discovery
|
|
86
121
|
class InterfaceRegistry:
|
|
@@ -129,6 +164,23 @@ class InterfaceRegistry:
|
|
|
129
164
|
"toolchain_analyzer": IToolchainAnalyzer,
|
|
130
165
|
"agent_recommender": IAgentRecommender,
|
|
131
166
|
"auto_config_manager": IAutoConfigManager,
|
|
167
|
+
# Model interfaces
|
|
168
|
+
"model_provider": IModelProvider,
|
|
169
|
+
"model_router": IModelRouter,
|
|
170
|
+
# Process interfaces
|
|
171
|
+
"deployment_state_manager": IDeploymentStateManager,
|
|
172
|
+
"local_process_manager": ILocalProcessManager,
|
|
173
|
+
# Health interfaces
|
|
174
|
+
"health_check": IHealthCheck,
|
|
175
|
+
"health_check_manager": IHealthCheckManager,
|
|
176
|
+
# Restart interfaces
|
|
177
|
+
"crash_detector": ICrashDetector,
|
|
178
|
+
"restart_policy": IRestartPolicy,
|
|
179
|
+
"restart_manager": IRestartManager,
|
|
180
|
+
# Stability interfaces
|
|
181
|
+
"memory_leak_detector": IMemoryLeakDetector,
|
|
182
|
+
"log_monitor": ILogMonitor,
|
|
183
|
+
"resource_monitor": IResourceMonitor,
|
|
132
184
|
}
|
|
133
185
|
|
|
134
186
|
@classmethod
|
|
@@ -153,7 +205,7 @@ class InterfaceRegistry:
|
|
|
153
205
|
|
|
154
206
|
|
|
155
207
|
# Re-export everything for backward compatibility
|
|
156
|
-
__all__ = [
|
|
208
|
+
__all__ = [ # noqa: RUF022 - Semantic grouping by domain preferred over alphabetical
|
|
157
209
|
"AgentCapabilitiesInterface",
|
|
158
210
|
"AgentDeploymentInterface",
|
|
159
211
|
"AgentMetadata",
|
|
@@ -168,12 +220,29 @@ __all__ = [
|
|
|
168
220
|
"ICacheService",
|
|
169
221
|
"IConfigurationManager",
|
|
170
222
|
"IConfigurationService",
|
|
223
|
+
# Process interfaces
|
|
224
|
+
"IDeploymentStateManager",
|
|
171
225
|
"IErrorHandler",
|
|
172
226
|
"IEventBus",
|
|
227
|
+
# Health interfaces
|
|
228
|
+
"IHealthCheck",
|
|
229
|
+
"IHealthCheckManager",
|
|
173
230
|
"IHealthMonitor",
|
|
231
|
+
# Infrastructure interfaces
|
|
232
|
+
"ILocalProcessManager",
|
|
233
|
+
# Restart interfaces
|
|
234
|
+
"ICrashDetector",
|
|
235
|
+
"IRestartManager",
|
|
236
|
+
"IRestartPolicy",
|
|
237
|
+
# Stability interfaces
|
|
238
|
+
"IMemoryLeakDetector",
|
|
239
|
+
"ILogMonitor",
|
|
240
|
+
"IResourceMonitor",
|
|
241
|
+
# Model interfaces
|
|
242
|
+
"IModelProvider",
|
|
243
|
+
"IModelRouter",
|
|
174
244
|
"IPerformanceMonitor",
|
|
175
245
|
"IPromptCache",
|
|
176
|
-
# Infrastructure interfaces
|
|
177
246
|
"IServiceContainer",
|
|
178
247
|
"IServiceFactory",
|
|
179
248
|
"IServiceLifecycle",
|
|
@@ -183,6 +252,9 @@ __all__ = [
|
|
|
183
252
|
"IToolchainAnalyzer",
|
|
184
253
|
# Registry
|
|
185
254
|
"InterfaceRegistry",
|
|
255
|
+
"ModelCapability",
|
|
256
|
+
"ModelProvider",
|
|
257
|
+
"ModelResponse",
|
|
186
258
|
"MemoryHookInterface",
|
|
187
259
|
"MemoryServiceInterface",
|
|
188
260
|
"ProjectAnalyzerInterface",
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Health Check Interfaces for Claude MPM Framework
|
|
3
|
+
=================================================
|
|
4
|
+
|
|
5
|
+
WHY: This module defines interfaces for health monitoring operations,
|
|
6
|
+
enabling the local-ops-agent to perform comprehensive health checks on
|
|
7
|
+
deployed processes including HTTP endpoints, process status, and resource usage.
|
|
8
|
+
|
|
9
|
+
DESIGN DECISION: Health check interfaces are separated to enable modular
|
|
10
|
+
health monitoring with different check types (HTTP, process, resource).
|
|
11
|
+
|
|
12
|
+
ARCHITECTURE:
|
|
13
|
+
- IHealthCheck: Interface for individual health check implementations
|
|
14
|
+
- IHealthCheckManager: Interface for orchestrating multiple health checks
|
|
15
|
+
- Health data models defined in models/health.py
|
|
16
|
+
|
|
17
|
+
USAGE:
|
|
18
|
+
http_check = HttpHealthCheck(endpoint="http://localhost:3000/health")
|
|
19
|
+
process_check = ProcessHealthCheck(process_manager)
|
|
20
|
+
resource_check = ResourceHealthCheck(process_manager)
|
|
21
|
+
|
|
22
|
+
health_manager = HealthCheckManager(
|
|
23
|
+
process_manager=process_manager,
|
|
24
|
+
check_interval=30
|
|
25
|
+
)
|
|
26
|
+
health_manager.start_monitoring()
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from abc import ABC, abstractmethod
|
|
30
|
+
from typing import List
|
|
31
|
+
|
|
32
|
+
from claude_mpm.services.core.models.health import (
|
|
33
|
+
DeploymentHealth,
|
|
34
|
+
HealthCheckResult,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class IHealthCheck(ABC):
|
|
39
|
+
"""
|
|
40
|
+
Interface for individual health check implementations.
|
|
41
|
+
|
|
42
|
+
WHY: Abstracts different types of health checks (HTTP, process, resource)
|
|
43
|
+
to enable flexible health monitoring strategies.
|
|
44
|
+
|
|
45
|
+
DESIGN DECISION: Each check type implements this interface to provide
|
|
46
|
+
a consistent API for executing checks and interpreting results.
|
|
47
|
+
|
|
48
|
+
Thread Safety: Implementations must be thread-safe for concurrent execution.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
@abstractmethod
|
|
52
|
+
def check(self, deployment_id: str, **kwargs) -> HealthCheckResult:
|
|
53
|
+
"""
|
|
54
|
+
Execute the health check for a deployment.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
deployment_id: Unique deployment identifier
|
|
58
|
+
**kwargs: Check-specific parameters (e.g., endpoint URL, thresholds)
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
HealthCheckResult with check status and details
|
|
62
|
+
|
|
63
|
+
Raises:
|
|
64
|
+
ValueError: If deployment_id not found
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
@abstractmethod
|
|
68
|
+
def get_check_type(self) -> str:
|
|
69
|
+
"""
|
|
70
|
+
Get the type identifier for this health check.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
Check type string (e.g., "http", "process", "resource")
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class IHealthCheckManager(ABC):
|
|
78
|
+
"""
|
|
79
|
+
Interface for coordinating health checks across deployments.
|
|
80
|
+
|
|
81
|
+
WHY: Health monitoring requires orchestrating multiple check types,
|
|
82
|
+
aggregating results, and maintaining historical data. This interface
|
|
83
|
+
provides a high-level API for comprehensive health monitoring.
|
|
84
|
+
|
|
85
|
+
DESIGN DECISION: Provides both synchronous (check_health) and asynchronous
|
|
86
|
+
(background monitoring) operations to support different use cases.
|
|
87
|
+
|
|
88
|
+
Background Monitoring:
|
|
89
|
+
- Runs health checks at regular intervals
|
|
90
|
+
- Maintains historical health data
|
|
91
|
+
- Triggers callbacks on status changes
|
|
92
|
+
- Thread-safe with proper locking
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
@abstractmethod
|
|
96
|
+
def check_health(self, deployment_id: str) -> DeploymentHealth:
|
|
97
|
+
"""
|
|
98
|
+
Execute all health checks for a deployment.
|
|
99
|
+
|
|
100
|
+
WHY: Provides a comprehensive health snapshot by running all
|
|
101
|
+
registered health checks and aggregating results.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
deployment_id: Unique deployment identifier
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
DeploymentHealth with aggregated status and check results
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
ValueError: If deployment_id not found
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
@abstractmethod
|
|
114
|
+
def start_monitoring(self) -> None:
|
|
115
|
+
"""
|
|
116
|
+
Start background health monitoring.
|
|
117
|
+
|
|
118
|
+
WHY: Enables continuous health tracking without manual polling.
|
|
119
|
+
Monitoring runs in a separate daemon thread.
|
|
120
|
+
|
|
121
|
+
Thread Safety: Creates a daemon thread that performs periodic checks.
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
@abstractmethod
|
|
125
|
+
def stop_monitoring(self) -> None:
|
|
126
|
+
"""
|
|
127
|
+
Stop background health monitoring.
|
|
128
|
+
|
|
129
|
+
WHY: Gracefully stops the monitoring thread and releases resources.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
@abstractmethod
|
|
133
|
+
def is_monitoring(self) -> bool:
|
|
134
|
+
"""
|
|
135
|
+
Check if background monitoring is active.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
True if monitoring thread is running
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
@abstractmethod
|
|
142
|
+
def get_health_history(
|
|
143
|
+
self, deployment_id: str, limit: int = 10
|
|
144
|
+
) -> List[DeploymentHealth]:
|
|
145
|
+
"""
|
|
146
|
+
Get historical health check results for a deployment.
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
deployment_id: Unique deployment identifier
|
|
150
|
+
limit: Maximum number of historical entries to return
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
List of DeploymentHealth objects, newest first
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
@abstractmethod
|
|
157
|
+
def register_status_callback(self, callback) -> None:
|
|
158
|
+
"""
|
|
159
|
+
Register a callback for health status changes.
|
|
160
|
+
|
|
161
|
+
WHY: Enables reactive behavior based on health status changes
|
|
162
|
+
(e.g., alerts, auto-recovery, logging).
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
callback: Function called with (deployment_id, old_status, new_status)
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
__all__ = [
|
|
170
|
+
"IHealthCheck",
|
|
171
|
+
"IHealthCheckManager",
|
|
172
|
+
]
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Model Provider Interfaces for Claude MPM Framework
|
|
3
|
+
==================================================
|
|
4
|
+
|
|
5
|
+
WHY: This module defines the interfaces for content processing model providers,
|
|
6
|
+
enabling support for both local (Ollama) and cloud (Claude) models with
|
|
7
|
+
intelligent routing and auto-fallback capabilities.
|
|
8
|
+
|
|
9
|
+
DESIGN DECISION: Model providers implement a common interface (IModelProvider)
|
|
10
|
+
to enable polymorphic use and easy switching between providers. The abstraction
|
|
11
|
+
allows for provider-specific optimizations while maintaining a consistent API.
|
|
12
|
+
|
|
13
|
+
ARCHITECTURE:
|
|
14
|
+
- IModelProvider: Core provider interface for content analysis
|
|
15
|
+
- ModelCapability: Enum of supported content processing tasks
|
|
16
|
+
- ModelProvider: Enum of available provider types
|
|
17
|
+
- ModelResponse: Standardized response format across providers
|
|
18
|
+
|
|
19
|
+
USAGE:
|
|
20
|
+
provider = OllamaProvider()
|
|
21
|
+
if await provider.is_available():
|
|
22
|
+
response = await provider.analyze_content(
|
|
23
|
+
content="Your text here",
|
|
24
|
+
task=ModelCapability.SEO_ANALYSIS
|
|
25
|
+
)
|
|
26
|
+
if response.success:
|
|
27
|
+
print(f"Analysis from {response.model}: {response.result}")
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from abc import ABC, abstractmethod
|
|
31
|
+
from dataclasses import dataclass, field
|
|
32
|
+
from enum import Enum
|
|
33
|
+
from typing import Any, Dict, List, Optional
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ModelCapability(Enum):
|
|
37
|
+
"""
|
|
38
|
+
Content processing capabilities supported by model providers.
|
|
39
|
+
|
|
40
|
+
WHY: Defines task-specific analysis types for content processing.
|
|
41
|
+
Each capability may route to different models optimized for that task.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
SEO_ANALYSIS = "seo_analysis"
|
|
45
|
+
READABILITY = "readability"
|
|
46
|
+
GRAMMAR = "grammar"
|
|
47
|
+
SUMMARIZATION = "summarization"
|
|
48
|
+
KEYWORD_EXTRACTION = "keyword_extraction"
|
|
49
|
+
ACCESSIBILITY = "accessibility"
|
|
50
|
+
SENTIMENT = "sentiment"
|
|
51
|
+
GENERAL = "general"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class ModelProvider(Enum):
|
|
55
|
+
"""
|
|
56
|
+
Available model provider backends.
|
|
57
|
+
|
|
58
|
+
WHY: Enables configuration-based routing between providers.
|
|
59
|
+
|
|
60
|
+
Values:
|
|
61
|
+
CLAUDE: Cloud-based Claude API (always available)
|
|
62
|
+
OLLAMA: Local Ollama installation (requires local setup)
|
|
63
|
+
AUTO: Intelligent routing with Ollama-first, Claude fallback
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
CLAUDE = "claude"
|
|
67
|
+
OLLAMA = "ollama"
|
|
68
|
+
AUTO = "auto"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class ModelResponse:
|
|
73
|
+
"""
|
|
74
|
+
Standardized response from model providers.
|
|
75
|
+
|
|
76
|
+
WHY: Provides consistent response format across all providers,
|
|
77
|
+
enabling transparent provider switching and unified error handling.
|
|
78
|
+
|
|
79
|
+
Attributes:
|
|
80
|
+
success: Whether the operation succeeded
|
|
81
|
+
provider: Name of provider that handled request (e.g., "ollama", "claude")
|
|
82
|
+
model: Specific model used (e.g., "llama3.3:70b", "claude-3-5-sonnet")
|
|
83
|
+
task: Task that was performed
|
|
84
|
+
result: Analysis result text
|
|
85
|
+
metadata: Provider-specific metadata (tokens, timing, etc.)
|
|
86
|
+
error: Error message if success=False
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
success: bool
|
|
90
|
+
provider: str
|
|
91
|
+
model: str
|
|
92
|
+
task: str
|
|
93
|
+
result: str
|
|
94
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
95
|
+
error: Optional[str] = None
|
|
96
|
+
|
|
97
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
98
|
+
"""Convert response to dictionary for serialization."""
|
|
99
|
+
return {
|
|
100
|
+
"success": self.success,
|
|
101
|
+
"provider": self.provider,
|
|
102
|
+
"model": self.model,
|
|
103
|
+
"task": self.task,
|
|
104
|
+
"result": self.result,
|
|
105
|
+
"metadata": self.metadata,
|
|
106
|
+
"error": self.error,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class IModelProvider(ABC):
|
|
111
|
+
"""
|
|
112
|
+
Interface for content processing model providers.
|
|
113
|
+
|
|
114
|
+
WHY: Defines contract for all model providers (Claude, Ollama, future providers).
|
|
115
|
+
Enables polymorphic use and easy provider switching without changing client code.
|
|
116
|
+
|
|
117
|
+
DESIGN PATTERN: Strategy pattern - allows runtime selection of model provider
|
|
118
|
+
based on availability, configuration, and task requirements.
|
|
119
|
+
|
|
120
|
+
Implementations should:
|
|
121
|
+
- Handle provider-specific connection management
|
|
122
|
+
- Map capabilities to optimal models
|
|
123
|
+
- Provide robust error handling
|
|
124
|
+
- Return standardized ModelResponse objects
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
@abstractmethod
|
|
128
|
+
async def is_available(self) -> bool:
|
|
129
|
+
"""
|
|
130
|
+
Check if provider is available and functional.
|
|
131
|
+
|
|
132
|
+
WHY: Enables auto-fallback routing. Local providers may not always be
|
|
133
|
+
available (Ollama not running), while cloud providers need API keys.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
True if provider is ready to handle requests
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
@abstractmethod
|
|
140
|
+
async def analyze_content(
|
|
141
|
+
self,
|
|
142
|
+
content: str,
|
|
143
|
+
task: ModelCapability,
|
|
144
|
+
model: Optional[str] = None,
|
|
145
|
+
**kwargs,
|
|
146
|
+
) -> ModelResponse:
|
|
147
|
+
"""
|
|
148
|
+
Analyze content with specified task.
|
|
149
|
+
|
|
150
|
+
WHY: Core content processing method. Handles all analysis types
|
|
151
|
+
with task-specific prompting and model selection.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
content: Text content to analyze
|
|
155
|
+
task: Type of analysis to perform
|
|
156
|
+
model: Optional specific model to use (overrides default)
|
|
157
|
+
**kwargs: Provider-specific options (temperature, max_tokens, etc.)
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
ModelResponse with analysis results or error
|
|
161
|
+
|
|
162
|
+
Example:
|
|
163
|
+
response = await provider.analyze_content(
|
|
164
|
+
content="Your article text",
|
|
165
|
+
task=ModelCapability.SEO_ANALYSIS,
|
|
166
|
+
temperature=0.7
|
|
167
|
+
)
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
@abstractmethod
|
|
171
|
+
def get_supported_capabilities(self) -> List[ModelCapability]:
|
|
172
|
+
"""
|
|
173
|
+
Return list of capabilities this provider supports.
|
|
174
|
+
|
|
175
|
+
WHY: Enables capability-based routing. Some providers may not
|
|
176
|
+
support all task types.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
List of supported ModelCapability values
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
@abstractmethod
|
|
183
|
+
async def get_available_models(self) -> List[str]:
|
|
184
|
+
"""
|
|
185
|
+
List models available from this provider.
|
|
186
|
+
|
|
187
|
+
WHY: Enables model validation and user selection. Local providers
|
|
188
|
+
may have different models installed than expected.
|
|
189
|
+
|
|
190
|
+
Returns:
|
|
191
|
+
List of model names/identifiers
|
|
192
|
+
|
|
193
|
+
Example:
|
|
194
|
+
models = await provider.get_available_models()
|
|
195
|
+
# ["llama3.3:70b", "gemma2:9b", "mistral:7b"]
|
|
196
|
+
"""
|
|
197
|
+
|
|
198
|
+
@abstractmethod
|
|
199
|
+
async def get_model_info(self, model: str) -> Dict[str, Any]:
|
|
200
|
+
"""
|
|
201
|
+
Get detailed information about a specific model.
|
|
202
|
+
|
|
203
|
+
WHY: Provides model metadata for UI display and capability checking.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
model: Model name/identifier
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
Dictionary with model details (size, parameters, capabilities, etc.)
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
@abstractmethod
|
|
213
|
+
async def shutdown(self) -> None:
|
|
214
|
+
"""
|
|
215
|
+
Shutdown provider and cleanup resources.
|
|
216
|
+
|
|
217
|
+
WHY: Proper resource cleanup for connection pools, HTTP sessions, etc.
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class IModelRouter(ABC):
|
|
222
|
+
"""
|
|
223
|
+
Interface for intelligent model routing with fallback.
|
|
224
|
+
|
|
225
|
+
WHY: Manages provider selection and fallback logic. Routes requests
|
|
226
|
+
to optimal provider based on availability and configuration.
|
|
227
|
+
|
|
228
|
+
DESIGN PATTERN: Chain of Responsibility - tries providers in order
|
|
229
|
+
until one succeeds or all fail.
|
|
230
|
+
"""
|
|
231
|
+
|
|
232
|
+
@abstractmethod
|
|
233
|
+
async def analyze_content(
|
|
234
|
+
self,
|
|
235
|
+
content: str,
|
|
236
|
+
task: ModelCapability,
|
|
237
|
+
model: Optional[str] = None,
|
|
238
|
+
**kwargs,
|
|
239
|
+
) -> ModelResponse:
|
|
240
|
+
"""
|
|
241
|
+
Route content analysis to optimal provider.
|
|
242
|
+
|
|
243
|
+
WHY: Single entry point for all content analysis. Handles provider
|
|
244
|
+
selection, fallback, and error recovery transparently.
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
content: Text content to analyze
|
|
248
|
+
task: Type of analysis to perform
|
|
249
|
+
model: Optional specific model to use
|
|
250
|
+
**kwargs: Provider-specific options
|
|
251
|
+
|
|
252
|
+
Returns:
|
|
253
|
+
ModelResponse from successful provider
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
@abstractmethod
|
|
257
|
+
def get_active_provider(self) -> Optional[str]:
|
|
258
|
+
"""
|
|
259
|
+
Get name of currently active provider.
|
|
260
|
+
|
|
261
|
+
Returns:
|
|
262
|
+
Provider name or None if no provider active
|
|
263
|
+
"""
|
|
264
|
+
|
|
265
|
+
@abstractmethod
|
|
266
|
+
async def get_provider_status(self) -> Dict[str, Dict[str, Any]]:
|
|
267
|
+
"""
|
|
268
|
+
Get status of all configured providers.
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
Dictionary mapping provider names to status info
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
__all__ = [
|
|
276
|
+
"IModelProvider",
|
|
277
|
+
"IModelRouter",
|
|
278
|
+
"ModelCapability",
|
|
279
|
+
"ModelProvider",
|
|
280
|
+
"ModelResponse",
|
|
281
|
+
]
|