Skip to content

Commit 599fbeb

Browse files
authored
🐛 Bugfix: Fixed an issue with batch model addition and validation in Alibaba Bailian. (#3350)
1 parent 10d9e74 commit 599fbeb

3 files changed

Lines changed: 936 additions & 434 deletions

File tree

backend/services/providers/dashscope_provider.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,19 @@ def _is_dashscope_video_understanding_model(model_id: str, desc: str, req_mods:
7171

7272

7373
def _is_dashscope_image_understanding_model(model_id: str, desc: str, req_mods: set, res_mods: set) -> bool:
74-
searchable_text = f"{model_id} {desc.lower()}"
75-
if _is_dashscope_image_generation_model(model_id, desc, req_mods, res_mods):
76-
return False
77-
if _is_dashscope_video_understanding_model(model_id, desc, req_mods, res_mods):
78-
return False
79-
if ("image" in req_mods or "video" in req_mods) and "text" in res_mods:
74+
"""Determine if model is for image understanding.
75+
76+
A model qualifies for image understanding if:
77+
- Its output is text AND input contains image or video (multimodal image understanding), OR
78+
- Model ID explicitly matches image-understanding keywords.
79+
80+
Note: This check is independent of video/image-generation classification.
81+
A model that is also a video model (vlm3) can simultaneously be an image model (vlm).
82+
"""
83+
if "text" in res_mods and ("image" in req_mods or "video" in req_mods):
8084
return True
8185
return _is_dashscope_explicit_image_understanding_model(model_id) or _has_keyword(
82-
searchable_text, DASHSCOPE_IMAGE_UNDERSTANDING_KEYWORDS
86+
model_id, DASHSCOPE_IMAGE_UNDERSTANDING_KEYWORDS
8387
)
8488

8589

@@ -142,9 +146,10 @@ async def get_models(self, provider_config: Dict) -> List[Dict]:
142146
"stt": [] # Maps to "stt"
143147
}
144148

145-
# Classify models and inject canonical fields expected downstream
149+
# Classify models into multiple buckets based on capabilities.
150+
# A model can belong to more than one bucket (e.g., a model that
151+
# accepts Image+Video+Text and returns Text is both vlm3, vlm, and llm).
146152
for model_obj in all_models:
147-
# Extract key fields for logical determination (lowercased for robustness)
148153
m_id = model_obj.get('model', '').lower()
149154
desc = model_obj.get('description', '')
150155
metadata = model_obj.get('inference_metadata') or {}
@@ -188,26 +193,28 @@ async def get_models(self, provider_config: Dict) -> List[Dict]:
188193
categorized_models['tts'].append(cleaned_model)
189194
continue
190195

191-
# 5. VLM
192-
if _is_dashscope_video_understanding_model(m_id, desc, req_mods, res_mods):
193-
cleaned_model.update({"model_tag": "chat", "model_type": "vlm3"})
194-
categorized_models['vlm3'].append(cleaned_model)
195-
continue
196-
196+
# Multimodal / general-purpose types - non-exclusive, no continue.
197+
# Each check is independent; one model can qualify for multiple buckets.
197198
if _is_dashscope_image_generation_model(m_id, desc, req_mods, res_mods):
198-
cleaned_model.update({"model_tag": "chat", "model_type": "vlm2"})
199-
categorized_models['vlm2'].append(cleaned_model)
200-
continue
199+
vlm2_model = cleaned_model.copy()
200+
vlm2_model.update({"model_tag": "chat", "model_type": "vlm2"})
201+
categorized_models['vlm2'].append(vlm2_model)
202+
203+
if _is_dashscope_video_understanding_model(m_id, desc, req_mods, res_mods):
204+
vlm3_model = cleaned_model.copy()
205+
vlm3_model.update({"model_tag": "chat", "model_type": "vlm3"})
206+
categorized_models['vlm3'].append(vlm3_model)
201207

202208
if _is_dashscope_image_understanding_model(m_id, desc, req_mods, res_mods):
203-
cleaned_model.update({"model_tag": "chat", "model_type": "vlm"})
204-
categorized_models['vlm'].append(cleaned_model)
205-
continue
209+
vlm_model = cleaned_model.copy()
210+
vlm_model.update({"model_tag": "chat", "model_type": "vlm"})
211+
categorized_models['vlm'].append(vlm_model)
206212

207-
# 6. Chat / LLM
213+
# Fallback to llm when no specialized modality is present
208214
if 'Text' in req_mod or 'Text' in res_mod:
209-
cleaned_model.update({"model_tag": "chat", "model_type": "llm"})
210-
categorized_models['chat'].append(cleaned_model)
215+
llm_model = cleaned_model.copy()
216+
llm_model.update({"model_tag": "chat", "model_type": "llm"})
217+
categorized_models['chat'].append(llm_model)
211218

212219
# Return the specific list based on the requested target_model_type
213220
if target_model_type == "llm":

frontend/hooks/model/useDashscopeModelList.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ export const useDashscopeModelList = ({
3939
const modelType =
4040
form.type === "embedding" && form.isMultimodal
4141
? ("multi_embedding" as ModelType)
42-
: form.type === "vlm2" || form.type === "vlm3"
43-
? ("vlm" as ModelType)
44-
: form.type;
42+
: form.type;
4543

4644
try {
4745
// Use manage interface if tenantId is provided (for super admin)

0 commit comments

Comments
 (0)