mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add extension API for external prompt additions
This commit is contained in:
@ -207,6 +207,7 @@
|
|||||||
var anchor_order = 0;
|
var anchor_order = 0;
|
||||||
var style_anchor = true;
|
var style_anchor = true;
|
||||||
var character_anchor = true;
|
var character_anchor = true;
|
||||||
|
let extension_prompt = '';
|
||||||
|
|
||||||
var main_api = 'kobold';
|
var main_api = 'kobold';
|
||||||
//novel settings
|
//novel settings
|
||||||
@ -710,6 +711,7 @@
|
|||||||
}
|
}
|
||||||
function clearChat(){
|
function clearChat(){
|
||||||
count_view_mes = 0;
|
count_view_mes = 0;
|
||||||
|
extension_prompt = '';
|
||||||
$('#chat').html('');
|
$('#chat').html('');
|
||||||
}
|
}
|
||||||
function messageFormating(mes, ch_name, isSystem, forceAvatar){
|
function messageFormating(mes, ch_name, isSystem, forceAvatar){
|
||||||
@ -1189,7 +1191,7 @@
|
|||||||
|
|
||||||
for (var item of chat2) {//console.log(encode("dsfs").length);
|
for (var item of chat2) {//console.log(encode("dsfs").length);
|
||||||
chatString = item+chatString;
|
chatString = item+chatString;
|
||||||
if(encode(JSON.stringify(worldInfoString+storyString+chatString+anchorTop+anchorBottom+charPersonality+promptBias)).length+120 < this_max_context){ //(The number of tokens in the entire promt) need fix, it must count correctly (added +120, so that the description of the character does not hide)
|
if(encode(JSON.stringify(worldInfoString+storyString+chatString+anchorTop+anchorBottom+charPersonality+promptBias+extension_prompt)).length+120 < this_max_context){ //(The number of tokens in the entire promt) need fix, it must count correctly (added +120, so that the description of the character does not hide)
|
||||||
|
|
||||||
|
|
||||||
//if (is_pygmalion && i == chat2.length-1) item='<START>\n'+item;
|
//if (is_pygmalion && i == chat2.length-1) item='<START>\n'+item;
|
||||||
@ -1205,7 +1207,7 @@
|
|||||||
let mesExmString = '';
|
let mesExmString = '';
|
||||||
for(let iii = 0; iii < mesExamplesArray.length; iii++){//mesExamplesArray It need to make from end to start
|
for(let iii = 0; iii < mesExamplesArray.length; iii++){//mesExamplesArray It need to make from end to start
|
||||||
mesExmString = mesExmString+mesExamplesArray[iii];
|
mesExmString = mesExmString+mesExamplesArray[iii];
|
||||||
if(encode(JSON.stringify(worldInfoString+storyString+mesExmString+chatString+anchorTop+anchorBottom+charPersonality+promptBias)).length+120 < this_max_context){ //example of dialogs
|
if(encode(JSON.stringify(worldInfoString+storyString+mesExmString+chatString+anchorTop+anchorBottom+charPersonality+promptBias+extension_prompt)).length+120 < this_max_context){ //example of dialogs
|
||||||
if(!is_pygmalion){
|
if(!is_pygmalion){
|
||||||
mesExamplesArray[iii] = mesExamplesArray[iii].replace(/<START>/i, 'This is how '+name2+' should talk');//An example of how '+name2+' responds
|
mesExamplesArray[iii] = mesExamplesArray[iii].replace(/<START>/i, 'This is how '+name2+' should talk');//An example of how '+name2+' responds
|
||||||
}
|
}
|
||||||
@ -1305,7 +1307,7 @@
|
|||||||
}
|
}
|
||||||
function checkPromtSize(){
|
function checkPromtSize(){
|
||||||
setPromtString();
|
setPromtString();
|
||||||
let thisPromtContextSize = encode(JSON.stringify(worldInfoString+storyString+mesExmString+mesSendString+anchorTop+anchorBottom+charPersonality+generatedPromtCache+promptBias)).length+120;
|
let thisPromtContextSize = encode(JSON.stringify(worldInfoString+storyString+mesExmString+mesSendString+anchorTop+anchorBottom+charPersonality+generatedPromtCache+promptBias+extension_prompt)).length+120;
|
||||||
if(thisPromtContextSize > this_max_context){
|
if(thisPromtContextSize > this_max_context){
|
||||||
if(count_exm_add > 0){
|
if(count_exm_add > 0){
|
||||||
//mesExamplesArray.length = mesExamplesArray.length-1;
|
//mesExamplesArray.length = mesExamplesArray.length-1;
|
||||||
@ -1334,7 +1336,7 @@
|
|||||||
mesSendString = '<START>\n'+mesSendString;
|
mesSendString = '<START>\n'+mesSendString;
|
||||||
//mesSendString = mesSendString; //This edit simply removes the first "<START>" that is prepended to all context prompts
|
//mesSendString = mesSendString; //This edit simply removes the first "<START>" that is prepended to all context prompts
|
||||||
}
|
}
|
||||||
finalPromt = worldInfoBefore+storyString+worldInfoAfter+mesExmString+mesSendString+generatedPromtCache+promptBias;
|
finalPromt = worldInfoBefore+storyString+worldInfoAfter+extension_prompt+mesExmString+mesSendString+generatedPromtCache+promptBias;
|
||||||
|
|
||||||
var generate_data;
|
var generate_data;
|
||||||
if(main_api == 'kobold'){
|
if(main_api == 'kobold'){
|
||||||
@ -4379,6 +4381,10 @@
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setExtensionPrompt(value) {
|
||||||
|
extension_prompt = value;
|
||||||
|
}
|
||||||
|
|
||||||
window['TavernAI'].getContext = function() {
|
window['TavernAI'].getContext = function() {
|
||||||
return {
|
return {
|
||||||
chat: chat,
|
chat: chat,
|
||||||
@ -4393,6 +4399,8 @@
|
|||||||
addOneMessage: addOneMessage,
|
addOneMessage: addOneMessage,
|
||||||
generate: Generate,
|
generate: Generate,
|
||||||
encode: encode,
|
encode: encode,
|
||||||
|
extensionPrompt: extension_prompt,
|
||||||
|
setExtensionPrompt: setExtensionPrompt,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -15,6 +15,9 @@ let extensions = [];
|
|||||||
<input id="extensions_autoconnect" type="checkbox"/><h4>Auto-connect</h4>
|
<input id="extensions_autoconnect" type="checkbox"/><h4>Auto-connect</h4>
|
||||||
</div>
|
</div>
|
||||||
<div id="extensions_status">Not connected</div>
|
<div id="extensions_status">Not connected</div>
|
||||||
|
<div id="extensions_settings">
|
||||||
|
<h4>Extension settings</h4>
|
||||||
|
</div>
|
||||||
<div id="extensions_loaded">
|
<div id="extensions_loaded">
|
||||||
<h4>Active extensions</h4>
|
<h4>Active extensions</h4>
|
||||||
<ul id="extensions_list">
|
<ul id="extensions_list">
|
||||||
@ -138,6 +141,7 @@ let extensions = [];
|
|||||||
|
|
||||||
if (success && extensions.length) {
|
if (success && extensions.length) {
|
||||||
$('#extensions_loaded').show(200);
|
$('#extensions_loaded').show(200);
|
||||||
|
$('#extensions_settings').show(200);
|
||||||
$('#extensions_list').empty();
|
$('#extensions_list').empty();
|
||||||
|
|
||||||
for (let extension of extensions) {
|
for (let extension of extensions) {
|
||||||
@ -146,6 +150,7 @@ let extensions = [];
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('#extensions_loaded').hide(200);
|
$('#extensions_loaded').hide(200);
|
||||||
|
$('#extensions_settings').hide(200);
|
||||||
$('#extensions_list').empty();
|
$('#extensions_list').empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user