mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Caption messages by id
This commit is contained in:
@ -257,6 +257,19 @@ async function onSelectImage(e, prompt, quiet) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const caption = await getCaptionForFile(file, prompt, quiet);
|
||||||
|
form && form.reset();
|
||||||
|
return caption;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a caption for an image file.
|
||||||
|
* @param {File} file Input file
|
||||||
|
* @param {string} prompt Caption prompt
|
||||||
|
* @param {boolean} quiet Suppresses sending a message
|
||||||
|
* @returns {Promise<string>} Generated caption
|
||||||
|
*/
|
||||||
|
async function getCaptionForFile(file, prompt, quiet) {
|
||||||
try {
|
try {
|
||||||
setSpinnerIcon();
|
setSpinnerIcon();
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
@ -276,7 +289,6 @@ async function onSelectImage(e, prompt, quiet) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
form && form.reset();
|
|
||||||
setImageIcon();
|
setImageIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,9 +303,26 @@ function onRefineModeInput() {
|
|||||||
* @param {object} args Named parameters
|
* @param {object} args Named parameters
|
||||||
* @param {string} prompt Caption prompt
|
* @param {string} prompt Caption prompt
|
||||||
*/
|
*/
|
||||||
function captionCommandCallback(args, prompt) {
|
async function captionCommandCallback(args, prompt) {
|
||||||
return new Promise(resolve => {
|
|
||||||
const quiet = isTrueBoolean(args?.quiet);
|
const quiet = isTrueBoolean(args?.quiet);
|
||||||
|
const id = args?.id;
|
||||||
|
|
||||||
|
if (!isNaN(Number(id))) {
|
||||||
|
const message = getContext().chat[id];
|
||||||
|
if (message?.extra?.image) {
|
||||||
|
try {
|
||||||
|
const fetchResult = await fetch(message.extra.image);
|
||||||
|
const blob = await fetchResult.blob();
|
||||||
|
const file = new File([blob], 'image.jpg', { type: blob.type });
|
||||||
|
return await getCaptionForFile(file, prompt, quiet);
|
||||||
|
} catch (error) {
|
||||||
|
toastr.error('Failed to get image from the message. Make sure the image is accessible.');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise(resolve => {
|
||||||
const input = document.createElement('input');
|
const input = document.createElement('input');
|
||||||
input.type = 'file';
|
input.type = 'file';
|
||||||
input.accept = 'image/*';
|
input.accept = 'image/*';
|
||||||
@ -502,6 +531,9 @@ jQuery(function () {
|
|||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'quiet', 'suppress sending a captioned message', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', ['true', 'false'],
|
'quiet', 'suppress sending a captioned message', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', ['true', 'false'],
|
||||||
),
|
),
|
||||||
|
new SlashCommandNamedArgument(
|
||||||
|
'id', 'get image from a message with this ID', [ARGUMENT_TYPE.NUMBER], false, false,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandArgument(
|
||||||
@ -515,6 +547,9 @@ jQuery(function () {
|
|||||||
<div>
|
<div>
|
||||||
Only multimodal sources support custom prompts.
|
Only multimodal sources support custom prompts.
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
Provide a message ID to get an image from a message instead of uploading one.
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Set the "quiet" argument to true to suppress sending a captioned message, default: false.
|
Set the "quiet" argument to true to suppress sending a captioned message, default: false.
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user