cleaned up a little

This commit is contained in:
based
2023-12-14 23:18:56 +10:00
parent 0b7c1a98cd
commit 178b07f414
2 changed files with 23 additions and 21 deletions

View File

@@ -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');
}