mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
feature: derived templates
This PR adds a simple hash based method for picking context and instruct templates based on the chat template, when provided by the back end.
This commit is contained in:
@@ -267,6 +267,7 @@ import { applyBrowserFixes } from './scripts/browser-fixes.js';
|
||||
import { initServerHistory } from './scripts/server-history.js';
|
||||
import { initSettingsSearch } from './scripts/setting-search.js';
|
||||
import { initBulkEdit } from './scripts/bulk-edit.js';
|
||||
import { deriveTemplatesFromChatTemplate } from './scripts/chat-cemplates.js';
|
||||
|
||||
//exporting functions and vars for mods
|
||||
export {
|
||||
@@ -1235,6 +1236,31 @@ async function getStatusTextgen() {
|
||||
const supportsTokenization = response.headers.get('x-supports-tokenization') === 'true';
|
||||
supportsTokenization ? sessionStorage.setItem(TOKENIZER_SUPPORTED_KEY, 'true') : sessionStorage.removeItem(TOKENIZER_SUPPORTED_KEY);
|
||||
|
||||
const supportsChatTemplate = response.headers.get('x-supports-chat-template') === 'true';
|
||||
|
||||
if (supportsChatTemplate) {
|
||||
const response = await fetch('/api/backends/text-completions/chat_template', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({
|
||||
api_server: endpoint,
|
||||
api_type: textgen_settings.type,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
if (data) {
|
||||
const chat_template = data.chat_template;
|
||||
console.log(`We have chat template ${chat_template.split('\n')[0]}...`);
|
||||
const templates = await deriveTemplatesFromChatTemplate(chat_template);
|
||||
if (templates) {
|
||||
const { context, instruct } = templates;
|
||||
selectContextPreset(context, { isAuto: true });
|
||||
selectInstructPreset(instruct, { isAuto: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress.
|
||||
if (online_status === 'no_connection' && data.response) {
|
||||
toastr.error(data.response, t`API Error`, { timeOut: 5000, preventDuplicates: true });
|
||||
|
Reference in New Issue
Block a user