Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b74d5ace7 | ||
|
|
bb5a451b50 | ||
|
|
f25ecbd95c | ||
|
|
9af7c63d9c | ||
|
|
5763404b05 | ||
|
|
4f9cbe5a5d | ||
|
|
50526a16b9 | ||
|
|
b180aeaae5 | ||
|
|
4f14557011 | ||
|
|
d10dc61131 | ||
|
|
b069ea9f55 | ||
|
|
c70214585a |
@@ -259,6 +259,7 @@ class Client {
|
||||
constructor(auto_reconnect = false, use_cached_bots = false) {
|
||||
this.auto_reconnect = auto_reconnect;
|
||||
this.use_cached_bots = use_cached_bots;
|
||||
this.abortController = new AbortController();
|
||||
}
|
||||
|
||||
async init(token, proxy = null) {
|
||||
@@ -267,6 +268,7 @@ class Client {
|
||||
timeout: 60000,
|
||||
httpAgent: new http.Agent({ keepAlive: true }),
|
||||
httpsAgent: new https.Agent({ keepAlive: true }),
|
||||
signal: this.abortController.signal,
|
||||
});
|
||||
if (proxy) {
|
||||
this.session.defaults.proxy = {
|
||||
@@ -544,6 +546,8 @@ class Client {
|
||||
let messageId;
|
||||
while (true) {
|
||||
try {
|
||||
this.abortController.signal.throwIfAborted();
|
||||
|
||||
const message = this.message_queues[humanMessageId].shift();
|
||||
if (!message) {
|
||||
await new Promise(resolve => setTimeout(() => resolve(), 1000));
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>
|
||||
<option value="gpt-3.5-turbo-0301">gpt-3.5-turbo-0301</option>
|
||||
<option value="gpt-4">gpt-4</option>
|
||||
<option value="gpt-4-32k">gpt-4-32k</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+26
-31
@@ -1028,7 +1028,7 @@ function getStoppingStrings(isImpersonate, addSpace) {
|
||||
const charString = `\n${name2}:`;
|
||||
const userString = is_pygmalion ? `\nYou:` : `\n${name1}:`;
|
||||
const result = isImpersonate ? charString : userString;
|
||||
return addSpace ? `${result} ` : result;
|
||||
return [addSpace ? `${result} ` : result];
|
||||
}
|
||||
|
||||
function getSlashCommand(message, type) {
|
||||
@@ -1273,6 +1273,7 @@ class StreamingProcessor {
|
||||
this.isStopped = false;
|
||||
this.isFinished = false;
|
||||
this.generator = this.nullStreamingGeneration;
|
||||
this.abortController = new AbortController();
|
||||
}
|
||||
|
||||
async generate() {
|
||||
@@ -1458,20 +1459,10 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
storyString += appendToStoryString(charPersonality, power_user.disable_personality_formatting ? '' : 'Personality: ');
|
||||
storyString += appendToStoryString(Scenario, power_user.disable_scenario_formatting ? '' : 'Scenario: ');
|
||||
} else {
|
||||
if (charDescription !== undefined) {
|
||||
if (charPersonality.length > 0 && !power_user.disable_personality_formatting) {
|
||||
charPersonality = name2 + "'s personality: " + charPersonality;
|
||||
}
|
||||
}
|
||||
|
||||
storyString += appendToStoryString(charDescription, '');
|
||||
|
||||
if (storyString.endsWith('\n')) {
|
||||
storyString = storyString.slice(0, -1);
|
||||
}
|
||||
|
||||
if (count_view_mes < topAnchorDepth) {
|
||||
storyString += '\n' + appendToStoryString(charPersonality, '');
|
||||
storyString += appendToStoryString(charPersonality, power_user.disable_personality_formatting ? '' : name2 + "'s personality: ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1484,9 +1475,6 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
if (power_user.pin_examples && main_api !== 'openai') {
|
||||
for (let example of mesExamplesArray) {
|
||||
if (!is_pygmalion) {
|
||||
if (!storyString.endsWith('\n')) {
|
||||
storyString += '\n';
|
||||
}
|
||||
const replaceString = power_user.disable_examples_formatting ? '' : `This is how ${name2} should talk`;
|
||||
example = example.replace(/<START>/i, replaceString);
|
||||
}
|
||||
@@ -1645,9 +1633,6 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
}
|
||||
}
|
||||
if (!is_pygmalion && Scenario && Scenario.length > 0) {
|
||||
if (!storyString.endsWith('\n')) {
|
||||
storyString += '\n';
|
||||
}
|
||||
storyString += !power_user.disable_scenario_formatting ? `Circumstances and context of the dialogue: ${Scenario}\n` : `${Scenario}\n`;
|
||||
}
|
||||
console.log('calling runGenerate');
|
||||
@@ -1682,9 +1667,9 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
is_add_personality = true;
|
||||
//chatString = chatString.substr(0,chatString.length-1);
|
||||
//anchorAndPersonality = "[Genre: roleplay chat][Tone: very long messages with descriptions]";
|
||||
if ((anchorTop != "" || charPersonality != "") && !is_pygmalion) {
|
||||
if (anchorTop != "") charPersonality += ' ';
|
||||
item += "[" + charPersonality + anchorTop + ']\n';
|
||||
let personalityAndAnchor = [ charPersonality, anchorTop ].filter(x => x).join(' ');
|
||||
if (personalityAndAnchor && !is_pygmalion) {
|
||||
item += "[" + personalityAndAnchor + ']\n';
|
||||
}
|
||||
}
|
||||
if (i >= arrMes.length - 1 && count_view_mes > 8 && $.trim(item).substr(0, (name1 + ":").length) == name1 + ":" && !is_pygmalion) {//For add anchor in end
|
||||
@@ -1898,7 +1883,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
'early_stopping': textgenerationwebui_settings.early_stopping,
|
||||
'seed': textgenerationwebui_settings.seed,
|
||||
'add_bos_token': textgenerationwebui_settings.add_bos_token,
|
||||
'custom_stopping_strings': JSON.stringify(getStoppingStrings(isImpersonate, false)),
|
||||
'stopping_strings': getStoppingStrings(isImpersonate, false),
|
||||
'truncation_length': max_context,
|
||||
'ban_eos_token': textgenerationwebui_settings.ban_eos_token,
|
||||
'skip_special_tokens': textgenerationwebui_settings.skip_special_tokens,
|
||||
@@ -1946,7 +1931,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
let prompt = await prepareOpenAIMessages(name2, storyString, worldInfoBefore, worldInfoAfter, afterScenarioAnchor, promptBias, type);
|
||||
|
||||
if (isStreamingEnabled()) {
|
||||
streamingProcessor.generator = await sendOpenAIRequest(prompt);
|
||||
streamingProcessor.generator = await sendOpenAIRequest(prompt, streamingProcessor.abortController.signal);
|
||||
}
|
||||
else {
|
||||
sendOpenAIRequest(prompt).then(onSuccess).catch(onError);
|
||||
@@ -1957,14 +1942,14 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
}
|
||||
else if (main_api == 'poe') {
|
||||
if (isStreamingEnabled()) {
|
||||
streamingProcessor.generator = await generatePoe(type, finalPromt);
|
||||
streamingProcessor.generator = await generatePoe(type, finalPromt, streamingProcessor.abortController.signal);
|
||||
}
|
||||
else {
|
||||
generatePoe(type, finalPromt).then(onSuccess).catch(onError);
|
||||
}
|
||||
}
|
||||
else if (main_api == 'textgenerationwebui' && textgenerationwebui_settings.streaming) {
|
||||
streamingProcessor.generator = await generateTextGenWithStreaming(generate_data);
|
||||
streamingProcessor.generator = await generateTextGenWithStreaming(generate_data, streamingProcessor.abortController.signal);
|
||||
}
|
||||
else {
|
||||
jQuery.ajax({
|
||||
@@ -2196,13 +2181,15 @@ function cleanUpMessage(getMessage, isImpersonate) {
|
||||
getMessage = getMessage.trim();
|
||||
}
|
||||
|
||||
const stoppingString = getStoppingStrings(isImpersonate, false);
|
||||
const stoppingStrings = getStoppingStrings(isImpersonate, false);
|
||||
|
||||
if (stoppingString.length) {
|
||||
for (let j = stoppingString.length - 1; j > 0; j--) {
|
||||
if (getMessage.slice(-j) === stoppingString.slice(0, j)) {
|
||||
getMessage = getMessage.slice(0, -j);
|
||||
break;
|
||||
for (const stoppingString of stoppingStrings) {
|
||||
if (stoppingString.length) {
|
||||
for (let j = stoppingString.length - 1; j > 0; j--) {
|
||||
if (getMessage.slice(-j) === stoppingString.slice(0, j)) {
|
||||
getMessage = getMessage.slice(0, -j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5030,6 +5017,7 @@ $(document).ready(function () {
|
||||
|
||||
$(document).on("click", ".mes_stop", function () {
|
||||
if (streamingProcessor) {
|
||||
streamingProcessor.abortController.abort();
|
||||
streamingProcessor.isStopped = true;
|
||||
streamingProcessor.onStopStreaming();
|
||||
streamingProcessor = null;
|
||||
@@ -5123,4 +5111,11 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('beforeunload', () => {
|
||||
if (streamingProcessor) {
|
||||
console.log('Page reloaded. Aborting streaming...');
|
||||
streamingProcessor.abortController.abort();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -91,12 +91,6 @@ async function onSelectImage(e) {
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
function patchSendForm() {
|
||||
const columns = $('#send_form').css('grid-template-columns').split(' ');
|
||||
columns[columns.length - 1] = `${parseInt(columns[columns.length - 1]) + 40}px`;
|
||||
columns[1] = 'auto';
|
||||
$('#send_form').css('grid-template-columns', columns.join(' '));
|
||||
}
|
||||
function addSendPictureButton() {
|
||||
const sendButton = document.createElement('div');
|
||||
sendButton.id = 'send_picture';
|
||||
@@ -118,7 +112,6 @@ $(document).ready(function () {
|
||||
addPictureSendForm();
|
||||
addSendPictureButton();
|
||||
setImageIcon();
|
||||
patchSendForm();
|
||||
moduleWorker();
|
||||
setInterval(moduleWorker, UPDATE_INTERVAL);
|
||||
});
|
||||
@@ -79,13 +79,6 @@ function addDiceScript() {
|
||||
}
|
||||
}
|
||||
|
||||
function patchSendForm() {
|
||||
const columns = $('#send_form').css('grid-template-columns').split(' ');
|
||||
columns[columns.length - 1] = `${parseInt(columns[columns.length - 1]) + 40}px`;
|
||||
columns[1] = 'auto';
|
||||
$('#send_form').css('grid-template-columns', columns.join(' '));
|
||||
}
|
||||
|
||||
async function moduleWorker() {
|
||||
const context = getContext();
|
||||
|
||||
@@ -97,7 +90,6 @@ async function moduleWorker() {
|
||||
$(document).ready(function () {
|
||||
addDiceScript();
|
||||
addDiceRollButton();
|
||||
patchSendForm();
|
||||
setDiceIcon();
|
||||
moduleWorker();
|
||||
setInterval(moduleWorker, UPDATE_INTERVAL);
|
||||
|
||||
@@ -85,7 +85,7 @@ function getKoboldGenerationData(finalPromt, this_settings, this_amount_gen, thi
|
||||
s7: this_settings.sampler_order[6],
|
||||
use_world_info: false,
|
||||
singleline: kai_settings.single_line,
|
||||
stop_sequence: kai_settings.use_stop_sequence ? [getStoppingStrings(isImpersonate, false)] : undefined,
|
||||
stop_sequence: kai_settings.use_stop_sequence ? getStoppingStrings(isImpersonate, false) : undefined,
|
||||
};
|
||||
return generate_data;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ const default_impersonation_prompt = "[Write your next reply from the point of v
|
||||
|
||||
const gpt3_max = 4095;
|
||||
const gpt4_max = 8191;
|
||||
const gpt4_32k_max = 32767;
|
||||
|
||||
const tokenCache = {};
|
||||
|
||||
@@ -435,7 +436,12 @@ function getSystemPrompt(nsfw_toggle_prompt, enhance_definitions_prompt, wiBefor
|
||||
return whole_prompt;
|
||||
}
|
||||
|
||||
async function sendOpenAIRequest(openai_msgs_tosend) {
|
||||
async function sendOpenAIRequest(openai_msgs_tosend, signal) {
|
||||
// Provide default abort signal
|
||||
if (!signal) {
|
||||
signal = new AbortController().signal;
|
||||
}
|
||||
|
||||
if (oai_settings.reverse_proxy) {
|
||||
validateReverseProxy();
|
||||
}
|
||||
@@ -458,7 +464,8 @@ async function sendOpenAIRequest(openai_msgs_tosend) {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"X-CSRF-Token": token,
|
||||
}
|
||||
},
|
||||
signal: signal,
|
||||
});
|
||||
|
||||
if (oai_settings.stream_openai) {
|
||||
@@ -772,6 +779,9 @@ $(document).ready(function () {
|
||||
if (value == 'gpt-4') {
|
||||
$('#openai_max_context').attr('max', gpt4_max);
|
||||
}
|
||||
else if (value == 'gpt-4-32k') {
|
||||
$('#openai_max_context').attr('max', gpt4_32k_max);
|
||||
}
|
||||
else {
|
||||
$('#openai_max_context').attr('max', gpt3_max);
|
||||
oai_settings.openai_max_context = Math.max(oai_settings.openai_max_context, gpt3_max);
|
||||
|
||||
@@ -86,7 +86,7 @@ function onBotChange() {
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
async function generatePoe(type, finalPrompt) {
|
||||
async function generatePoe(type, finalPrompt, signal) {
|
||||
if (poe_settings.auto_purge) {
|
||||
let count_to_delete = -1;
|
||||
|
||||
@@ -136,7 +136,7 @@ async function generatePoe(type, finalPrompt) {
|
||||
finalPrompt = sentences.join('');
|
||||
}
|
||||
|
||||
const reply = await sendMessage(finalPrompt, true);
|
||||
const reply = await sendMessage(finalPrompt, true, signal);
|
||||
got_reply = true;
|
||||
return reply;
|
||||
}
|
||||
@@ -160,7 +160,11 @@ async function purgeConversation(count = -1) {
|
||||
return response.ok;
|
||||
}
|
||||
|
||||
async function sendMessage(prompt, withStreaming) {
|
||||
async function sendMessage(prompt, withStreaming, signal) {
|
||||
if (!signal) {
|
||||
signal = new AbortController().signal;
|
||||
}
|
||||
|
||||
const body = JSON.stringify({
|
||||
bot: poe_settings.bot,
|
||||
token: poe_settings.token,
|
||||
@@ -175,6 +179,7 @@ async function sendMessage(prompt, withStreaming) {
|
||||
},
|
||||
body: body,
|
||||
method: 'POST',
|
||||
signal: signal,
|
||||
});
|
||||
|
||||
if (withStreaming && poe_settings.streaming) {
|
||||
|
||||
@@ -26,11 +26,11 @@ let textgenerationwebui_settings = {
|
||||
seed: -1,
|
||||
preset: 'Default',
|
||||
add_bos_token: true,
|
||||
custom_stopping_strings: [],
|
||||
stopping_strings: [],
|
||||
truncation_length: 2048,
|
||||
ban_eos_token: false,
|
||||
streaming: false,
|
||||
fn_index: 34,
|
||||
fn_index: 43,
|
||||
skip_special_tokens: true,
|
||||
};
|
||||
|
||||
@@ -147,7 +147,7 @@ function setSettingByName(i, value, trigger) {
|
||||
}
|
||||
}
|
||||
|
||||
async function generateTextGenWithStreaming(generate_data) {
|
||||
async function generateTextGenWithStreaming(generate_data, signal) {
|
||||
const response = await fetch('/generate_textgenerationwebui', {
|
||||
headers: {
|
||||
'X-CSRF-Token': token,
|
||||
@@ -157,6 +157,7 @@ async function generateTextGenWithStreaming(generate_data) {
|
||||
},
|
||||
body: JSON.stringify(generate_data),
|
||||
method: 'POST',
|
||||
signal: signal,
|
||||
});
|
||||
|
||||
return async function* streamData() {
|
||||
|
||||
+4
-4
@@ -169,12 +169,12 @@ code {
|
||||
|
||||
#bg1 {
|
||||
background-image: url(backgrounds/tavern1.jpg);
|
||||
z-index: 0;
|
||||
z-index: -2;
|
||||
}
|
||||
|
||||
#bg_custom {
|
||||
background-image: none;
|
||||
z-index: 1;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
/*TOPPER margin*/
|
||||
@@ -279,9 +279,8 @@ code {
|
||||
}
|
||||
|
||||
#send_form {
|
||||
display: grid;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
grid-template-columns: 40px auto 40px;
|
||||
width: 100%;
|
||||
margin: 0 auto 0 auto;
|
||||
border: 1px solid var(--grey30a);
|
||||
@@ -644,6 +643,7 @@ select {
|
||||
font-family: "Noto Sans", "Noto Color Emoji", sans-serif;
|
||||
margin: 0;
|
||||
text-shadow: #000 0 0 3px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
#send_textarea::placeholder,
|
||||
|
||||
@@ -61,7 +61,8 @@ https://rentry.org/TAI_Termux
|
||||
| Character Expressions | See your character reacting to your messages!<br><br>**You need to provide your own character images!**<br><br>1. Create a folder in TavernAI called `public/characters/<name>`, where `<name>` is the name of your character.<br>2. For the base emotion classification model, put six PNG files there with the following names: `joy.png`, `anger.png`, `fear.png`, `love.png`, `sadness.png`, `surprise.png`. Other models may provide other options.<br>3. Images only display in desktop mode. | `classify` | <img style="max-width:200px" alt="image" src="https://user-images.githubusercontent.com/18619528/223765089-34968217-6862-47e0-85da-7357370f8de6.png"> |
|
||||
| Memory | Chatbot long-term memory simulation using automatic message context summarization. | `summarize` | <img style="max-width:200px" alt="image" src="https://user-images.githubusercontent.com/18619528/223766279-88a46481-1fa6-40c5-9724-6cdd6f587233.png"> |
|
||||
| D&D Dice | A set of 7 classic D&D dice for all your dice rolling needs.<br><br>*I used to roll the dice.<br>Feel the fear in my enemies' eyes* | None | <img style="max-width:200px" alt="image" src="https://user-images.githubusercontent.com/18619528/226199925-a066c6fc-745e-4a2b-9203-1cbffa481b14.png"> |
|
||||
| Author's Note | Built-in extension that allows you to append notes that will be added to the context and steer the story and character in a specific direction. Because it's sent after the character description, it has a lot of weight. Thanks Ali឵#2222 for pitching the idea! | None | 
|
||||
| Author's Note | Built-in extension that allows you to append notes that will be added to the context and steer the story and character in a specific direction. Because it's sent after the character description, it has a lot of weight. Thanks Ali឵#2222 for pitching the idea! | None |  |
|
||||
| Character Backgrounds | Built-in extension to assign unique backgrounds to specific chats or groups. | None | <img style="max-width:200px" alt="image" src="https://user-images.githubusercontent.com/18619528/233494454-bfa7c9c7-4faa-4d97-9c69-628fd96edd92.png"> |
|
||||
|
||||
## UI/CSS/Quality of Life tweaks by RossAscends
|
||||
|
||||
|
||||
@@ -367,6 +367,10 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
|
||||
|
||||
if (!!request.header('X-Response-Streaming')) {
|
||||
const fn_index = Number(request.header('X-Gradio-Streaming-Function'));
|
||||
let isStreamingStopped = false;
|
||||
request.socket.on('close', function() {
|
||||
isStreamingStopped = true;
|
||||
});
|
||||
|
||||
response_generate.writeHead(200, {
|
||||
'Content-Type': 'text/plain;charset=utf-8',
|
||||
@@ -404,6 +408,12 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
|
||||
});
|
||||
|
||||
while (true) {
|
||||
if (isStreamingStopped) {
|
||||
console.error('Streaming stopped by user. Closing websocket...');
|
||||
websocket.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (websocket.readyState == 0 || websocket.readyState == 1 || websocket.readyState == 2) {
|
||||
await delay(50);
|
||||
yield text;
|
||||
@@ -424,7 +434,7 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
|
||||
|
||||
let result = JSON.parse(request.body.data)[0];
|
||||
let prompt = result;
|
||||
let stopping_strings = JSON.parse(request.body.data)[1].custom_stopping_strings;
|
||||
let stopping_strings = JSON.parse(request.body.data)[1].stopping_strings;
|
||||
|
||||
try {
|
||||
for await (const text of readWebsocket()) {
|
||||
@@ -1895,6 +1905,12 @@ app.post('/generate_poe', jsonParser, async (request, response) => {
|
||||
}
|
||||
|
||||
if (streaming) {
|
||||
let isStreamingStopped = false;
|
||||
request.socket.on('close', function() {
|
||||
isStreamingStopped = true;
|
||||
client.abortController.abort();
|
||||
});
|
||||
|
||||
try {
|
||||
response.writeHead(200, {
|
||||
'Content-Type': 'text/plain;charset=utf-8',
|
||||
@@ -1904,6 +1920,11 @@ app.post('/generate_poe', jsonParser, async (request, response) => {
|
||||
|
||||
let reply = '';
|
||||
for await (const mes of client.send_message(bot, prompt)) {
|
||||
if (isStreamingStopped) {
|
||||
console.error('Streaming stopped by user. Closing websocket...');
|
||||
break;
|
||||
}
|
||||
|
||||
let newText = mes.text.substring(reply.length);
|
||||
reply = mes.text;
|
||||
response.write(newText);
|
||||
@@ -2135,6 +2156,11 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
|
||||
if (!request.body) return response_generate_openai.sendStatus(400);
|
||||
const api_url = new URL(request.body.reverse_proxy || api_openai).toString();
|
||||
|
||||
const controller = new AbortController();
|
||||
request.socket.on('close', function() {
|
||||
controller.abort();
|
||||
});
|
||||
|
||||
console.log(request.body);
|
||||
const config = {
|
||||
method: 'post',
|
||||
@@ -2153,7 +2179,8 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
|
||||
"frequency_penalty": request.body.frequency_penalty,
|
||||
"stop": request.body.stop,
|
||||
"logit_bias": request.body.logit_bias
|
||||
}
|
||||
},
|
||||
signal: controller.signal,
|
||||
};
|
||||
|
||||
if (request.body.stream)
|
||||
|
||||
Reference in New Issue
Block a user