diff --git a/aiserver.py b/aiserver.py index 33b50f60..a592b6f2 100644 --- a/aiserver.py +++ b/aiserver.py @@ -9927,6 +9927,41 @@ def UI_2_refresh_auto_memory(data): koboldai_vars.auto_memory += "\n\n Final Result:\n" + output +#==================================================================# +# Story review zero-shot +#==================================================================# +@socketio.on("story_review") +@logger.catch +def UI_2_story_review(data): + who = data["who"] + template = data.get("template", "\n\n%s's thoughts on this situation:\n\"") + prompt = template % who + logger.info(prompt) + + context = koboldai_vars.calc_ai_text( + prompt, + return_text=True, + send_context=False + ) + + out_text = raw_generate( + context, + max_new=30, + ).decoded[0] + + + out_text = re.sub(r"[\s\(\)]", " ", out_text) + # Beware contractions! + # out_text = re.sub(r"[\s!\.\?]'", " ", out_text) + while " " in out_text: + out_text = out_text.replace(" ", " ") + + if '"' in out_text: + out_text = out_text.split('"')[0] + + out_text = out_text.strip() + out_text = utils.trimincompletesentence(out_text) + emit("show_story_review", {"who": who, "review": out_text}) #==================================================================# # Get next 100 actions for infinate scroll diff --git a/static/koboldai.js b/static/koboldai.js index 7f4bcb66..78740806 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -34,6 +34,7 @@ socket.on("log_message", function(data){process_log_message(data);}); socket.on("debug_message", function(data){console.log(data);}); socket.on("scratchpad_response", recieveScratchpadResponse); socket.on("show_error_notification", function(data) { reportError(data.title, data.text) }); +socket.on("show_story_review", showStoryReview); //socket.onAny(function(event_name, data) {console.log({"event": event_name, "class": data.classname, "data": data});}); // Must be done before any elements are made; we track their changes. @@ -6680,4 +6681,15 @@ function imgGenRetry() { }); -})(); \ No newline at end of file +})(); + +function requestStoryReview(who, template=null) { + let data = {who: who}; + if (template) data.template = template; + socket.emit("story_review", data); +} + +function showStoryReview(data) { + console.log(`${data.who}: ${data.review}`) + +} \ No newline at end of file