Merge pull request #642 from ollama-webui/multimodal-fix

feat: include only last images
This commit is contained in:
Timothy Jaeryang Baek 2024-02-04 00:30:27 -08:00 committed by GitHub
commit c4ca46637e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 77 additions and 38 deletions

View file

@ -316,9 +316,7 @@
// Scroll down // Scroll down
window.scrollTo({ top: document.body.scrollHeight }); window.scrollTo({ top: document.body.scrollHeight });
const [res, controller] = await generateChatCompletion(localStorage.token, { const messagesBody = [
model: model,
messages: [
$settings.system $settings.system
? { ? {
role: 'system', role: 'system',
@ -336,7 +334,27 @@
.filter((file) => file.type === 'image') .filter((file) => file.type === 'image')
.map((file) => file.url.slice(file.url.indexOf(',') + 1)) .map((file) => file.url.slice(file.url.indexOf(',') + 1))
}) })
})), }));
let lastImageIndex = -1;
// Find the index of the last object with images
messagesBody.forEach((item, index) => {
if (item.images) {
lastImageIndex = index;
}
});
// Remove images from all but the last one
messagesBody.forEach((item, index) => {
if (index !== lastImageIndex) {
delete item.images;
}
});
const [res, controller] = await generateChatCompletion(localStorage.token, {
model: model,
messages: messagesBody,
options: { options: {
...($settings.options ?? {}) ...($settings.options ?? {})
}, },

View file

@ -330,9 +330,7 @@
// Scroll down // Scroll down
window.scrollTo({ top: document.body.scrollHeight }); window.scrollTo({ top: document.body.scrollHeight });
const [res, controller] = await generateChatCompletion(localStorage.token, { const messagesBody = [
model: model,
messages: [
$settings.system $settings.system
? { ? {
role: 'system', role: 'system',
@ -350,7 +348,27 @@
.filter((file) => file.type === 'image') .filter((file) => file.type === 'image')
.map((file) => file.url.slice(file.url.indexOf(',') + 1)) .map((file) => file.url.slice(file.url.indexOf(',') + 1))
}) })
})), }));
let lastImageIndex = -1;
// Find the index of the last object with images
messagesBody.forEach((item, index) => {
if (item.images) {
lastImageIndex = index;
}
});
// Remove images from all but the last one
messagesBody.forEach((item, index) => {
if (index !== lastImageIndex) {
delete item.images;
}
});
const [res, controller] = await generateChatCompletion(localStorage.token, {
model: model,
messages: messagesBody,
options: { options: {
...($settings.options ?? {}) ...($settings.options ?? {})
}, },
@ -358,6 +376,8 @@
}); });
if (res && res.ok) { if (res && res.ok) {
console.log('controller', controller);
const reader = res.body const reader = res.body
.pipeThrough(new TextDecoderStream()) .pipeThrough(new TextDecoderStream())
.pipeThrough(splitStream('\n')) .pipeThrough(splitStream('\n'))
@ -375,6 +395,7 @@
} }
currentRequestId = null; currentRequestId = null;
break; break;
} }