Improve settings, add settings for prompt, sent message summarize toggle
This commit is contained in:
parent
a022c9eccb
commit
10692523f0
|
@ -10,7 +10,14 @@ import {
|
|||
substituteParams,
|
||||
generateRaw,
|
||||
} from '../../../script.js';
|
||||
import { ModuleWorkerWrapper, extension_settings, getContext, modules, renderExtensionTemplateAsync } from '../../extensions.js';
|
||||
import {
|
||||
ModuleWorkerWrapper,
|
||||
extension_settings,
|
||||
getContext,
|
||||
modules,
|
||||
renderExtensionTemplateAsync,
|
||||
doExtrasFetch, getApiUrl,
|
||||
} from '../../extensions.js';
|
||||
import { collapseNewlines } from '../../power-user.js';
|
||||
import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js';
|
||||
import { debounce, getStringHash as calculateHash, waitUntilCondition, onlyUnique, splitRecursive } from '../../utils.js';
|
||||
|
@ -26,7 +33,9 @@ const settings = {
|
|||
togetherai_model: 'togethercomputer/m2-bert-80M-32k-retrieval',
|
||||
openai_model: 'text-embedding-ada-002',
|
||||
summarize: false,
|
||||
summarize_sent: false,
|
||||
summary_source: 'main',
|
||||
summary_prompt: 'Pause your roleplay. Summarize the most important parts of the message. Limit yourself to 250 words or less. Your response should include nothing but the summary.',
|
||||
|
||||
// For chats
|
||||
enabled_chats: false,
|
||||
|
@ -158,9 +167,8 @@ async function summarizeExtra(hashedMessages) {
|
|||
}
|
||||
|
||||
async function summarizeMain(hashedMessages) {
|
||||
const sysPrompt = 'Pause your roleplay. Summarize the most important parts of the message. Limit yourself to 250 words or less. Your response should include nothing but the summary.';
|
||||
for (const element of hashedMessages) {
|
||||
element.text = await generateRaw(element.text, '', false, false, sysPrompt);
|
||||
element.text = await generateRaw(element.text, '', false, false, settings.summary_prompt);
|
||||
}
|
||||
|
||||
return hashedMessages;
|
||||
|
@ -465,7 +473,7 @@ async function getQueryText(chat) {
|
|||
|
||||
let hashedMessages = chat.map(x => ({ text: String(substituteParams(x.mes)) }));
|
||||
|
||||
if (settings.summarize) {
|
||||
if (settings.summarize && settings.summarize_sent) {
|
||||
hashedMessages = await summarize(hashedMessages, settings.summary_source);
|
||||
}
|
||||
|
||||
|
@ -839,12 +847,24 @@ jQuery(async () => {
|
|||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#vectors_summary_source').val(settings.togetherai_model).on('change', () => {
|
||||
$('#vectors_summarize_user').prop('checked', settings.summarize_sent).on('input', () => {
|
||||
settings.summarize_sent = !!$('#vectors_summarize_user').prop('checked');
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#vectors_summary_source').val(settings.summary_source).on('change', () => {
|
||||
settings.summary_source = String($('#vectors_summary_source').val());
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#vectors_summary_prompt').val(settings.summary_prompt).on('input', () => {
|
||||
settings.summary_prompt = String($('#vectors_summary_prompt').val());
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#vectors_message_chunk_size').val(settings.message_chunk_size).on('input', () => {
|
||||
settings.message_chunk_size = Number($('#vectors_message_chunk_size').val());
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
|
|
|
@ -83,15 +83,28 @@
|
|||
<hr>
|
||||
|
||||
<div class="flex-container flexFlowColumn">
|
||||
<span>Summarization for vectors is an experimental feature that may improve vectors or may worsen them. Use at your own discretion.</span>
|
||||
<label class="checkbox_label expander" for="vectors_summarize" title="Summarize chat messages before generating embeddings.">
|
||||
<input id="vectors_summarize" type="checkbox" class="checkbox">
|
||||
Summarize chat messages
|
||||
Summarize chat messages for vector generation
|
||||
</label>
|
||||
<i class="failure">Warning: This will slow down vector generation drastically, as all messages have to be summarized first.</i>
|
||||
|
||||
<label class="checkbox_label expander" for="vectors_summarize_user" title="Summarize sent chat messages before generating embeddings.">
|
||||
<input id="vectors_summarize_user" type="checkbox" class="checkbox">
|
||||
Summarize chat messages when sending
|
||||
</label>
|
||||
<i class="failure">Warning: This might cause your sent messages to take a bit to process and slow down response time.</i>
|
||||
|
||||
<label for="vectors_summary_source">Summarize with:</label>
|
||||
<select id="vectors_summary_source" class="text_pole">
|
||||
<option value="main">Main API</option>
|
||||
<option value="extras">Extras API</option>
|
||||
</select>
|
||||
|
||||
<label for="vectors_summary_prompt">Summary Prompt:</label>
|
||||
<small>Only used when Main API is selected.</small>
|
||||
<textarea id="vectors_summary_prompt" class="text_pole textarea_compact" rows="6" placeholder="This prompt will be sent to AI to request the summary generation."></textarea>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
|
Loading…
Reference in New Issue