Switched aidg.club import from HTML scrape to API call

Added square bracket to bad_words_ids to help suppress AN tag from leaking into generator output
Added version number to CSS/JS ref to address browser loading outdated versions from cache
This commit is contained in:
KoboldAI Dev 2021-05-16 14:53:19 -04:00
parent 47f1f7a85b
commit ce2e4e1f9e
2 changed files with 26 additions and 27 deletions

View File

@ -1,6 +1,6 @@
#==================================================================#
# KoboldAI Client
# Version: Dev-0.1
# Version: 1.14.0
# By: KoboldAIDev
#==================================================================#
@ -680,6 +680,11 @@ def generate(txt, min, max):
if(vars.hascuda and vars.usegpu):
torch.cuda.empty_cache()
# Suppress Author's Note by flagging square brackets
bad_words = []
bad_words.append(tokenizer("[", add_prefix_space=True).input_ids)
bad_words.append(tokenizer("[", add_prefix_space=False).input_ids)
# Submit input text to generator
genout = generator(
txt,
@ -688,7 +693,8 @@ def generate(txt, min, max):
max_length=max,
repetition_penalty=vars.rep_pen,
top_p=vars.top_p,
temperature=vars.temp
temperature=vars.temp,
bad_words_ids=bad_words
)[0]["generated_text"]
print("{0}{1}{2}".format(colors.CYAN, genout, colors.END))
@ -1284,39 +1290,32 @@ def importgame():
#==================================================================#
# Import an aidg.club prompt and start a new game with it.
#==================================================================#
def importAidgRequest(id):
import html
import re
def importAidgRequest(id):
exitModes()
urlformat = "https://prompts.aidg.club/"
urlformat = "https://prompts.aidg.club/api/"
req = requests.get(urlformat+id)
if(req.status_code == 200):
contents = html.unescape(req.text)
title = re.search("<h3>(.*?)</h3>", contents, re.IGNORECASE | re.MULTILINE | re.DOTALL).group(1).strip()
js = req.json()
keys = re.findall("<h5>(.*?)</h5>", contents, re.IGNORECASE | re.MULTILINE | re.DOTALL)
contents = re.findall("<code class=\"card-text pre-line\">(.*?)</code>", contents, re.IGNORECASE | re.MULTILINE | re.DOTALL)
# Initialize game state
# Import game state
vars.gamestarted = True
vars.prompt = ""
vars.memory = ""
vars.authornote = ""
vars.prompt = js["promptContent"]
vars.memory = js["memory"]
vars.authornote = js["authorsNote"]
vars.actions = []
vars.worldinfo = []
for i in range(len(keys)):
if(keys[i] == "Description"):
pass
elif(keys[i] == "Prompt"):
vars.prompt = contents[i]
elif(keys[i] == "Memory"):
vars.memory = contents[i]
elif(keys[i] == "Author's Note"):
vars.authornote = contents[i]
num = 0
for wi in js["worldInfos"]:
vars.worldinfo.append({
"key": wi["keys"],
"content": wi["entry"],
"num": num,
"init": True
})
num += 1
# Refresh game screen
sendwi()

View File

@ -6,13 +6,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="static/socket.io.min.js"></script>
<script src="static/application.js"></script>
<script src="static/application.js?ver=0.14.1"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="static/bootstrap-toggle.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="static/bootstrap-toggle.min.css">
<link rel="stylesheet" href="static/custom.css">
<link rel="stylesheet" href="static/custom.css?ver=0.14.1">
</head>
<body>
<div class="container">