Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/locales/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -14758,12 +14758,15 @@ msgstr "Please analyze the content of the video."
msgid "Please analyze the content of the file."
msgstr "Please analyze the content of the file."

#: apps/xpack/serializers/channel/aibot/bot_manager.py:548
#: apps/xpack/serializers/channel/wecom.py:270
#: apps/xpack/serializers/channel/wecomBot.py:122
#: apps/xpack/serializers/channel/wecom.py:302
msgid "Enterprise WeChat user: "
msgstr "Enterprise WeChat user: "

#: apps/xpack/serializers/channel/aibot/bot_manager.py:493
#: apps/xpack/serializers/channel/wecomBot.py:132
msgid "AI bot user: "
msgstr "AI bot user: "

#: apps/xpack/serializers/channel/chat_manage.py:149
msgid "The user is not authorized to access this application"
msgstr "The user is not authorized to access this application"
Expand Down
9 changes: 6 additions & 3 deletions apps/locales/zh_CN/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -14541,12 +14541,15 @@ msgstr "请分析视频内容。"
msgid "Please analyze the content of the file."
msgstr "请分析文件内容。"

#: apps/xpack/serializers/channel/aibot/bot_manager.py:548
#: apps/xpack/serializers/channel/wecom.py:270
#: apps/xpack/serializers/channel/wecomBot.py:122
#: apps/xpack/serializers/channel/wecom.py:302
msgid "Enterprise WeChat user: "
msgstr "企业微信用户: "

#: apps/xpack/serializers/channel/aibot/bot_manager.py:493
#: apps/xpack/serializers/channel/wecomBot.py:132
msgid "AI bot user: "
msgstr "智能机器人用户: "

#: apps/xpack/serializers/channel/chat_manage.py:149
msgid "The user is not authorized to access this application"
msgstr "用户无权访问该智能体"
Expand Down
9 changes: 6 additions & 3 deletions apps/locales/zh_Hant/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -14541,12 +14541,15 @@ msgstr "請分析視頻內容。"
msgid "Please analyze the content of the file."
msgstr "請分析文件內容。"

#: apps/xpack/serializers/channel/aibot/bot_manager.py:548
#: apps/xpack/serializers/channel/wecom.py:270
#: apps/xpack/serializers/channel/wecomBot.py:122
#: apps/xpack/serializers/channel/wecom.py:302
msgid "Enterprise WeChat user: "
msgstr "企業微信用戶: "

#: apps/xpack/serializers/channel/aibot/bot_manager.py:493
#: apps/xpack/serializers/channel/wecomBot.py:132
msgid "AI bot user: "
msgstr "智能機器人用戶: "

#: apps/xpack/serializers/channel/chat_manage.py:149
msgid "The user is not authorized to access this application"
msgstr "使用者無權訪問該智慧體"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ModelInfo,
ModelTypeConst,
ModelInfoManage,
classify_dynamic_model_id,
)
from models_provider.impl.tencent_model_provider.credential.embedding import TencentEmbeddingCredential
from models_provider.impl.tencent_model_provider.credential.image import TencentVisionModelCredential
Expand Down Expand Up @@ -232,6 +233,20 @@ def __init__(self):
def get_model_info_manage(self):
return self._model_info_manage

@staticmethod
def classify_dynamic_model(model_id):
"""TokenHub 的 /models 不带模态元数据,按官方命名规则补齐判型。

YT-Video 系列为图生视频/首尾帧(ITV);含 vision 的多数为视觉多模态
理解模型(IMAGE),但带 video/t2v/i2v 的仍按视频处理,避免误判。
"""
model_id = str(model_id).lower()
if "yt-video" in model_id:
return ModelTypeConst.ITV
if "vision" in model_id and not any(k in model_id for k in ("video", "t2v", "i2v")):
return ModelTypeConst.IMAGE
return classify_dynamic_model_id(model_id)

def get_model(self, model_type, model_name, model_credential, **model_kwargs):
# STT 模型:模型名不以 asr- 开头的一律走 Tencent Tokenhub WAND 识别
if model_type == ModelTypeConst.STT.name and not model_name.startswith("asr-"):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my review of the diff:

Potential Issues

  1. Type inference may be fragile / over-broad

    • if "vision" in model_id: any future model containing "vision" that is not an image-understanding model will be misclassified as IMAGE. String matching on model IDs is brittle; consider a whitelist/prefix map or config-driven mapping instead.
    • The blacklist ("video", "t2v", "i2v") is likely incomplete. Common video conventions like "vid", "i2v", "t2v", "itv", "ti2v", "s2v" (speech-to-video) should be enumerated if you keep this approach.
  2. Ordering dependency

    • yt-video check happens before vision, so yt-video-vision would go to ITV. If such a model can exist, ensure this is intentional and documented.
  3. Name collision confusion

    • The method is named classify_dynamic_model while it delegates to the imported classify_dynamic_model_id. Similar names can cause confusion; consider renaming to something like _classify_tokenhub_model to signal that this is provider-specific logic.
  4. Staticmethod placement

    • It's defined between get_model_info_manage and get_model — fine, but since it's pure (no self), you could also move it near other factory/helper methods for readability.
  5. Case handling

    • str(model_id).lower() is safe, but if model_id is ever None, you'd get "none" — for consistency with classify_dynamic_model_id, confirm its expectations so behavior stays aligned.
  6. Missing tests

    • Add unit tests covering: pure yt-video-*, *-vision, *-vision-t2v, *-vision-i2v, unknown IDs falling back, and mixed-case inputs.

Optimization Suggestions

  • Extract keyword tuples to module-level constants:
    _VIDEO_KEYWORDS = ("video", "t2v", "i2v")
  • Prefer prefix-based matching if the naming is stable (e.g., model_id.startswith("yt-video")) — more explicit and cheaper than in.
  • Consider returning early and logging at debug level when falling back to classify_dynamic_model_id, to help diagnose misclassifications in production.
  • If provider metadata later becomes available (even a type field in /models), prefer that over name heuristics and deprecate this shim.

Style

  • Docstring mixes Chinese comments with English code — acceptable in many codebases, but ensure the project's convention (looks consistent with existing files).
  • No functional defects detected in the shown snippet; the main risk is heuristic misclassification.

Expand Down
20 changes: 20 additions & 0 deletions apps/models_provider/tests/test_tencent_provider.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from django.test import SimpleTestCase

from models_provider.base_model_provider import ModelTypeConst
from models_provider.impl.tencent_model_provider.tencent_model_provider import TencentModelProvider


Expand Down Expand Up @@ -30,3 +31,22 @@ def test_wand_asr_v1_uses_tokenhub_credential(self):
self.assertIsInstance(credential, TencentTokenhubSTTModelCredential)
fields = {item.get("field") for item in credential.to_form_list()}
self.assertIn("api_key", fields)

def test_dynamic_classify_vision_as_image(self):
# TokenHub 的 /models 不带模态元数据,含 vision 的多模态理解模型应收敛到 IMAGE。
for model_id in (
"hy-vision-2.0-instruct",
"hunyuan-t1-vision-20250916",
"deepseek/deepseek-v4-flash-vision-exp",
):
self.assertEqual(TencentModelProvider.classify_dynamic_model(model_id), ModelTypeConst.IMAGE)

def test_dynamic_classify_yt_video_as_itv(self):
self.assertEqual(TencentModelProvider.classify_dynamic_model("yt-video-humanactor"), ModelTypeConst.ITV)

def test_dynamic_classify_vision_video_stays_ttv(self):
# 带 video 的视觉模型仍是视频生成任务,不应被误判为视觉模型。
self.assertEqual(
TencentModelProvider.classify_dynamic_model("hunyuan-turbos-vision-video-20250728"),
ModelTypeConst.TTV,
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added tests are generally reasonable and do not introduce network calls or obvious runtime/performance concerns. Main points to verify:

Potential issues

  • TencentModelProvider.classify_dynamic_model(...) is called on the class. This only works if the method is a @classmethod or @staticmethod. If it is an instance method, the tests will fail with a missing self argument.
  • Confirm that ModelTypeConst.IMAGE, ModelTypeConst.ITV, and ModelTypeConst.TTV exist and have the intended semantics. In particular, make sure IMAGE means “vision/multimodal understanding” here, not “text-to-image generation”; otherwise hunyuan-t1-vision-* may be classified incorrectly.
  • The tests encode substring-based classification behavior. If the implementation is case-sensitive, uppercase model IDs may fail. Consider normalizing the model ID to lowercase before matching.
  • The hunyuan-turbos-vision-video-* test correctly protects against “vision” overriding “video”, but ensure the implementation explicitly checks video-related patterns before vision-related patterns.
  • The yt-video-humanactor -> ITV expectation should be confirmed against Tencent’s model documentation. If the classification relies on special substrings such as yt or humanactor, document that rule clearly.

Optimization suggestions

  • Use subTest in the loop so a failure clearly identifies which model ID failed:
for model_id in (
    "hy-vision-2.0-instruct",
    "hunyuan-t1-vision-20250916",
    "deepseek/deepseek-v4-flash-vision-exp",
):
    with self.subTest(model_id=model_id):
        self.assertEqual(
            TencentModelProvider.classify_dynamic_model(model_id),
            ModelTypeConst.IMAGE,
        )
  • Add a few edge-case tests:
    • uppercase model IDs,
    • model IDs with neither vision nor video,
    • false positives such as television or visionary,
    • model IDs containing both vision and video.

Minor style note

  • The comments are in Chinese while the surrounding code/tests appear English. This is not a functional issue, but consistency with the repository’s language convention would improve readability.

Loading