fix(ImageGenerationMiddleware): correctly process image URLs (#7198)

This commit is contained in:
Doekin 2025-06-14 22:39:32 +08:00 committed by GitHub
parent 163e28d9ba
commit 1c354ffa0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -97,11 +97,21 @@ export const ImageGenerationMiddleware: CompletionsMiddleware =
)
}
const b64_json_array = response.data?.map((item) => `data:image/png;base64,${item.b64_json}`) || []
let imageType: 'url' | 'base64' = 'base64'
const imageList =
response.data?.reduce((acc: string[], image) => {
if (image.url) {
acc.push(image.url)
imageType = 'url'
} else if (image.b64_json) {
acc.push(`data:image/png;base64,${image.b64_json}`)
}
return acc
}, []) || []
enqueue({
type: ChunkType.IMAGE_COMPLETE,
image: { type: 'base64', images: b64_json_array }
image: { type: imageType, images: imageList }
})
const usage = (response as any).usage || { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }

View File

@ -137,7 +137,7 @@ export interface ImageCompleteChunk {
/**
* The image content of the chunk
*/
image?: { type: 'base64'; images: string[] }
image?: { type: 'url' | 'base64'; images: string[] }
}
export interface ThinkingDeltaChunk {