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

View File

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