-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
chathelper.py
48 lines (35 loc) · 1.27 KB
/
chathelper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
chathelper.py - utils to help out parsing the chat
Memoir+ a persona extension for Text Gen Web UI.
MIT License
Copyright (c) 2024 brucepro
"""
from extensions.Memoir.persona.persona import Persona
from extensions.Memoir.commands.urlhandler import UrlHandler
import re
from sqlite3 import connect
import pathlib
import validators
class ChatHelper():
def __init__(self):
pass
def process_string(self, input_string):
pattern = r'\[([^\[\]]+)\]'
emotion_output = {}
commands_in_string = re.findall(pattern, input_string, re.IGNORECASE)
print("Processing commands:" + str(commands_in_string))
def safer_string(self, input_string):
#output_string = input_string.Replace("'","''");
cleaned_string = re.sub(r'[^a-zA-Z0-9\s]+', '', input_string)
return cleaned_string
def remove_dtime(self, input_string):
pattern = r"\[DTime=.*?\]"
new_str = re.sub(pattern, "", input_string)
return new_str
def check_if_narration(input_string):
#pattern check if it is narration.
#set input name for narrator.
if len(input_string) > 0:
if input_string[0] == "*" and input_string[-1] == "*":
return True
return False