fix: sync logic to filter non-volc models by api_base hash and add debug logs
This commit is contained in:
+99
-9
@@ -106,6 +106,10 @@ VOLC_MODEL_MAP = {
|
|||||||
"glm-4-7": "glm-4-7-251222",
|
"glm-4-7": "glm-4-7-251222",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Whitelist of (model_name, api_base_hash) managed by VolcSync
|
||||||
|
# Populated by active_monitor_loop scanning config.yaml
|
||||||
|
VOLC_MANAGED_PAIRS = set()
|
||||||
|
|
||||||
# Static Quotas (Fallback/Strict Limits)
|
# Static Quotas (Fallback/Strict Limits)
|
||||||
MODEL_QUOTAS = {
|
MODEL_QUOTAS = {
|
||||||
# "deepseek-v3-2-251201:ba0383d3": 1600000,
|
# "deepseek-v3-2-251201:ba0383d3": 1600000,
|
||||||
@@ -441,6 +445,35 @@ class DailyLimitHandler(CustomLogger):
|
|||||||
clean_model = clean_model_name(raw_model)
|
clean_model = clean_model_name(raw_model)
|
||||||
api_base = litellm_params.get("api_base")
|
api_base = litellm_params.get("api_base")
|
||||||
|
|
||||||
|
# FILTER: Only track models explicitly discovered as VolcEngine in config.yaml
|
||||||
|
# This prevents tracking NewAPI aliases that point to other providers
|
||||||
|
current_hash = generate_api_base_hash(api_base)
|
||||||
|
|
||||||
|
# DEBUG: Trace why NewAPI models might be slipping through
|
||||||
|
if DEBUG_MODE or True: # Force print for debugging
|
||||||
|
is_managed = (clean_model, current_hash) in VOLC_MANAGED_PAIRS
|
||||||
|
if not is_managed and VOLC_MANAGED_PAIRS:
|
||||||
|
print(
|
||||||
|
f"DEBUG: Skipping {clean_model} (Hash: {current_hash}) - Not in Managed Pairs",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
elif is_managed:
|
||||||
|
print(
|
||||||
|
f"DEBUG: Tracking {clean_model} (Hash: {current_hash}) - Found in Managed Pairs",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"DEBUG: Permitting {clean_model} (Hash: {current_hash}) - Managed Pairs Empty!",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
VOLC_MANAGED_PAIRS
|
||||||
|
and (clean_model, current_hash) not in VOLC_MANAGED_PAIRS
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
usage = None
|
usage = None
|
||||||
if hasattr(response_obj, "usage"):
|
if hasattr(response_obj, "usage"):
|
||||||
usage = response_obj.usage
|
usage = response_obj.usage
|
||||||
@@ -627,6 +660,8 @@ def process_packages_breakdown(packages):
|
|||||||
|
|
||||||
def active_monitor_loop():
|
def active_monitor_loop():
|
||||||
# Config Discovery
|
# Config Discovery
|
||||||
|
global VOLC_MANAGED_PAIRS
|
||||||
|
VOLC_MANAGED_PAIRS.clear()
|
||||||
INTERESTED_MODELS = set()
|
INTERESTED_MODELS = set()
|
||||||
try:
|
try:
|
||||||
if os.path.exists("config.yaml"):
|
if os.path.exists("config.yaml"):
|
||||||
@@ -640,7 +675,11 @@ def active_monitor_loop():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Robust Parsing Logic
|
# Robust Parsing Logic
|
||||||
current_entry = {"is_volc": False, "upstream_model": None}
|
current_entry = {
|
||||||
|
"is_volc": False,
|
||||||
|
"upstream_model": None,
|
||||||
|
"api_base_val": None,
|
||||||
|
}
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
sline = line.strip()
|
sline = line.strip()
|
||||||
@@ -648,18 +687,54 @@ def active_monitor_loop():
|
|||||||
# Start of a new model definition
|
# Start of a new model definition
|
||||||
if sline.startswith("- model_name:"):
|
if sline.startswith("- model_name:"):
|
||||||
# Commit previous entry if valid
|
# Commit previous entry if valid
|
||||||
if current_entry.get("is_volc") and current_entry.get(
|
if (
|
||||||
"upstream_model"
|
current_entry.get("is_volc")
|
||||||
|
and current_entry.get("upstream_model")
|
||||||
|
and current_entry.get("api_base_val")
|
||||||
):
|
):
|
||||||
INTERESTED_MODELS.add(current_entry["upstream_model"])
|
INTERESTED_MODELS.add(current_entry["upstream_model"])
|
||||||
|
# Compute Hash
|
||||||
|
h = generate_api_base_hash(current_entry["api_base_val"])
|
||||||
|
VOLC_MANAGED_PAIRS.add((current_entry["upstream_model"], h))
|
||||||
|
print(
|
||||||
|
f"✅ [Config] Added Managed Pair: {current_entry['upstream_model']} | Hash: {h} | Base: {str(current_entry['api_base_val'])[:30]}...",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Reset for new entry
|
# Reset for new entry
|
||||||
current_entry = {"is_volc": False, "upstream_model": None}
|
current_entry = {
|
||||||
|
"is_volc": False,
|
||||||
|
"upstream_model": None,
|
||||||
|
"api_base_val": None,
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Check for Volcengine Base URL
|
# Capture API Base & Check for Volcengine
|
||||||
if "api_base:" in sline and "HUOSHAN_BASE_URL" in sline:
|
if "api_base:" in sline:
|
||||||
current_entry["is_volc"] = True
|
try:
|
||||||
|
raw_val = sline.split(":", 1)[1].strip()
|
||||||
|
# Resolve Env Var
|
||||||
|
if raw_val.startswith("os.environ/"):
|
||||||
|
env_key = raw_val.replace("os.environ/", "")
|
||||||
|
resolved_val = os.getenv(env_key, "")
|
||||||
|
if not resolved_val:
|
||||||
|
print(
|
||||||
|
f"⚠️ [Config] Warning: Env var {env_key} resolved to EMPTY!",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
resolved_val = raw_val
|
||||||
|
|
||||||
|
current_entry["api_base_val"] = resolved_val
|
||||||
|
|
||||||
|
# Identify as Volcengine if using HUOSHAN env or specific host
|
||||||
|
if (
|
||||||
|
"HUOSHAN_BASE_URL" in sline
|
||||||
|
or "volcengineapi" in resolved_val
|
||||||
|
):
|
||||||
|
current_entry["is_volc"] = True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# Capture Upstream Model Name
|
# Capture Upstream Model Name
|
||||||
# Matches: "model: openai/deepseek..."
|
# Matches: "model: openai/deepseek..."
|
||||||
@@ -677,13 +752,28 @@ def active_monitor_loop():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Commit the last entry
|
# Commit the last entry
|
||||||
if current_entry.get("is_volc") and current_entry.get("upstream_model"):
|
if (
|
||||||
|
current_entry.get("is_volc")
|
||||||
|
and current_entry.get("upstream_model")
|
||||||
|
and current_entry.get("api_base_val")
|
||||||
|
):
|
||||||
INTERESTED_MODELS.add(current_entry["upstream_model"])
|
INTERESTED_MODELS.add(current_entry["upstream_model"])
|
||||||
|
h = generate_api_base_hash(current_entry["api_base_val"])
|
||||||
|
VOLC_MANAGED_PAIRS.add((current_entry["upstream_model"], h))
|
||||||
|
if DEBUG_MODE:
|
||||||
|
print(
|
||||||
|
f"DEBUG: Added Managed Pair: {current_entry['upstream_model']} @ {h}"
|
||||||
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Auto-discovered / 已自动发现 {len(INTERESTED_MODELS)} Active Volcengine models (Upstream Names): {INTERESTED_MODELS}",
|
f"Auto-discovered / 已自动发现 {len(INTERESTED_MODELS)} Active Volcengine models: {INTERESTED_MODELS}",
|
||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
|
print(
|
||||||
|
f"Managed Pairs Hashes: {[p[1] for p in VOLC_MANAGED_PAIRS]}",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Config Auto-discovery failed / 配置自动发现失败: {e}", flush=True)
|
print(f"Config Auto-discovery failed / 配置自动发现失败: {e}", flush=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user