cleaned up a little
This commit is contained in:
parent
0b7c1a98cd
commit
178b07f414
|
@ -30,25 +30,21 @@ export async function getMultimodalCaption(base64Img, prompt) {
|
|||
base64Img = await createThumbnail(base64Img, maxSide, maxSide, 'image/jpeg');
|
||||
}
|
||||
|
||||
const apiResult = extension_settings.caption.multimodal_api === 'google' ?
|
||||
await fetch('/api/google/caption-image', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({
|
||||
image: base64Img,
|
||||
prompt: prompt,
|
||||
}),
|
||||
})
|
||||
: await fetch('/api/openai/caption-image', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({
|
||||
image: base64Img,
|
||||
prompt: prompt,
|
||||
api: extension_settings.caption.multimodal_api || 'openai',
|
||||
model: extension_settings.caption.multimodal_model || 'gpt-4-vision-preview',
|
||||
}),
|
||||
});
|
||||
const isGoogle = extension_settings.caption.multimodal_api === 'google';
|
||||
const apiResult = await fetch(`/api/${isGoogle ? 'google' : 'openai'}/caption-image`, {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({
|
||||
image: base64Img,
|
||||
prompt: prompt,
|
||||
...(isGoogle
|
||||
? {}
|
||||
: {
|
||||
api: extension_settings.caption.multimodal_api || 'openai',
|
||||
model: extension_settings.caption.multimodal_model || 'gpt-4-vision-preview',
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
if (!apiResult.ok) {
|
||||
throw new Error('Failed to caption image via OpenAI.');
|
||||
|
|
|
@ -14,7 +14,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||
parts: [
|
||||
{ text: request.body.prompt },
|
||||
{ inlineData: {
|
||||
mimeType: 'image/png',
|
||||
mimeType: 'image/png', //jpg images seem to work fine even with this mimetype set?
|
||||
data: request.body.image,
|
||||
},
|
||||
}],
|
||||
|
@ -40,8 +40,14 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||
}
|
||||
|
||||
const data = await result.json();
|
||||
console.log('Multimodal captioning response', data);
|
||||
|
||||
const caption = data?.candidates[0].content.parts[0].text;
|
||||
const candidates = data?.candidates;
|
||||
if(!candidates) {
|
||||
return response.status(500).send('No candidates found, image was most likely filtered.');
|
||||
}
|
||||
|
||||
const caption = candidates[0].content.parts[0].text;
|
||||
if (!caption) {
|
||||
return response.status(500).send('No caption found');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue