fix: gemini generateImage model detection (#7241)

* fix: gemini generateImage model detection

* refactor: use base name for websearch model detection
This commit is contained in:
one 2025-06-16 13:06:52 +08:00 committed by GitHub
parent eb650aa586
commit eb89ca5415
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2594,9 +2594,11 @@ export function isWebSearchModel(model: Model): boolean {
return false return false
} }
const baseName = getBaseModelName(model.id, '/').toLowerCase()
// 不管哪个供应商都判断了 // 不管哪个供应商都判断了
if (model.id.includes('claude')) { if (model.id.includes('claude')) {
return CLAUDE_SUPPORTED_WEBSEARCH_REGEX.test(model.id) return CLAUDE_SUPPORTED_WEBSEARCH_REGEX.test(baseName)
} }
if (provider.type === 'openai-response') { if (provider.type === 'openai-response') {
@ -2608,7 +2610,7 @@ export function isWebSearchModel(model: Model): boolean {
} }
if (provider.id === 'perplexity') { if (provider.id === 'perplexity') {
return PERPLEXITY_SEARCH_MODELS.includes(model?.id) return PERPLEXITY_SEARCH_MODELS.includes(baseName)
} }
if (provider.id === 'aihubmix') { if (provider.id === 'aihubmix') {
@ -2617,31 +2619,31 @@ export function isWebSearchModel(model: Model): boolean {
} }
const models = ['gemini-2.0-flash-search', 'gemini-2.0-flash-exp-search', 'gemini-2.0-pro-exp-02-05-search'] const models = ['gemini-2.0-flash-search', 'gemini-2.0-flash-exp-search', 'gemini-2.0-pro-exp-02-05-search']
return models.includes(model?.id) return models.includes(baseName)
} }
if (provider?.type === 'openai') { if (provider?.type === 'openai') {
if (GEMINI_SEARCH_MODELS.includes(model?.id) || isOpenAIWebSearchModel(model)) { if (GEMINI_SEARCH_MODELS.includes(baseName) || isOpenAIWebSearchModel(model)) {
return true return true
} }
} }
if (provider.id === 'gemini' || provider?.type === 'gemini') { if (provider.id === 'gemini' || provider?.type === 'gemini') {
return GEMINI_SEARCH_MODELS.includes(model?.id) return GEMINI_SEARCH_MODELS.includes(baseName)
} }
if (provider.id === 'hunyuan') { if (provider.id === 'hunyuan') {
return model?.id !== 'hunyuan-lite' return baseName !== 'hunyuan-lite'
} }
if (provider.id === 'zhipu') { if (provider.id === 'zhipu') {
return model?.id?.startsWith('glm-4-') return baseName?.startsWith('glm-4-')
} }
if (provider.id === 'dashscope') { if (provider.id === 'dashscope') {
const models = ['qwen-turbo', 'qwen-max', 'qwen-plus', 'qwq'] const models = ['qwen-turbo', 'qwen-max', 'qwen-plus', 'qwq']
// matches id like qwen-max-0919, qwen-max-latest // matches id like qwen-max-0919, qwen-max-latest
return models.some((i) => model.id.startsWith(i)) return models.some((i) => baseName.startsWith(i))
} }
if (provider.id === 'openrouter') { if (provider.id === 'openrouter') {
@ -2685,7 +2687,9 @@ export function isGenerateImageModel(model: Model): boolean {
if (isEmbedding) { if (isEmbedding) {
return false return false
} }
if (GENERATE_IMAGE_MODELS.includes(model.id)) {
const baseName = getBaseModelName(model.id, '/').toLowerCase()
if (GENERATE_IMAGE_MODELS.includes(baseName)) {
return true return true
} }
return false return false