Fix: Sync ALL discovered VolcEngine models to Redis, ignoring INTERESTED_MODELS filter for cache

This commit is contained in:
kim
2026-01-29 18:11:59 +08:00
parent 2ceec7f1c6
commit fb77e4047c
+37 -26
View File
@@ -90,6 +90,7 @@ SUFFIXES_TO_REMOVE = [
"_free_inference_resource_pack", "_free_inference_resource_pack",
"free_inference_resource_pack", "free_inference_resource_pack",
"_infer_res_pack", "_infer_res_pack",
"-free-infer-res-pack", # Matches: DeepSeek-V3-free-infer-res-pack
] ]
# Volcengine Name -> LiteLLM Model Name Map # Volcengine Name -> LiteLLM Model Name Map
@@ -598,6 +599,18 @@ def process_packages_breakdown(packages):
for model_name in target_models: for model_name in target_models:
if model_name == "unknown": if model_name == "unknown":
continue 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 # Aggregate balances
model_counts[model_name] = model_counts.get(model_name, 0) + int( model_counts[model_name] = model_counts.get(model_name, 0) + int(
available available
@@ -767,42 +780,40 @@ def active_monitor_loop():
flush=True, flush=True,
) )
# Target Resolution # Target Resolution (Already handled in process_packages_breakdown mostly)
targets = [] # But we'll treat model_name as the target since process_packages_breakdown now handles the list logic
if model_name in VOLC_MODEL_MAP: targets = [model_name]
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]
for target in targets: for target in targets:
# Only set keys for models we are actually using (found in config) # Optimization: Sync ALL balances found in the VolcEngine account
# BUT we must set ALL keys to ensure we don't miss any aliases. # Reason: Some models might be used via aliases (e.g. NewAPI) or not explicitly in config
# Optimization: Check if target is in INTERESTED_MODELS # but belong to the same account. We should cache their quota regardless.
if target in INTERESTED_MODELS:
configured_models_found = True
# Use normalized key for storage # Use normalized key for storage
# Format: limit:dynamic:volcengine:remaining:{model_name} # Format: limit:dynamic:volcengine:remaining:{model_name}
dynamic_key = f"limit:dynamic:volcengine:remaining:{target}" dynamic_key = f"limit:dynamic:volcengine:remaining:{target}"
# Set with expiry (slightly longer than max interval) if DEBUG_MODE:
redis_client.setex(dynamic_key, 7200, int(remaining)) 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,
)
# Set with expiry (24h)
redis_client.setex(dynamic_key, 86400, int(remaining))
if DEBUG_MODE:
print( print(
f"DEBUG: Set Redis {dynamic_key} = {int(remaining)}", f"DEBUG: Set Redis {dynamic_key} = {int(remaining)}",
flush=True, 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 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 global_min_remaining = temp_min_remaining if model_balances else 0
last_usage_map["global"] = current_usage_global last_usage_map["global"] = current_usage_global