mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-13 04:45:19 +00:00
refac: submit suggestion prompt by default
This commit is contained in:
parent
6dc0df2473
commit
e023a98f11
3 changed files with 51 additions and 15 deletions
|
|
@ -202,7 +202,12 @@
|
|||
|
||||
if (type === 'prompt') {
|
||||
// Handle prompt selection
|
||||
messageInput?.setText(data);
|
||||
messageInput?.setText(data, async () => {
|
||||
if (!($settings?.insertSuggestionPrompt ?? false)) {
|
||||
await tick();
|
||||
submitPrompt(prompt);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@
|
|||
export let codeInterpreterEnabled = false;
|
||||
|
||||
let showInputVariablesModal = false;
|
||||
let inputVariablesModalCallback = (variableValues) => {};
|
||||
let inputVariables = {};
|
||||
let inputVariableValues = {};
|
||||
|
||||
|
|
@ -122,11 +123,24 @@
|
|||
codeInterpreterEnabled
|
||||
});
|
||||
|
||||
const inputVariableHandler = async (text: string) => {
|
||||
const inputVariableHandler = async (text: string): Promise<string> => {
|
||||
inputVariables = extractInputVariables(text);
|
||||
if (Object.keys(inputVariables).length > 0) {
|
||||
showInputVariablesModal = true;
|
||||
|
||||
// No variables? return the original text immediately.
|
||||
if (Object.keys(inputVariables).length === 0) {
|
||||
return text;
|
||||
}
|
||||
|
||||
// Show modal and wait for the user's input.
|
||||
showInputVariablesModal = true;
|
||||
return await new Promise<string>((resolve) => {
|
||||
inputVariablesModalCallback = (variableValues) => {
|
||||
inputVariableValues = { ...inputVariableValues, ...variableValues };
|
||||
replaceVariables(inputVariableValues);
|
||||
showInputVariablesModal = false;
|
||||
resolve(text);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const textVariableHandler = async (text: string) => {
|
||||
|
|
@ -244,7 +258,6 @@
|
|||
text = text.replaceAll('{{CURRENT_WEEKDAY}}', weekday);
|
||||
}
|
||||
|
||||
inputVariableHandler(text);
|
||||
return text;
|
||||
};
|
||||
|
||||
|
|
@ -280,7 +293,7 @@
|
|||
}
|
||||
};
|
||||
|
||||
export const setText = async (text?: string) => {
|
||||
export const setText = async (text?: string, cb?: (text: string) => void) => {
|
||||
const chatInput = document.getElementById('chat-input');
|
||||
|
||||
if (chatInput) {
|
||||
|
|
@ -296,6 +309,10 @@
|
|||
chatInput.focus();
|
||||
chatInput.dispatchEvent(new Event('input'));
|
||||
}
|
||||
|
||||
text = await inputVariableHandler(text);
|
||||
await tick();
|
||||
if (cb) await cb(text);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -758,11 +775,7 @@
|
|||
}
|
||||
];
|
||||
};
|
||||
reader.readAsDataURL(
|
||||
file['type'] === 'image/heic'
|
||||
? await convertHeicToJpeg(file)
|
||||
: file
|
||||
);
|
||||
reader.readAsDataURL(file['type'] === 'image/heic' ? await convertHeicToJpeg(file) : file);
|
||||
} else {
|
||||
uploadFileHandler(file);
|
||||
}
|
||||
|
|
@ -868,10 +881,7 @@
|
|||
<InputVariablesModal
|
||||
bind:show={showInputVariablesModal}
|
||||
variables={inputVariables}
|
||||
onSave={(variableValues) => {
|
||||
inputVariableValues = { ...inputVariableValues, ...variableValues };
|
||||
replaceVariables(inputVariableValues);
|
||||
}}
|
||||
onSave={inputVariablesModalCallback}
|
||||
/>
|
||||
|
||||
{#if loaded}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
|
||||
let largeTextAsFile = false;
|
||||
|
||||
let insertSuggestionPrompt = false;
|
||||
let keepFollowUpPrompts = false;
|
||||
let insertFollowUpPrompt = false;
|
||||
|
||||
|
|
@ -200,6 +201,7 @@
|
|||
insertPromptAsRichText = $settings?.insertPromptAsRichText ?? false;
|
||||
promptAutocomplete = $settings?.promptAutocomplete ?? false;
|
||||
|
||||
insertSuggestionPrompt = $settings?.insertSuggestionPrompt ?? false;
|
||||
keepFollowUpPrompts = $settings?.keepFollowUpPrompts ?? false;
|
||||
insertFollowUpPrompt = $settings?.insertFollowUpPrompt ?? false;
|
||||
|
||||
|
|
@ -697,6 +699,25 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div id="insert-suggestion-prompt-label" class=" self-center text-xs">
|
||||
{$i18n.t('Insert Suggestion Prompt to Input')}
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2 p-1">
|
||||
<Switch
|
||||
ariaLabelledbyId="insert-suggestion-prompt-label"
|
||||
tooltip={true}
|
||||
bind:state={insertSuggestionPrompt}
|
||||
on:change={() => {
|
||||
saveSettings({ insertSuggestionPrompt });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div id="keep-follow-up-prompts-label" class=" self-center text-xs">
|
||||
|
|
|
|||
Loading…
Reference in a new issue