(self, config: Dict, fallback_client=None)
| 105 | """OpenAI-compatible client that proxies to multiple providers""" |
| 106 | |
| 107 | def __init__(self, config: Dict, fallback_client=None): |
| 108 | self.config = config |
| 109 | self.fallback_client = fallback_client |
| 110 | |
| 111 | # Initialize providers |
| 112 | self.providers = [ |
| 113 | Provider(p) for p in config.get('providers', []) |
| 114 | ] |
| 115 | |
| 116 | # Filter out fallback-only providers for normal routing |
| 117 | self.active_providers = [ |
| 118 | p for p in self.providers if not p.fallback_only |
| 119 | ] |
| 120 | |
| 121 | self.fallback_providers = [ |
| 122 | p for p in self.providers if p.fallback_only |
| 123 | ] |
| 124 | |
| 125 | # Initialize router |
| 126 | strategy = config.get('routing', {}).get('strategy', 'round_robin') |
| 127 | self.router = RouterFactory.create(strategy, self.active_providers) |
| 128 | |
| 129 | # Initialize health checker |
| 130 | health_config = config.get('routing', {}).get('health_check', {}) |
| 131 | self.health_checker = HealthChecker( |
| 132 | providers=self.providers, |
| 133 | enabled=health_config.get('enabled', True), |
| 134 | interval=health_config.get('interval', 30), |
| 135 | timeout=health_config.get('timeout', 5) |
| 136 | ) |
| 137 | |
| 138 | # Start health checking |
| 139 | self.health_checker.start() |
| 140 | |
| 141 | # Timeout settings |
| 142 | timeout_config = config.get('timeouts', {}) |
| 143 | self.request_timeout = timeout_config.get('request', 30) # Default 30 seconds |
| 144 | self.connect_timeout = timeout_config.get('connect', 5) # Default 5 seconds |
| 145 | |
| 146 | # Queue management settings |
| 147 | queue_config = config.get('queue', {}) |
| 148 | self.max_concurrent_requests = queue_config.get('max_concurrent', 100) |
| 149 | self.queue_timeout = queue_config.get('timeout', 60) # Max time in queue |
| 150 | self._request_semaphore = threading.Semaphore(self.max_concurrent_requests) |
| 151 | |
| 152 | # Monitoring settings |
| 153 | monitoring = config.get('monitoring', {}) |
| 154 | self.track_latency = monitoring.get('track_latency', True) |
| 155 | self.track_errors = monitoring.get('track_errors', True) |
| 156 | |
| 157 | # Create chat namespace |
| 158 | self.chat = self._Chat(self) |
| 159 | |
| 160 | class _Chat: |
| 161 | def __init__(self, proxy_client): |
nothing calls this directly
no test coverage detected