Spaces:
Paused
Paused
Commit
·
04c79ee
1
Parent(s):
8b27505
bug fixes
Browse files- app/express_key_manager.py +8 -12
app/express_key_manager.py
CHANGED
|
@@ -18,14 +18,10 @@ class ExpressKeyManager:
|
|
| 18 |
"""Get the total number of available Express API keys."""
|
| 19 |
return len(self.express_keys)
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
"""Return a tuple of (key, original_index) for logging purposes."""
|
| 23 |
-
return (key, index)
|
| 24 |
-
|
| 25 |
-
def get_random_express_key(self) -> Optional[Tuple[str, int]]:
|
| 26 |
"""
|
| 27 |
Get a random Express API key.
|
| 28 |
-
Returns (
|
| 29 |
"""
|
| 30 |
if not self.express_keys:
|
| 31 |
print("WARNING: No Express API keys available for selection.")
|
|
@@ -40,12 +36,12 @@ class ExpressKeyManager:
|
|
| 40 |
|
| 41 |
# Return the first key (which is random due to shuffle)
|
| 42 |
original_idx, key = indexed_keys[0]
|
| 43 |
-
return
|
| 44 |
|
| 45 |
-
def get_roundrobin_express_key(self) -> Optional[Tuple[
|
| 46 |
"""
|
| 47 |
Get an Express API key using round-robin selection.
|
| 48 |
-
Returns (
|
| 49 |
"""
|
| 50 |
if not self.express_keys:
|
| 51 |
print("WARNING: No Express API keys available for selection.")
|
|
@@ -64,13 +60,13 @@ class ExpressKeyManager:
|
|
| 64 |
# Move to next index for next call
|
| 65 |
self.round_robin_index = (self.round_robin_index + 1) % len(self.express_keys)
|
| 66 |
|
| 67 |
-
return
|
| 68 |
|
| 69 |
-
def get_express_api_key(self) -> Optional[Tuple[
|
| 70 |
"""
|
| 71 |
Get an Express API key based on the configured selection strategy.
|
| 72 |
Checks ROUNDROBIN config and calls the appropriate method.
|
| 73 |
-
Returns (
|
| 74 |
"""
|
| 75 |
if app_config.ROUNDROBIN:
|
| 76 |
return self.get_roundrobin_express_key()
|
|
|
|
| 18 |
"""Get the total number of available Express API keys."""
|
| 19 |
return len(self.express_keys)
|
| 20 |
|
| 21 |
+
def get_random_express_key(self) -> Optional[Tuple[int, str]]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
"""
|
| 23 |
Get a random Express API key.
|
| 24 |
+
Returns (original_index, key) tuple or None if no keys available.
|
| 25 |
"""
|
| 26 |
if not self.express_keys:
|
| 27 |
print("WARNING: No Express API keys available for selection.")
|
|
|
|
| 36 |
|
| 37 |
# Return the first key (which is random due to shuffle)
|
| 38 |
original_idx, key = indexed_keys[0]
|
| 39 |
+
return (original_idx, key)
|
| 40 |
|
| 41 |
+
def get_roundrobin_express_key(self) -> Optional[Tuple[int, str]]:
|
| 42 |
"""
|
| 43 |
Get an Express API key using round-robin selection.
|
| 44 |
+
Returns (original_index, key) tuple or None if no keys available.
|
| 45 |
"""
|
| 46 |
if not self.express_keys:
|
| 47 |
print("WARNING: No Express API keys available for selection.")
|
|
|
|
| 60 |
# Move to next index for next call
|
| 61 |
self.round_robin_index = (self.round_robin_index + 1) % len(self.express_keys)
|
| 62 |
|
| 63 |
+
return (original_idx, key)
|
| 64 |
|
| 65 |
+
def get_express_api_key(self) -> Optional[Tuple[int, str]]:
|
| 66 |
"""
|
| 67 |
Get an Express API key based on the configured selection strategy.
|
| 68 |
Checks ROUNDROBIN config and calls the appropriate method.
|
| 69 |
+
Returns (original_index, key) tuple or None if no keys available.
|
| 70 |
"""
|
| 71 |
if app_config.ROUNDROBIN:
|
| 72 |
return self.get_roundrobin_express_key()
|