try to fix image gen
This commit is contained in:
parent
4a7149b4bb
commit
a881be2b78
@ -37,20 +37,30 @@ const IMAGE_MODEL_ADAPTERS: Record<string, ModelAdapter> = {
|
|||||||
name: 'Gemini 2.5 Flash Image Preview',
|
name: 'Gemini 2.5 Flash Image Preview',
|
||||||
prepareRequest: (userInput: string, promptContent: string, params: Record<string, unknown>) => ({
|
prepareRequest: (userInput: string, promptContent: string, params: Record<string, unknown>) => ({
|
||||||
model: 'google/gemini-2.5-flash-image-preview',
|
model: 'google/gemini-2.5-flash-image-preview',
|
||||||
contents: [{
|
messages: [{
|
||||||
parts: [{
|
role: 'user',
|
||||||
text: `${promptContent}\n\nUser input: ${userInput}`
|
content: `${promptContent}\n\nUser input: ${userInput}`
|
||||||
}]
|
|
||||||
}],
|
}],
|
||||||
generationConfig: {
|
temperature: params.temperature || 0.7,
|
||||||
temperature: params.temperature || 0.7,
|
...(params.maxTokens ? { max_tokens: params.maxTokens } : {}),
|
||||||
maxOutputTokens: params.maxTokens || 1024
|
...(params.topP ? { top_p: params.topP } : {}),
|
||||||
}
|
...(params.frequencyPenalty ? { frequency_penalty: params.frequencyPenalty } : {}),
|
||||||
|
...(params.presencePenalty ? { presence_penalty: params.presencePenalty } : {})
|
||||||
}),
|
}),
|
||||||
parseResponse: (response: Record<string, unknown>) => ({
|
parseResponse: (response: Record<string, unknown>) => {
|
||||||
content: (response as { candidates?: Array<{ content?: { parts?: Array<{ text?: string }> } }>; generated_image_url?: string }).candidates?.[0]?.content?.parts?.[0]?.text || (response as { generated_image_url?: string }).generated_image_url || 'Image generated successfully',
|
// 尝试从不同的响应格式中提取内容
|
||||||
outputType: 'image'
|
const choices = (response as { choices?: Array<{ message?: { content?: string } }> }).choices
|
||||||
})
|
const content = choices?.[0]?.message?.content || ''
|
||||||
|
|
||||||
|
// 从内容中提取图像URL
|
||||||
|
const urlMatch = content.match(/https?:\/\/[^\s<>"']*\.(?:png|jpg|jpeg|gif|webp|bmp|svg)(?:\?[^\s<>"']*)?/i)
|
||||||
|
const imageUrl = urlMatch?.[0] || ''
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: imageUrl || content || 'Image generation completed',
|
||||||
|
outputType: 'image'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,20 +33,30 @@ const IMAGE_MODEL_ADAPTERS: Record<string, ModelAdapter> = {
|
|||||||
name: 'Gemini 2.5 Flash Image Preview',
|
name: 'Gemini 2.5 Flash Image Preview',
|
||||||
prepareRequest: (userInput: string, promptContent: string, params: Record<string, unknown>) => ({
|
prepareRequest: (userInput: string, promptContent: string, params: Record<string, unknown>) => ({
|
||||||
model: 'google/gemini-2.5-flash-image-preview',
|
model: 'google/gemini-2.5-flash-image-preview',
|
||||||
contents: [{
|
messages: [{
|
||||||
parts: [{
|
role: 'user',
|
||||||
text: `${promptContent}\n\nUser input: ${userInput}`
|
content: `${promptContent}\n\nUser input: ${userInput}`
|
||||||
}]
|
|
||||||
}],
|
}],
|
||||||
generationConfig: {
|
temperature: params.temperature || 0.7,
|
||||||
temperature: params.temperature || 0.7,
|
...(params.maxTokens ? { max_tokens: params.maxTokens } : {}),
|
||||||
maxOutputTokens: params.maxTokens || 1024
|
...(params.topP ? { top_p: params.topP } : {}),
|
||||||
}
|
...(params.frequencyPenalty ? { frequency_penalty: params.frequencyPenalty } : {}),
|
||||||
|
...(params.presencePenalty ? { presence_penalty: params.presencePenalty } : {})
|
||||||
}),
|
}),
|
||||||
parseResponse: (response: Record<string, unknown>) => ({
|
parseResponse: (response: Record<string, unknown>) => {
|
||||||
content: (response as { candidates?: Array<{ content?: { parts?: Array<{ text?: string }> } }>; generated_image_url?: string }).candidates?.[0]?.content?.parts?.[0]?.text || (response as { generated_image_url?: string }).generated_image_url || 'Image generated successfully',
|
// 尝试从不同的响应格式中提取内容
|
||||||
outputType: 'image'
|
const choices = (response as { choices?: Array<{ message?: { content?: string } }> }).choices
|
||||||
})
|
const content = choices?.[0]?.message?.content || ''
|
||||||
|
|
||||||
|
// 从内容中提取图像URL
|
||||||
|
const urlMatch = content.match(/https?:\/\/[^\s<>"']*\.(?:png|jpg|jpeg|gif|webp|bmp|svg)(?:\?[^\s<>"']*)?/i)
|
||||||
|
const imageUrl = urlMatch?.[0] || ''
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: imageUrl || content || 'Image generation completed',
|
||||||
|
outputType: 'image'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user