mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Gemini inline images (#3681)
* Gemini images for non-streaming * Parse images on stream * Add toggle for image request * Add extraction params to extractImageFromData * Add explicit break and return * Add more JSdoc to processImageAttachment * Add file name prefix * Add object argument for saveReply * Add defaults to saveReply params * Use type for saveReply result * Change type check in saveReply backward compat
This commit is contained in:
@ -305,6 +305,7 @@ export const settingsToUpdate = {
|
||||
seed: ['#seed_openai', 'seed', false],
|
||||
n: ['#n_openai', 'n', false],
|
||||
bypass_status_check: ['#openai_bypass_status_check', 'bypass_status_check', true],
|
||||
request_images: ['#openai_request_images', 'request_images', true],
|
||||
};
|
||||
|
||||
const default_settings = {
|
||||
@ -383,6 +384,7 @@ const default_settings = {
|
||||
show_thoughts: true,
|
||||
reasoning_effort: 'medium',
|
||||
enable_web_search: false,
|
||||
request_images: false,
|
||||
seed: -1,
|
||||
n: 1,
|
||||
};
|
||||
@ -463,6 +465,7 @@ const oai_settings = {
|
||||
show_thoughts: true,
|
||||
reasoning_effort: 'medium',
|
||||
enable_web_search: false,
|
||||
request_images: false,
|
||||
seed: -1,
|
||||
n: 1,
|
||||
};
|
||||
@ -2014,6 +2017,7 @@ async function sendOpenAIRequest(type, messages, signal) {
|
||||
'include_reasoning': Boolean(oai_settings.show_thoughts),
|
||||
'reasoning_effort': String(oai_settings.reasoning_effort),
|
||||
'enable_web_search': Boolean(oai_settings.enable_web_search),
|
||||
'request_images': Boolean(oai_settings.request_images),
|
||||
};
|
||||
|
||||
if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) {
|
||||
@ -2200,7 +2204,7 @@ async function sendOpenAIRequest(type, messages, signal) {
|
||||
let text = '';
|
||||
const swipes = [];
|
||||
const toolCalls = [];
|
||||
const state = { reasoning: '' };
|
||||
const state = { reasoning: '', image: '' };
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) return;
|
||||
@ -2258,6 +2262,10 @@ function getStreamingReply(data, state) {
|
||||
}
|
||||
return data?.delta?.text || '';
|
||||
} else if (oai_settings.chat_completion_source === chat_completion_sources.MAKERSUITE) {
|
||||
const inlineData = data?.candidates?.[0]?.content?.parts?.find(x => x.inlineData)?.inlineData;
|
||||
if (inlineData) {
|
||||
state.image = `data:${inlineData.mimeType};base64,${inlineData.data}`;
|
||||
}
|
||||
if (oai_settings.show_thoughts) {
|
||||
state.reasoning += (data?.candidates?.[0]?.content?.parts?.filter(x => x.thought)?.map(x => x.text)?.[0] || '');
|
||||
}
|
||||
@ -3242,6 +3250,7 @@ function loadOpenAISettings(data, settings) {
|
||||
oai_settings.show_thoughts = settings.show_thoughts ?? default_settings.show_thoughts;
|
||||
oai_settings.reasoning_effort = settings.reasoning_effort ?? default_settings.reasoning_effort;
|
||||
oai_settings.enable_web_search = settings.enable_web_search ?? default_settings.enable_web_search;
|
||||
oai_settings.request_images = settings.request_images ?? default_settings.request_images;
|
||||
oai_settings.seed = settings.seed ?? default_settings.seed;
|
||||
oai_settings.n = settings.n ?? default_settings.n;
|
||||
|
||||
@ -3370,6 +3379,7 @@ function loadOpenAISettings(data, settings) {
|
||||
$('#n_openai').val(oai_settings.n);
|
||||
$('#openai_show_thoughts').prop('checked', oai_settings.show_thoughts);
|
||||
$('#openai_enable_web_search').prop('checked', oai_settings.enable_web_search);
|
||||
$('#openai_request_images').prop('checked', oai_settings.request_images);
|
||||
|
||||
$('#openai_reasoning_effort').val(oai_settings.reasoning_effort);
|
||||
$(`#openai_reasoning_effort option[value="${oai_settings.reasoning_effort}"]`).prop('selected', true);
|
||||
@ -3641,6 +3651,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
|
||||
show_thoughts: settings.show_thoughts,
|
||||
reasoning_effort: settings.reasoning_effort,
|
||||
enable_web_search: settings.enable_web_search,
|
||||
request_images: settings.request_images,
|
||||
seed: settings.seed,
|
||||
n: settings.n,
|
||||
};
|
||||
@ -5603,6 +5614,11 @@ export function initOpenAI() {
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#openai_request_images').on('input', function () {
|
||||
oai_settings.request_images = !!$(this).prop('checked');
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
if (!CSS.supports('field-sizing', 'content')) {
|
||||
$(document).on('input', '#openai_settings .autoSetHeight', function () {
|
||||
resetScrollHeight($(this));
|
||||
|
Reference in New Issue
Block a user