chore: initialize clean history without secrets
Some checks failed
CI / lint-and-compile (push) Has been cancelled
Some checks failed
CI / lint-and-compile (push) Has been cancelled
This commit is contained in:
84
app/model_map.py
Normal file
84
app/model_map.py
Normal file
@@ -0,0 +1,84 @@
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
DEFAULT_MODEL_NAME_MAP = {
|
||||
"org_auto": "Auto",
|
||||
"dashscope_qmodel": "qwen3.6-plus",
|
||||
"dashscope_qwen3_coder": "qwen3-coder",
|
||||
"dashscope_qwen_plus_20250428_thinking": "qwen3-thinking",
|
||||
"dashscope_qwen_max_latest": "qwen3-max",
|
||||
}
|
||||
|
||||
|
||||
def build_model_name_map(models: dict) -> dict[str, str]:
|
||||
name_map = dict(DEFAULT_MODEL_NAME_MAP)
|
||||
if not isinstance(models, dict):
|
||||
return name_map
|
||||
for group in ("chat", "assistant", "developer", "inline"):
|
||||
items = models.get(group) or []
|
||||
if not isinstance(items, list):
|
||||
continue
|
||||
for item in items:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
key = item.get("key")
|
||||
if not isinstance(key, str) or not key:
|
||||
continue
|
||||
display_name = item.get("displayName") or item.get("name")
|
||||
if isinstance(display_name, str) and display_name.strip():
|
||||
name_map[key] = display_name.strip()
|
||||
return name_map
|
||||
|
||||
|
||||
def reverse_name_map(name_map: dict[str, str]) -> dict[str, str]:
|
||||
rev: dict[str, str] = {}
|
||||
for key, name in name_map.items():
|
||||
if not isinstance(name, str) or not name:
|
||||
continue
|
||||
rev[name] = key
|
||||
rev[name.lower()] = key
|
||||
return rev
|
||||
|
||||
|
||||
def flatten_model_keys(models: dict) -> list[str]:
|
||||
keys: list[str] = []
|
||||
if not isinstance(models, dict):
|
||||
return keys
|
||||
for group in ("chat", "assistant", "developer", "inline"):
|
||||
items = models.get(group) or []
|
||||
if not isinstance(items, list):
|
||||
continue
|
||||
for item in items:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
key = item.get("key")
|
||||
if isinstance(key, str) and key and key not in keys:
|
||||
keys.append(key)
|
||||
return keys
|
||||
|
||||
|
||||
def resolve_model(
|
||||
request_model: str,
|
||||
available_keys: list[str],
|
||||
default_model: str,
|
||||
model_name_map: dict[str, str] | None = None,
|
||||
) -> str:
|
||||
model_name_map = model_name_map or {}
|
||||
rev_map = reverse_name_map(model_name_map)
|
||||
|
||||
if request_model in available_keys:
|
||||
return request_model
|
||||
if request_model in rev_map and rev_map[request_model] in available_keys:
|
||||
return rev_map[request_model]
|
||||
if request_model.lower() in rev_map and rev_map[request_model.lower()] in available_keys:
|
||||
return rev_map[request_model.lower()]
|
||||
if request_model in {"gpt-4o-mini", "gpt-4o", "gpt-4.1", "gpt-3.5-turbo"}:
|
||||
if default_model in available_keys:
|
||||
return default_model
|
||||
if available_keys:
|
||||
return available_keys[0]
|
||||
if default_model in available_keys:
|
||||
return default_model
|
||||
if available_keys:
|
||||
return available_keys[0]
|
||||
return request_model or default_model
|
||||
Reference in New Issue
Block a user