mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Temporarily added auto-memory box to UI.
This commit is contained in:
20
aiserver.py
20
aiserver.py
@@ -8582,8 +8582,10 @@ def summarize(text, max_length=100, min_length=30):
|
||||
#==================================================================#
|
||||
# Test
|
||||
#==================================================================#
|
||||
@app.route("/summarize")
|
||||
def request_summarize():
|
||||
@socketio.on("refresh_auto_memory")
|
||||
@logger.catch
|
||||
def UI_2_refresh_auto_memory(data):
|
||||
koboldai_vars.auto_memory = "Generating..."
|
||||
if koboldai_vars.summary_tokenizer is None:
|
||||
koboldai_vars.summary_tokenizer = AutoTokenizer.from_pretrained("models/{}".format(args.summarizer_model.replace('/', '_')), cache_dir="cache")
|
||||
#first, let's get all of our game text and split it into sentences
|
||||
@@ -8605,19 +8607,15 @@ def request_summarize():
|
||||
new_sentences = []
|
||||
i=0
|
||||
for summary_chunk in summary_chunks:
|
||||
print("summarizing chunk {}".format(i))
|
||||
logger.debug("summarizing chunk {}".format(i))
|
||||
new_sentences.extend(re.split("(?<=[.!?])\s+", summarize(summary_chunk)))
|
||||
i+=1
|
||||
print("Summarized to {} sentencees from {}".format(len(new_sentences), len(sentences)))
|
||||
logger.debug("Summarized to {} sentencees from {}".format(len(new_sentences), len(sentences)))
|
||||
sentences = new_sentences
|
||||
for sentence in sentences:
|
||||
print(sentence)
|
||||
print("OK, doing final summarization")
|
||||
koboldai_vars.auto_memory = "\n".join(sentences)
|
||||
logger.debug("OK, doing final summarization")
|
||||
output = summarize(" ".join(sentences))
|
||||
print(output)
|
||||
return "Input tokens: {}\nOutput tokens: {}\n{}".format(len(koboldai_vars.summary_tokenizer.encode(request.args['text'])),
|
||||
len(koboldai_vars.summary_tokenizer.encode(output)),
|
||||
output)
|
||||
koboldai_vars.auto_memory += "\n" + output
|
||||
|
||||
@app.route("/vars")
|
||||
@logger.catch
|
||||
|
@@ -586,6 +586,7 @@ class story_settings(settings):
|
||||
self.autosave = False # Whether or not to automatically save after each action
|
||||
self.prompt = "" # Prompt
|
||||
self.memory = "" # Text submitted to memory field
|
||||
self.auto_memory = ""
|
||||
self.authornote = "" # Text submitted to Author's Note field
|
||||
self.authornotetemplate = "[Author's note: <|>]" # Author's note template
|
||||
self.setauthornotetemplate = self.authornotetemplate # Saved author's note template in settings
|
||||
|
@@ -13,6 +13,14 @@
|
||||
</span>
|
||||
<textarea rows=20 id="memory" class="var_sync_story_memory var_sync_alt_story_memory_length fullwidth" onchange='sync_to_server(this);' oninput="autoResize(this)" autocomplete="off"></textarea>
|
||||
</div>
|
||||
<div id="Auto-Memory">
|
||||
<h4 class="section_header">Auto-Memory (non-functional)</h4>
|
||||
<span class="help_text">
|
||||
What the system would use for automatic memory summarized from the game
|
||||
</span>
|
||||
<button class="settings_button" onclick="socket.emit('refresh_auto_memory', {});">Generate</button>
|
||||
<textarea rows=20 id="auto_memory" class="var_sync_story_auto_memory fullwidth" oninput="autoResize(this)" autocomplete="off"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div id="story_menu_author" class="story_category_area tab-target tab-target-story hidden">
|
||||
<div id="author_notes">
|
||||
|
Reference in New Issue
Block a user