将简化模型名 + generationConfig 参数解析为内部 MODEL_CONFIG key。 如果 model 已经是有效的 MODEL_CONFIG key,直接返回。 如果 model 是简化名(基础模型名),则根据 generationConfig 中的 aspectRatio / imageSize 拼接出完整的内部模型名。 Args: model: 请求中的模型名 request: ChatCompletionRequest 实例(用于提取 generationConfig) model_c
(
model: str, request=None, model_config: Dict[str, Any] = None, images: Any = None
)
| 614 | |
| 615 | |
| 616 | def resolve_model_name( |
| 617 | model: str, request=None, model_config: Dict[str, Any] = None, images: Any = None |
| 618 | ) -> str: |
| 619 | """将简化模型名 + generationConfig 参数解析为内部 MODEL_CONFIG key。 |
| 620 | |
| 621 | 如果 model 已经是有效的 MODEL_CONFIG key,直接返回。 |
| 622 | 如果 model 是简化名(基础模型名),则根据 generationConfig 中的 |
| 623 | aspectRatio / imageSize 拼接出完整的内部模型名。 |
| 624 | |
| 625 | Args: |
| 626 | model: 请求中的模型名 |
| 627 | request: ChatCompletionRequest 实例(用于提取 generationConfig) |
| 628 | model_config: MODEL_CONFIG 字典(用于验证解析后的模型名) |
| 629 | |
| 630 | Returns: |
| 631 | 解析后的内部模型名 |
| 632 | """ |
| 633 | # ────── 图片模型解析 ────── |
| 634 | if model in IMAGE_BASE_MODELS: |
| 635 | base = IMAGE_BASE_MODELS[model] |
| 636 | aspect_ratio, image_size = ( |
| 637 | _extract_generation_params(request) if request else (None, None) |
| 638 | ) |
| 639 | |
| 640 | if not aspect_ratio: |
| 641 | aspect_ratio = _infer_aspect_ratio_from_images(images) |
| 642 | |
| 643 | # 默认 aspect ratio |
| 644 | if not aspect_ratio: |
| 645 | aspect_ratio = DEFAULT_ASPECT |
| 646 | |
| 647 | # 检查支持的 aspect ratio |
| 648 | supported_aspects = MODEL_SUPPORTED_ASPECTS.get(base, []) |
| 649 | if aspect_ratio not in supported_aspects and supported_aspects: |
| 650 | debug_logger.log_warning( |
| 651 | f"[MODEL_RESOLVER] 模型 {base} 不支持 aspectRatio={aspect_ratio}," |
| 652 | f"降级到 {DEFAULT_ASPECT}" |
| 653 | ) |
| 654 | aspect_ratio = DEFAULT_ASPECT |
| 655 | |
| 656 | # 拼接模型名 |
| 657 | resolved = f"{base}-{aspect_ratio}" |
| 658 | |
| 659 | # 检查支持的 imageSize |
| 660 | if image_size and image_size != "1k": |
| 661 | supported_sizes = MODEL_SUPPORTED_SIZES.get(base, []) |
| 662 | if image_size in supported_sizes: |
| 663 | resolved = f"{resolved}-{image_size}" |
| 664 | else: |
| 665 | debug_logger.log_warning( |
| 666 | f"[MODEL_RESOLVER] 模型 {base} 不支持 imageSize={image_size},忽略" |
| 667 | ) |
| 668 | |
| 669 | # 最终验证 |
| 670 | if model_config and resolved not in model_config: |
| 671 | debug_logger.log_warning( |
| 672 | f"[MODEL_RESOLVER] 解析后的模型名 {resolved} 不在 MODEL_CONFIG 中," |
| 673 | f"回退到原始模型名 {model}" |