mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 18:50:56 +08:00
fix(ImageGenerationMiddleware): correctly process image URLs (#7198)
This commit is contained in:
parent
3c5c63f555
commit
bb8e5321e8
@ -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 }
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user