Upload script.py
Browse files
script.py
CHANGED
@@ -424,26 +424,28 @@ def parse_dynamic_lore(lore_string):
|
|
424 |
memories = []
|
425 |
entries = lore_string.strip().split('\n\n') # Split the input string into entries separated by blank lines
|
426 |
|
|
|
|
|
427 |
for entry in entries:
|
428 |
lines = entry.strip().split('\n') # Split each entry into lines
|
429 |
if len(lines) < 2: # Ensure there are at least two lines (keywords and memory text)
|
430 |
continue
|
431 |
|
432 |
keywords_part = lines[0].strip() # First line contains keywords
|
433 |
-
memory_text = '
|
434 |
|
435 |
-
|
|
|
436 |
|
437 |
# Append the parsed data to the memories list
|
438 |
memories.append({
|
439 |
'keywords': ','.join(keywords), # Join keywords with commas
|
440 |
'memory': memory_text
|
441 |
})
|
442 |
-
|
443 |
return memories
|
444 |
|
445 |
|
446 |
-
|
447 |
def atoi(text):
|
448 |
return int(text) if text.isdigit() else text.lower()
|
449 |
|
@@ -629,6 +631,9 @@ def generate_reply_wrapperMY(text_prompt, existing_text_in_output, state, _conti
|
|
629 |
|
630 |
text_to_keep = ""
|
631 |
|
|
|
|
|
|
|
632 |
if dynamic_lore_changed==True:
|
633 |
dynamic_lore = parse_dynamic_lore(params['lorebook'])
|
634 |
dynamic_lore_changed = False
|
@@ -791,10 +796,10 @@ def generate_reply_wrapperMY(text_prompt, existing_text_in_output, state, _conti
|
|
791 |
for dyn_mem_item in dynamic_lore:
|
792 |
# Check to see if keywords are present.
|
793 |
keywords = dyn_mem_item["keywords"].lower().split(",")
|
794 |
-
|
795 |
for keyword in keywords:
|
796 |
keywordsimp = keyword.strip()
|
797 |
if keywordsimp!='' and keywordsimp in user_input_lower:
|
|
|
798 |
# keyword is present in user_input
|
799 |
lore_msg += "\n\n"+ dyn_mem_item["memory"]
|
800 |
|
@@ -905,6 +910,9 @@ def generate_reply_wrapperMY_NP(text_prompt, existing_text_in_output, state, _co
|
|
905 |
|
906 |
text_to_keep = ""
|
907 |
|
|
|
|
|
|
|
908 |
if dynamic_lore_changed==True:
|
909 |
dynamic_lore = parse_dynamic_lore(params['lorebook'])
|
910 |
dynamic_lore_changed = False
|
@@ -1016,6 +1024,7 @@ def generate_reply_wrapperMY_NP(text_prompt, existing_text_in_output, state, _co
|
|
1016 |
keywordsimp = keyword.strip()
|
1017 |
if keywordsimp!='' and keywordsimp in user_input_lower:
|
1018 |
# keyword is present in user_input
|
|
|
1019 |
lore_msg += "\n\n"+ dyn_mem_item["memory"]
|
1020 |
|
1021 |
|
|
|
424 |
memories = []
|
425 |
entries = lore_string.strip().split('\n\n') # Split the input string into entries separated by blank lines
|
426 |
|
427 |
+
print("Parsing lore")
|
428 |
+
|
429 |
for entry in entries:
|
430 |
lines = entry.strip().split('\n') # Split each entry into lines
|
431 |
if len(lines) < 2: # Ensure there are at least two lines (keywords and memory text)
|
432 |
continue
|
433 |
|
434 |
keywords_part = lines[0].strip() # First line contains keywords
|
435 |
+
memory_text = '\n'.join(lines[1:]).strip() # Combine the rest as memory text
|
436 |
|
437 |
+
# Remove colons and process keywords
|
438 |
+
keywords = [kw.replace(':', '').strip().lower() for kw in keywords_part.split(',')]
|
439 |
|
440 |
# Append the parsed data to the memories list
|
441 |
memories.append({
|
442 |
'keywords': ','.join(keywords), # Join keywords with commas
|
443 |
'memory': memory_text
|
444 |
})
|
445 |
+
|
446 |
return memories
|
447 |
|
448 |
|
|
|
449 |
def atoi(text):
|
450 |
return int(text) if text.isdigit() else text.lower()
|
451 |
|
|
|
631 |
|
632 |
text_to_keep = ""
|
633 |
|
634 |
+
if params['lorebook']!='' and not dynamic_lore:
|
635 |
+
dynamic_lore_changed=True
|
636 |
+
|
637 |
if dynamic_lore_changed==True:
|
638 |
dynamic_lore = parse_dynamic_lore(params['lorebook'])
|
639 |
dynamic_lore_changed = False
|
|
|
796 |
for dyn_mem_item in dynamic_lore:
|
797 |
# Check to see if keywords are present.
|
798 |
keywords = dyn_mem_item["keywords"].lower().split(",")
|
|
|
799 |
for keyword in keywords:
|
800 |
keywordsimp = keyword.strip()
|
801 |
if keywordsimp!='' and keywordsimp in user_input_lower:
|
802 |
+
print(f"Found Lore keyword: {keywordsimp}")
|
803 |
# keyword is present in user_input
|
804 |
lore_msg += "\n\n"+ dyn_mem_item["memory"]
|
805 |
|
|
|
910 |
|
911 |
text_to_keep = ""
|
912 |
|
913 |
+
if params['lorebook']!='' and not dynamic_lore:
|
914 |
+
dynamic_lore_changed=True
|
915 |
+
|
916 |
if dynamic_lore_changed==True:
|
917 |
dynamic_lore = parse_dynamic_lore(params['lorebook'])
|
918 |
dynamic_lore_changed = False
|
|
|
1024 |
keywordsimp = keyword.strip()
|
1025 |
if keywordsimp!='' and keywordsimp in user_input_lower:
|
1026 |
# keyword is present in user_input
|
1027 |
+
print(f"Found Lore keyword: {keywordsimp}")
|
1028 |
lore_msg += "\n\n"+ dyn_mem_item["memory"]
|
1029 |
|
1030 |
|