Welcome Message API

Allows model creators to customize the welcome message using Markdown and Limited HTML

Existing United users need to run install_requirements..bat again, you can leave the existing dependencies intact.
This commit is contained in:
henk717 2022-01-30 19:47:30 +01:00
parent ddfa21e6dd
commit a484244392
7 changed files with 32 additions and 5 deletions

View File

@ -24,6 +24,8 @@ import packaging
import contextlib
import traceback
import threading
import markdown
import bleach
from collections.abc import Iterable
from typing import Any, Callable, TypeVar, Tuple, Union, Dict, Set, List
@ -198,6 +200,7 @@ class vars:
nopromptgen = False
rngpersist = False
nogenmod = False
welcome = False # Custom Welcome Text (False is default)
#==================================================================#
# Function to get model selection at startup
@ -422,6 +425,8 @@ def loadmodelsettings():
vars.dynamicscan = js["dynamicscan"]
if("formatoptns" in js):
vars.formatoptns = js["formatoptns"]
if("welcome" in js):
vars.welcome = js["welcome"]
if("antemplate" in js):
vars.setauthornotetemplate = js["antemplate"]
if(not vars.gamestarted):
@ -2153,14 +2158,24 @@ def sendUSStatItems():
emit('from_server', {'cmd': 'usstatitems', 'data': loaded, 'flash': last_userscripts != vars.last_userscripts}, broadcast=True)
vars.last_userscripts = last_userscripts
#==================================================================#
# KoboldAI Markup Formatting (Mixture of Markdown and sanitized html)
#==================================================================#
def kml(txt):
txt = bleach.clean(markdown.markdown(txt), tags = ['p', 'em', 'strong', 'code', 'h1', 'h2', 'h3', 'h4', 'h5', 'b', 'i', 'a', 'span', 'button'], styles = ['color', 'font-weight'], attributes=['id', 'class', 'style', 'href'])
return txt
#==================================================================#
# Send start message and tell Javascript to set UI state
#==================================================================#
def setStartState():
txt = "<span>Welcome to <span class=\"color_cyan\">KoboldAI</span>! You are running <span class=\"color_green\">"+getmodelname()+"</span>.<br/>"
if(not vars.noai):
txt = txt + "Please load a game or enter a prompt below to begin!</span>"
if(vars.welcome):
txt = kml(vars.welcome) + "<br/>"
else:
txt = "<span>Welcome to <span class=\"color_cyan\">KoboldAI</span>! You are running <span class=\"color_green\">"+getmodelname()+"</span>.<br/>"
if(not vars.noai and not vars.welcome):
txt = txt + "Please load a game or enter a prompt below to begin!</span>"
if(vars.noai):
txt = txt + "Please load or import a story to read. There is no AI in this mode."
emit('from_server', {'cmd': 'updatescreen', 'gamestarted': vars.gamestarted, 'data': txt}, broadcast=True)
emit('from_server', {'cmd': 'setgamestate', 'data': 'start'}, broadcast=True)

View File

@ -11,6 +11,8 @@ dependencies:
- tensorflow-gpu
- python=3.8.*
- eventlet
- markdown
- bleach
- pip
- git
- pip:

View File

@ -12,6 +12,8 @@ dependencies:
- cudatoolkit=11.1
- transformers
- eventlet
- markdown
- bleach
- pip
- git
- pip:

View File

@ -7,6 +7,8 @@ dependencies:
- flask-socketio
- python=3.8.*
- eventlet
- markdown
- bleach
- pip
- git
- pip:

View File

@ -9,6 +9,8 @@ dependencies:
- flask-socketio
- python=3.8.*
- eventlet
- markdown
- bleach
- pip
- git
- pip:

View File

@ -6,4 +6,6 @@ torch
flask-cloudflared
flask-ngrok
eventlet
lupa==1.10
lupa==1.10
markdown
bleach

View File

@ -13,4 +13,6 @@ Flask-SocketIO
flask-cloudflared >= 0.0.5
flask-ngrok
eventlet
lupa==1.10
lupa==1.10
markdown
bleach