feat(pineagents): 模型静态展示目录(描述/价格/分类/标签) + ModelInfo 扩展
- ModelInfo 追加可选 description/price/category/tags(默认为空,不破坏现有构造,经 model_dump + response_model 自动透传前端,无需改序列化)。 - 新增 providers/pineagents_catalog.py:按模型 id 的静态展示目录(覆盖 Qwen/DeepSeek/ GLM/Kimi/MiniMax/MiMo/ModelScope 等) + enrich_catalog() 在拉取结果上回填;未命中 优雅降级为仅名+能力标签,不修改调用参数。 - provider_manager.list_provider_info:pineagents 拉取成功后回填目录元数据。 - 新增 tests/test_pineagents_catalog.py(命中/免费/未命中/空/大小写),6 passed。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""PineAgents 模型静态展示目录单测。"""
|
||||
import pytest
|
||||
|
||||
from pineagents.providers.pineagents_catalog import (
|
||||
PINEAGENTS_MODEL_CATALOG as _catalog_pub,
|
||||
enrich_catalog,
|
||||
)
|
||||
from pineagents.providers.provider import ModelInfo
|
||||
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
|
||||
def test_enrich_catalog_hit_fills_metadata():
|
||||
"""命中目录:回填描述/价格/分类/标签/is_free,且不改调用参数。"""
|
||||
src = [
|
||||
ModelInfo(
|
||||
id="qwen3.7-max",
|
||||
name="Qwen3.7 Max",
|
||||
supports_image=False,
|
||||
supports_video=False,
|
||||
thinking_enabled=True,
|
||||
)
|
||||
]
|
||||
out = enrich_catalog(src)
|
||||
m = out[0]
|
||||
assert m.description
|
||||
assert m.price
|
||||
assert m.category == "文本"
|
||||
assert m.tags
|
||||
# 调用参数保持不变
|
||||
assert m.thinking_enabled is True
|
||||
assert m.supports_multimodal is None
|
||||
|
||||
|
||||
def test_enrich_catalog_free_model():
|
||||
"""免费模型 is_free 命中为 True。"""
|
||||
out = enrich_catalog([ModelInfo(id="Qwen/Qwen3.5-122B-A10B", name="Q3.5")])
|
||||
assert out[0].is_free is True
|
||||
assert out[0].price == "免费"
|
||||
|
||||
|
||||
def test_enrich_catalog_miss_degrades():
|
||||
"""未命中目录:原样返回,不填充展示字段。"""
|
||||
out = enrich_catalog([ModelInfo(id="unknown-model-xyz", name="X")])
|
||||
m = out[0]
|
||||
assert m.id == "unknown-model-xyz"
|
||||
assert m.name == "X"
|
||||
assert m.description is None
|
||||
assert m.price is None
|
||||
assert m.tags == []
|
||||
|
||||
|
||||
def test_enrich_catalog_empty():
|
||||
assert enrich_catalog([]) == []
|
||||
|
||||
|
||||
def test_enrich_catalog_case_insensitive():
|
||||
"""id 大小写不同仍能命中(查找表已归一化)。"""
|
||||
out = enrich_catalog([ModelInfo(id="MINIMAX-M2.5", name="MM")])
|
||||
assert out[0].category == "文本"
|
||||
|
||||
|
||||
def test_catalog_public_entries():
|
||||
"""公共目录表不应为空(供回填使用)。"""
|
||||
assert len(_catalog_pub) > 0
|
||||
Reference in New Issue
Block a user