Fix: Sync ALL discovered VolcEngine models to Redis, ignoring INTERESTED_MODELS filter for cache
This commit is contained in:
+38
-27
@@ -90,6 +90,7 @@ SUFFIXES_TO_REMOVE = [
|
||||
"_free_inference_resource_pack",
|
||||
"free_inference_resource_pack",
|
||||
"_infer_res_pack",
|
||||
"-free-infer-res-pack", # Matches: DeepSeek-V3-free-infer-res-pack
|
||||
]
|
||||
|
||||
# Volcengine Name -> LiteLLM Model Name Map
|
||||
@@ -598,6 +599,18 @@ def process_packages_breakdown(packages):
|
||||
for model_name in target_models:
|
||||
if model_name == "unknown":
|
||||
continue
|
||||
# Aggregate balances (Handle float string '123.00' -> float -> int)
|
||||
try:
|
||||
amount = int(float(available))
|
||||
except ValueError:
|
||||
print(f"Error converting available amount '{available}' to int for {model_name}")
|
||||
amount = 0
|
||||
|
||||
model_counts[model_name] = model_counts.get(model_name, 0) + amount
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error processing package: {e}")
|
||||
continue
|
||||
# Aggregate balances
|
||||
model_counts[model_name] = model_counts.get(model_name, 0) + int(
|
||||
available
|
||||
@@ -767,42 +780,40 @@ def active_monitor_loop():
|
||||
flush=True,
|
||||
)
|
||||
|
||||
# Target Resolution
|
||||
targets = []
|
||||
if model_name in VOLC_MODEL_MAP:
|
||||
val = VOLC_MODEL_MAP[model_name]
|
||||
targets = val if isinstance(val, list) else [val]
|
||||
if not targets:
|
||||
targets = [model_name] # Empty string case
|
||||
else:
|
||||
targets = [model_name]
|
||||
# Target Resolution (Already handled in process_packages_breakdown mostly)
|
||||
# But we'll treat model_name as the target since process_packages_breakdown now handles the list logic
|
||||
targets = [model_name]
|
||||
|
||||
for target in targets:
|
||||
# Only set keys for models we are actually using (found in config)
|
||||
# BUT we must set ALL keys to ensure we don't miss any aliases.
|
||||
# Optimization: Check if target is in INTERESTED_MODELS
|
||||
if target in INTERESTED_MODELS:
|
||||
configured_models_found = True
|
||||
# Optimization: Sync ALL balances found in the VolcEngine account
|
||||
# Reason: Some models might be used via aliases (e.g. NewAPI) or not explicitly in config
|
||||
# but belong to the same account. We should cache their quota regardless.
|
||||
|
||||
# Use normalized key for storage
|
||||
# Format: limit:dynamic:volcengine:remaining:{model_name}
|
||||
dynamic_key = f"limit:dynamic:volcengine:remaining:{target}"
|
||||
|
||||
if DEBUG_MODE:
|
||||
is_interested = " (Configured)" if target in INTERESTED_MODELS else " (Auto-Found)"
|
||||
print(
|
||||
f"DEBUG: Checking {target}{is_interested} (Bal: {int(balance)}, Rem: {int(remaining)})",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
# Use normalized key for storage
|
||||
# Format: limit:dynamic:volcengine:remaining:{model_name}
|
||||
dynamic_key = f"limit:dynamic:volcengine:remaining:{target}"
|
||||
|
||||
# Set with expiry (slightly longer than max interval)
|
||||
redis_client.setex(dynamic_key, 7200, int(remaining))
|
||||
# Set with expiry (24h)
|
||||
redis_client.setex(dynamic_key, 86400, int(remaining))
|
||||
if DEBUG_MODE:
|
||||
print(
|
||||
f"DEBUG: Set Redis {dynamic_key} = {int(remaining)}",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
if remaining < temp_min_remaining:
|
||||
# Only count INTERESTED models for global min tracking (frequency control)
|
||||
if target in INTERESTED_MODELS:
|
||||
configured_models_found = True
|
||||
if remaining < temp_min_remaining:
|
||||
temp_min_remaining = remaining
|
||||
else:
|
||||
if DEBUG_MODE:
|
||||
print(
|
||||
f"DEBUG: Skipping {target} (Not in INTERESTED_MODELS)",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
|
||||
global_min_remaining = temp_min_remaining if model_balances else 0
|
||||
last_usage_map["global"] = current_usage_global
|
||||
|
||||
Reference in New Issue
Block a user