mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add support for external TAI API calls
This commit is contained in:
@ -3,7 +3,8 @@ const port = 8000;
|
|||||||
const whitelist = ['127.0.0.1']; //Example for add several IP in whitelist: ['127.0.0.1', '192.168.0.10']
|
const whitelist = ['127.0.0.1']; //Example for add several IP in whitelist: ['127.0.0.1', '192.168.0.10']
|
||||||
const whitelistMode = false; //Disabling enabling the ip whitelist mode. true/false
|
const whitelistMode = false; //Disabling enabling the ip whitelist mode. true/false
|
||||||
const autorun = true; //Autorun in the browser. true/false
|
const autorun = true; //Autorun in the browser. true/false
|
||||||
|
const enableExtensions = true; //Enables support for TavernAI-extras project
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
port, whitelist, whitelistMode, autorun
|
port, whitelist, whitelistMode, autorun, enableExtensions,
|
||||||
};
|
};
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
|
|
||||||
|
|
||||||
<script type=module>
|
<script type=module>
|
||||||
|
// API OBJECT FOR EXTERNAL WIRING
|
||||||
|
window['TavernAI'] = {};
|
||||||
|
|
||||||
import {encode, decode} from "../scripts/gpt-2-3-tokenizer/mod.js";
|
import {encode, decode} from "../scripts/gpt-2-3-tokenizer/mod.js";
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
@ -765,6 +767,14 @@
|
|||||||
const newMessage = $(`#chat [mesid="${count_view_mes}"]`);
|
const newMessage = $(`#chat [mesid="${count_view_mes}"]`);
|
||||||
newMessage.data('isSystem', isSystem);
|
newMessage.data('isSystem', isSystem);
|
||||||
|
|
||||||
|
if (mes.extra?.image) {
|
||||||
|
const image = document.createElement('img');
|
||||||
|
image.src = mes.extra?.image;
|
||||||
|
image.classList.add('img_extra');
|
||||||
|
newMessage.find('.mes_text').css('font-size', '0px');
|
||||||
|
newMessage.find('.mes_text').append(image);
|
||||||
|
}
|
||||||
|
|
||||||
if (isSystem) {
|
if (isSystem) {
|
||||||
newMessage.find('.mes_edit').hide();
|
newMessage.find('.mes_edit').hide();
|
||||||
}
|
}
|
||||||
@ -3371,6 +3381,16 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// end world info settings
|
// end world info settings
|
||||||
|
|
||||||
|
if (data.enable_extensions) {
|
||||||
|
const src = 'scripts/extensions.js';
|
||||||
|
if ($(`script[src="${src}"]`).length === 0) {
|
||||||
|
const script = document.createElement('script');
|
||||||
|
script.type = 'text/javascript';
|
||||||
|
script.src = src;
|
||||||
|
$('body').append(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!is_checked_colab) isColab();
|
if(!is_checked_colab) isColab();
|
||||||
|
|
||||||
@ -4326,6 +4346,19 @@
|
|||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window['TavernAI'].getContext = function() {
|
||||||
|
return {
|
||||||
|
chat: chat,
|
||||||
|
characters: characters,
|
||||||
|
name1: name1,
|
||||||
|
name2: name2,
|
||||||
|
characterId: this_chid,
|
||||||
|
onlineStatus: online_status,
|
||||||
|
addOneMessage: addOneMessage,
|
||||||
|
generate: Generate,
|
||||||
|
};
|
||||||
|
};
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<title>Tavern.AI</title>
|
<title>Tavern.AI</title>
|
||||||
@ -4921,6 +4954,5 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="scripts/extensions.js" type="module"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
|
|
||||||
const settings_html = `
|
const extensions_urlKey = 'extensions_url';
|
||||||
<div class="extensions_block">
|
const extensions_autoConnectKey = 'extensions_autoconnect';
|
||||||
|
let extensions = [];
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
const settings_html = `
|
||||||
|
<div class="extensions_block">
|
||||||
<hr>
|
<hr>
|
||||||
<h3>Extensions</h3>
|
<h3>Extensions</h3>
|
||||||
<input id="extensions_url" type="text" class="text_pole" />
|
<input id="extensions_url" type="text" class="text_pole" />
|
||||||
<div class="extensions_url_block">
|
<div class="extensions_url_block">
|
||||||
<input id="extensions_connect" type="submit" value="Connect" />
|
<input id="extensions_connect" type="submit" value="Connect" />
|
||||||
|
<span class="expander"></span>
|
||||||
<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>
|
||||||
@ -14,34 +20,34 @@ const settings_html = `
|
|||||||
<ul id="extensions_list">
|
<ul id="extensions_list">
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const settings_style = `
|
const settings_style = `
|
||||||
<style>
|
<style>
|
||||||
#extensions_url {
|
#extensions_url {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
#extensions_loaded {
|
#extensions_loaded {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.extensions_block h3 {
|
.extensions_block h3 {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#extensions_status {
|
#extensions_status {
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
opacity: 0.85;
|
opacity: 0.85;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
.extensions_block input[type="submit"]:hover{
|
.extensions_block input[type="submit"]:hover{
|
||||||
background-color: green;
|
background-color: green;
|
||||||
}
|
}
|
||||||
|
|
||||||
.extensions_block input[type="submit"] {
|
.extensions_block input[type="submit"] {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
@ -49,59 +55,61 @@ const settings_style = `
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
height: 2.5rem;
|
height: 2.5rem;
|
||||||
transition: 0.3s;
|
transition: 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.extensions_block input[type="checkbox"] {
|
.extensions_block input[type="checkbox"] {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.extensions_url_block {
|
.extensions_url_block {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
}
|
width: 90%
|
||||||
|
}
|
||||||
|
|
||||||
.extensions_url_block- h4 {
|
.extensions_url_block- h4 {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.extensions_block {
|
.extensions_block {
|
||||||
clear: both;
|
clear: both;
|
||||||
padding: 0.05px; /* clear fix */
|
padding: 0.05px; /* clear fix */
|
||||||
}
|
}
|
||||||
|
|
||||||
.success {
|
.success {
|
||||||
color: green;
|
color: green;
|
||||||
}
|
}
|
||||||
|
|
||||||
.failure {
|
.failure {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
</style>
|
|
||||||
`;
|
|
||||||
|
|
||||||
const urlKey = 'extensions_url';
|
.expander {
|
||||||
const autoConnectKey = 'extensions_autoconnect';
|
flex-grow: 1;
|
||||||
const defaultUrl = "http://localhost:5100";
|
}
|
||||||
let connectedToApi = false;
|
</style>
|
||||||
let extensions = [];
|
`;
|
||||||
|
|
||||||
async function connectClickHandler() {
|
const defaultUrl = "http://localhost:5100";
|
||||||
|
let connectedToApi = false;
|
||||||
|
|
||||||
|
async function connectClickHandler() {
|
||||||
const baseUrl = $("#extensions_url").val();
|
const baseUrl = $("#extensions_url").val();
|
||||||
localStorage.setItem(urlKey, baseUrl);
|
localStorage.setItem(extensions_urlKey, baseUrl);
|
||||||
await connectToApi(baseUrl);
|
await connectToApi(baseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
function autoConnectInputHandler() {
|
function autoConnectInputHandler() {
|
||||||
const value = $(this).prop('checked');
|
const value = $(this).prop('checked');
|
||||||
localStorage.setItem(autoConnectKey, value.toString());
|
localStorage.setItem(extensions_autoConnectKey, value.toString());
|
||||||
|
|
||||||
if (value && !connectedToApi) {
|
if (value && !connectedToApi) {
|
||||||
$("#extensions_connect").trigger('click');
|
$("#extensions_connect").trigger('click');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function connectToApi(baseUrl) {
|
async function connectToApi(baseUrl) {
|
||||||
const url = new URL(baseUrl);
|
const url = new URL(baseUrl);
|
||||||
url.pathname = '/api/extensions';
|
url.pathname = '/api/extensions';
|
||||||
|
|
||||||
@ -119,9 +127,9 @@ async function connectToApi(baseUrl) {
|
|||||||
catch {
|
catch {
|
||||||
updateStatus(false);
|
updateStatus(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStatus(success) {
|
function updateStatus(success) {
|
||||||
connectedToApi = success;
|
connectedToApi = success;
|
||||||
const _text = success ? 'Connected to API' : 'Could not connect to API';
|
const _text = success ? 'Connected to API' : 'Could not connect to API';
|
||||||
const _class = success ? 'success' : 'failure';
|
const _class = success ? 'success' : 'failure';
|
||||||
@ -140,9 +148,9 @@ function updateStatus(success) {
|
|||||||
$('#extensions_loaded').hide(200);
|
$('#extensions_loaded').hide(200);
|
||||||
$('#extensions_list').empty();
|
$('#extensions_list').empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyExtensions(baseUrl) {
|
function applyExtensions(baseUrl) {
|
||||||
const url = new URL(baseUrl);
|
const url = new URL(baseUrl);
|
||||||
|
|
||||||
if (!Array.isArray(extensions) || extensions.length === 0) {
|
if (!Array.isArray(extensions) || extensions.length === 0) {
|
||||||
@ -150,19 +158,11 @@ function applyExtensions(baseUrl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let extension of extensions) {
|
for (let extension of extensions) {
|
||||||
if (extension.metadata.js) {
|
addExtensionStyle(extension);
|
||||||
url.pathname = `/api/script/${extension.name}`;
|
addExtensionScript(extension);
|
||||||
const src = url.toString();
|
|
||||||
|
|
||||||
if ($(`script[src="${src}"]`).length === 0) {
|
|
||||||
const script = document.createElement('script');
|
|
||||||
script.type = 'module';
|
|
||||||
script.src = src;
|
|
||||||
$('body').append(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addExtensionStyle(extension) {
|
||||||
if (extension.metadata.css) {
|
if (extension.metadata.css) {
|
||||||
url.pathname = `/api/style/${extension.name}`;
|
url.pathname = `/api/style/${extension.name}`;
|
||||||
const href = url.toString();
|
const href = url.toString();
|
||||||
@ -176,15 +176,30 @@ function applyExtensions(baseUrl) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready(async function () {
|
function addExtensionScript(extension) {
|
||||||
const url = localStorage.getItem(urlKey) ?? defaultUrl;
|
if (extension.metadata.js) {
|
||||||
const autoConnect = Boolean(localStorage.getItem(autoConnectKey)) ?? false;
|
url.pathname = `/api/script/${extension.name}`;
|
||||||
|
const src = url.toString();
|
||||||
|
|
||||||
|
if ($(`script[src="${src}"]`).length === 0) {
|
||||||
|
const script = document.createElement('script');
|
||||||
|
script.type = 'module';
|
||||||
|
script.src = src;
|
||||||
|
$('body').append(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(async function () {
|
||||||
|
const url = localStorage.getItem(extensions_urlKey) ?? defaultUrl;
|
||||||
|
const autoConnect = Boolean(localStorage.getItem(extensions_autoConnectKey)) ?? false;
|
||||||
$('#rm_api_block').append(settings_html);
|
$('#rm_api_block').append(settings_html);
|
||||||
$('head').append(settings_style);
|
$('head').append(settings_style);
|
||||||
$("#extensions_url").val(url);
|
$("#extensions_url").val(url);
|
||||||
$("#extensions_connect").on('click', connectClickHandler);
|
$("#extensions_connect").on('click', connectClickHandler);
|
||||||
$("#extensions_autoconnect").on('input', autoConnectInputHandler);
|
$("#extensions_autoconnect").on('input', autoConnectInputHandler);
|
||||||
$("#extensions_autoconnect").prop('checked', autoConnect).trigger('input');
|
$("#extensions_autoconnect").prop('checked', autoConnect).trigger('input');
|
||||||
});
|
});
|
||||||
|
})();
|
@ -25,7 +25,7 @@ const server_port = config.port;
|
|||||||
const whitelist = config.whitelist;
|
const whitelist = config.whitelist;
|
||||||
const whitelistMode = config.whitelistMode;
|
const whitelistMode = config.whitelistMode;
|
||||||
const autorun = config.autorun;
|
const autorun = config.autorun;
|
||||||
|
const enableExtensions = config.enableExtensions;
|
||||||
|
|
||||||
|
|
||||||
var Client = require('node-rest-client').Client;
|
var Client = require('node-rest-client').Client;
|
||||||
@ -804,7 +804,8 @@ app.post('/getsettings', jsonParser, (request, response) => { //Wintermute's cod
|
|||||||
koboldai_setting_names,
|
koboldai_setting_names,
|
||||||
world_names,
|
world_names,
|
||||||
novelai_settings,
|
novelai_settings,
|
||||||
novelai_setting_names
|
novelai_setting_names,
|
||||||
|
enable_extensions: enableExtensions,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user