Update utils.py
Browse files
utils.py
CHANGED
|
@@ -222,6 +222,48 @@ def rag_chain(prompt, db, k=3):
|
|
| 222 |
|
| 223 |
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
|
| 227 |
|
|
|
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
+
##########################################
|
| 226 |
+
#Hashing....
|
| 227 |
+
# Funktion zum Hashen des Eingabewerts
|
| 228 |
+
def hash_input(input_string):
|
| 229 |
+
return hashlib.sha256(input_string.encode()).hexdigest()
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
########################################
|
| 233 |
+
#zur Zeit nicht im Gebrauch
|
| 234 |
+
def transfer_input(inputs):
|
| 235 |
+
textbox = reset_textbox()
|
| 236 |
+
return (
|
| 237 |
+
inputs,
|
| 238 |
+
gr.update(value=""),
|
| 239 |
+
gr.Button.update(visible=True),
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
#################################################
|
| 244 |
+
#Klasse mit zuständen - z.B. für interrupt wenn Stop gedrückt...
|
| 245 |
+
#################################################
|
| 246 |
+
class State:
|
| 247 |
+
interrupted = False
|
| 248 |
+
|
| 249 |
+
def interrupt(self):
|
| 250 |
+
self.interrupted = True
|
| 251 |
+
|
| 252 |
+
def recover(self):
|
| 253 |
+
self.interrupted = False
|
| 254 |
+
shared_state = State()
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def is_stop_word_or_prefix(s: str, stop_words: list) -> bool:
|
| 260 |
+
for stop_word in stop_words:
|
| 261 |
+
if s.endswith(stop_word):
|
| 262 |
+
return True
|
| 263 |
+
for i in range(1, len(stop_word)):
|
| 264 |
+
if s.endswith(stop_word[:i]):
|
| 265 |
+
return True
|
| 266 |
+
return False
|
| 267 |
|
| 268 |
|
| 269 |
|