From 942839d48d7109194be40eff8550f4ecae2d3802 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 22 Sep 2022 14:21:06 -0400 Subject: [PATCH] Bug fix for world info highlighting --- koboldai_settings.py | 8 ++++---- static/koboldai.js | 31 +++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index 007571cf..54fa75cf 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -145,7 +145,7 @@ class koboldai_vars(object): for wi in self.worldinfo_v2: if wi['constant']: if used_tokens+0 if 'token_length' not in wi else wi['token_length'] <= token_budget: - used_tokens+=wi['token_length'] + used_tokens+=0 if wi['token_length'] is None else wi['token_length'] used_world_info.append(wi['uid']) self.worldinfo_v2.set_world_info_used(wi['uid']) wi_text = wi['content'] @@ -226,7 +226,7 @@ class koboldai_vars(object): break if match: if used_tokens+0 if 'token_length' not in wi else wi['token_length'] <= token_budget: - used_tokens+=wi['token_length'] + used_tokens+=0 if wi['token_length'] is None else wi['token_length'] used_world_info.append(wi['uid']) wi_text = wi['content'] context.append({"type": "world_info", "text": wi_text}) @@ -291,7 +291,7 @@ class koboldai_vars(object): match = False if match: if used_tokens+0 if 'token_length' not in wi or wi['token_length'] is None else wi['token_length'] <= token_budget: - used_tokens+=wi['token_length'] + used_tokens+=0 if wi['token_length'] is None else wi['token_length'] used_world_info.append(wi['uid']) wi_text = wi["content"] if method == 1: @@ -342,7 +342,7 @@ class koboldai_vars(object): break if match: if used_tokens+0 if 'token_length' not in wi else wi['token_length'] <= token_budget: - used_tokens+=wi['token_length'] + used_tokens+=0 if wi['token_length'] is None else wi['token_length'] used_world_info.append(wi['uid']) wi_text = wi['content'] context.append({"type": "world_info", "text": wi_text}) diff --git a/static/koboldai.js b/static/koboldai.js index 2b4cb45c..d928cd3f 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -3113,39 +3113,50 @@ function highlight_world_info_text_in_chunk(action, wi) { var to_check = words.slice(i, i+len_of_keyword).join(" ").replace(/[^0-9a-z \'\"]/gi, '').trim(); if (largest_key == to_check) { var start_word = i; - var end_word = i+len_of_keyword; + var end_word = i+len_of_keyword-1; var passed_words = 0; + //console.log("Finding "+to_check); for (span of action.childNodes) { - if (passed_words + span.textContent.split(" ").length < start_word) { + //console.log(span); + //console.log("passed_words("+passed_words+")+span("+(span.textContent.trim().split(" ").length)+")