mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
cleaned up a little
This commit is contained in:
@@ -30,24 +30,20 @@ export async function getMultimodalCaption(base64Img, prompt) {
|
|||||||
base64Img = await createThumbnail(base64Img, maxSide, maxSide, 'image/jpeg');
|
base64Img = await createThumbnail(base64Img, maxSide, maxSide, 'image/jpeg');
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiResult = extension_settings.caption.multimodal_api === 'google' ?
|
const isGoogle = extension_settings.caption.multimodal_api === 'google';
|
||||||
await fetch('/api/google/caption-image', {
|
const apiResult = await fetch(`/api/${isGoogle ? 'google' : 'openai'}/caption-image`, {
|
||||||
method: 'POST',
|
|
||||||
headers: getRequestHeaders(),
|
|
||||||
body: JSON.stringify({
|
|
||||||
image: base64Img,
|
|
||||||
prompt: prompt,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
: await fetch('/api/openai/caption-image', {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
image: base64Img,
|
image: base64Img,
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
|
...(isGoogle
|
||||||
|
? {}
|
||||||
|
: {
|
||||||
api: extension_settings.caption.multimodal_api || 'openai',
|
api: extension_settings.caption.multimodal_api || 'openai',
|
||||||
model: extension_settings.caption.multimodal_model || 'gpt-4-vision-preview',
|
model: extension_settings.caption.multimodal_model || 'gpt-4-vision-preview',
|
||||||
}),
|
}),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!apiResult.ok) {
|
if (!apiResult.ok) {
|
||||||
|
@@ -14,7 +14,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||||||
parts: [
|
parts: [
|
||||||
{ text: request.body.prompt },
|
{ text: request.body.prompt },
|
||||||
{ inlineData: {
|
{ inlineData: {
|
||||||
mimeType: 'image/png',
|
mimeType: 'image/png', //jpg images seem to work fine even with this mimetype set?
|
||||||
data: request.body.image,
|
data: request.body.image,
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
@@ -40,8 +40,14 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await result.json();
|
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) {
|
if (!caption) {
|
||||||
return response.status(500).send('No caption found');
|
return response.status(500).send('No caption found');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user