feat: update-t2i-image (#12236)

* chore: comment

* chore: comment 2

* fix: comment

* chore: var name
This commit is contained in:
SuYao 2026-01-02 16:26:28 +08:00 committed by GitHub
parent 77e024027c
commit 48a582820f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -75,12 +75,37 @@ const VISION_REGEX = new RegExp(
'i'
)
// For middleware to identify models that must use the dedicated Image API
// All dedicated image generation models (only generate images, no text chat capability)
// These models need:
// 1. Route to dedicated image generation API
// 2. Exclude from reasoning/websearch/tooluse selection
const DEDICATED_IMAGE_MODELS = [
'grok-2-image(?:-[\\w-]+)?',
// OpenAI series
'dall-e(?:-[\\w-]+)?',
'gpt-image-1(?:-[\\w-]+)?',
'imagen(?:-[\\w-]+)?'
'gpt-image(?:-[\\w-]+)?',
// xAI
'grok-2-image(?:-[\\w-]+)?',
// Google
'imagen(?:-[\\w-]+)?',
// Stable Diffusion series
'flux(?:-[\\w-]+)?',
'stable-?diffusion(?:-[\\w-]+)?',
'stabilityai(?:-[\\w-]+)?',
'sd-[\\w-]+',
'sdxl(?:-[\\w-]+)?',
// zhipu
'cogview(?:-[\\w-]+)?',
// Alibaba
'qwen-image(?:-[\\w-]+)?',
// Others
'janus(?:-[\\w-]+)?',
'midjourney(?:-[\\w-]+)?',
'mj-[\\w-]+',
'z-image(?:-[\\w-]+)?',
'longcat-image(?:-[\\w-]+)?',
'hunyuanimage(?:-[\\w-]+)?',
'seedream(?:-[\\w-]+)?',
'kandinsky(?:-[\\w-]+)?'
]
const IMAGE_ENHANCEMENT_MODELS = [
@ -133,13 +158,23 @@ const GENERATE_IMAGE_MODELS_REGEX = new RegExp(GENERATE_IMAGE_MODELS.join('|'),
const MODERN_GENERATE_IMAGE_MODELS_REGEX = new RegExp(MODERN_IMAGE_MODELS.join('|'), 'i')
export const isDedicatedImageGenerationModel = (model: Model): boolean => {
/**
* Check if the model is a dedicated image generation model
* Dedicated image generation models can only generate images, no text chat capability
*
* These models need:
* 1. Route to dedicated image generation API
* 2. Exclude from reasoning/websearch/tooluse selection
*/
export function isDedicatedImageModel(model: Model): boolean {
if (!model) return false
const modelId = getLowerBaseModelName(model.id)
return DEDICATED_IMAGE_MODELS_REGEX.test(modelId)
}
// Backward compatible aliases
export const isDedicatedImageGenerationModel = isDedicatedImageModel
export const isAutoEnableImageGenerationModel = (model: Model): boolean => {
if (!model) return false
@ -195,14 +230,8 @@ export function isPureGenerateImageModel(model: Model): boolean {
return !OPENAI_TOOL_USE_IMAGE_GENERATION_MODELS.some((m) => modelId.includes(m))
}
// TODO: refine the regex
// Text to image models
const TEXT_TO_IMAGE_REGEX = /flux|diffusion|stabilityai|sd-|dall|cogview|janus|midjourney|mj-|imagen|gpt-image/i
export function isTextToImageModel(model: Model): boolean {
const modelId = getLowerBaseModelName(model.id)
return TEXT_TO_IMAGE_REGEX.test(modelId)
}
// Backward compatible alias - now uses unified dedicated image model detection
export const isTextToImageModel = isDedicatedImageModel
/**
*