mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
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:
21
aiserver.py
21
aiserver.py
@ -24,6 +24,8 @@ import packaging
|
|||||||
import contextlib
|
import contextlib
|
||||||
import traceback
|
import traceback
|
||||||
import threading
|
import threading
|
||||||
|
import markdown
|
||||||
|
import bleach
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from typing import Any, Callable, TypeVar, Tuple, Union, Dict, Set, List
|
from typing import Any, Callable, TypeVar, Tuple, Union, Dict, Set, List
|
||||||
|
|
||||||
@ -198,6 +200,7 @@ class vars:
|
|||||||
nopromptgen = False
|
nopromptgen = False
|
||||||
rngpersist = False
|
rngpersist = False
|
||||||
nogenmod = False
|
nogenmod = False
|
||||||
|
welcome = False # Custom Welcome Text (False is default)
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Function to get model selection at startup
|
# Function to get model selection at startup
|
||||||
@ -422,6 +425,8 @@ def loadmodelsettings():
|
|||||||
vars.dynamicscan = js["dynamicscan"]
|
vars.dynamicscan = js["dynamicscan"]
|
||||||
if("formatoptns" in js):
|
if("formatoptns" in js):
|
||||||
vars.formatoptns = js["formatoptns"]
|
vars.formatoptns = js["formatoptns"]
|
||||||
|
if("welcome" in js):
|
||||||
|
vars.welcome = js["welcome"]
|
||||||
if("antemplate" in js):
|
if("antemplate" in js):
|
||||||
vars.setauthornotetemplate = js["antemplate"]
|
vars.setauthornotetemplate = js["antemplate"]
|
||||||
if(not vars.gamestarted):
|
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)
|
emit('from_server', {'cmd': 'usstatitems', 'data': loaded, 'flash': last_userscripts != vars.last_userscripts}, broadcast=True)
|
||||||
vars.last_userscripts = last_userscripts
|
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
|
# Send start message and tell Javascript to set UI state
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def setStartState():
|
def setStartState():
|
||||||
txt = "<span>Welcome to <span class=\"color_cyan\">KoboldAI</span>! You are running <span class=\"color_green\">"+getmodelname()+"</span>.<br/>"
|
if(vars.welcome):
|
||||||
if(not vars.noai):
|
txt = kml(vars.welcome) + "<br/>"
|
||||||
txt = txt + "Please load a game or enter a prompt below to begin!</span>"
|
|
||||||
else:
|
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."
|
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': 'updatescreen', 'gamestarted': vars.gamestarted, 'data': txt}, broadcast=True)
|
||||||
emit('from_server', {'cmd': 'setgamestate', 'data': 'start'}, broadcast=True)
|
emit('from_server', {'cmd': 'setgamestate', 'data': 'start'}, broadcast=True)
|
||||||
|
@ -11,6 +11,8 @@ dependencies:
|
|||||||
- tensorflow-gpu
|
- tensorflow-gpu
|
||||||
- python=3.8.*
|
- python=3.8.*
|
||||||
- eventlet
|
- eventlet
|
||||||
|
- markdown
|
||||||
|
- bleach
|
||||||
- pip
|
- pip
|
||||||
- git
|
- git
|
||||||
- pip:
|
- pip:
|
||||||
|
@ -12,6 +12,8 @@ dependencies:
|
|||||||
- cudatoolkit=11.1
|
- cudatoolkit=11.1
|
||||||
- transformers
|
- transformers
|
||||||
- eventlet
|
- eventlet
|
||||||
|
- markdown
|
||||||
|
- bleach
|
||||||
- pip
|
- pip
|
||||||
- git
|
- git
|
||||||
- pip:
|
- pip:
|
||||||
|
@ -7,6 +7,8 @@ dependencies:
|
|||||||
- flask-socketio
|
- flask-socketio
|
||||||
- python=3.8.*
|
- python=3.8.*
|
||||||
- eventlet
|
- eventlet
|
||||||
|
- markdown
|
||||||
|
- bleach
|
||||||
- pip
|
- pip
|
||||||
- git
|
- git
|
||||||
- pip:
|
- pip:
|
||||||
|
@ -9,6 +9,8 @@ dependencies:
|
|||||||
- flask-socketio
|
- flask-socketio
|
||||||
- python=3.8.*
|
- python=3.8.*
|
||||||
- eventlet
|
- eventlet
|
||||||
|
- markdown
|
||||||
|
- bleach
|
||||||
- pip
|
- pip
|
||||||
- git
|
- git
|
||||||
- pip:
|
- pip:
|
||||||
|
@ -6,4 +6,6 @@ torch
|
|||||||
flask-cloudflared
|
flask-cloudflared
|
||||||
flask-ngrok
|
flask-ngrok
|
||||||
eventlet
|
eventlet
|
||||||
lupa==1.10
|
lupa==1.10
|
||||||
|
markdown
|
||||||
|
bleach
|
@ -13,4 +13,6 @@ Flask-SocketIO
|
|||||||
flask-cloudflared >= 0.0.5
|
flask-cloudflared >= 0.0.5
|
||||||
flask-ngrok
|
flask-ngrok
|
||||||
eventlet
|
eventlet
|
||||||
lupa==1.10
|
lupa==1.10
|
||||||
|
markdown
|
||||||
|
bleach
|
Reference in New Issue
Block a user