-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
157 lines (124 loc) · 4.17 KB
/
script.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""Extension that allows us to fetch and store memories from/to LTM."""
import json
import pathlib
import pprint
import subprocess
from typing import List, Tuple
import gradio as gr
import modules.shared as shared
from modules.chat import generate_chat_prompt
from modules.text_generation import generate_reply
from modules.html_generator import fix_newlines
from extensions.long_term_memory.core.memory_database import LtmDatabase
from extensions.long_term_memory.utils.chat_parsing import clean_character_message
from extensions.long_term_memory.utils.timestamp_parsing import (
get_time_difference_message,
)
_JSON_PATH = "extensions/super_story_summarizer/utils/example.json"
with open(_JSON_PATH, "rt") as handle:
_HISTORY = json.load(handle)
print("============ TEST HISTORY ============")
print(_HISTORY)
# === Internal constants (don't change these without good reason) ===
_CONFIG_PATH = "extensions/super_story_summarizer/sss_config.json"
_MIN_ROWS_TILL_RESPONSE = 5
_LAST_BOT_MESSAGE_INDEX = -3
_LTM_STATS_TEMPLATE = """{num_memories_seen_by_bot} memories are loaded in the bot
{num_memories_in_ram} memories are loaded in RAM
{num_memories_on_disk} memories are saved to disk"""
with open(_CONFIG_PATH, "rt") as handle:
_CONFIG = json.load(handle)
"""# === Module-level variables ===
debug_texts = {
"current_memory_text": "(None)",
"num_memories_loaded": 0,
"current_context_block": "(None)",
}
memory_database = LtmDatabase(
pathlib.Path("./extensions/super_story_summarizer/user_data/summaries"),
num_memories_to_fetch=_CONFIG["sss_reads"]["num_memories_to_fetch"],
)"""
print("----------")
print("SSS CONFIG")
print("----------")
print("change these values in sss_config.json")
pprint.pprint(_CONFIG)
print("----------")
def setup():
print("Loaded Super Story Summarizer!")
def input_modifier(
user_input,
state
):
bot_name = state["name1"]
user_name = state["name2"]
print("Context:")
print(state["context"])
print("Input:")
print(user_input)
print("========== STATE ==========")
print(state)
history = state["history"]["internal"]
print("History:")
print(f"{history} ::: {not history}")
joinedHistory = ""
if len(history) != 0:
for el in history:
print(f"el {el}")
joinedHistory = f"{joinedHistory}\n\n\n{bot_name}: {el[0]}\n\n{user_name}: {el[1]}"
print("Joined history:")
print(joinedHistory)
# generate_chat_prompt()
return user_input
"""def custom_generate_chat_prompt(
user_input,
state,
**kwargs,
):
""Main hook that allows us to fetch and store memories from/to LTM.""
print("=" * 60)
character_name = state["name2"].strip().lower().replace(" ", "_")
memory_database.load_character_db_if_new(character_name)
user_input = fix_newlines(user_input)
# === Call oobabooga's original generate_chat_prompt ===
augmented_context = state["context"]
if memory_context is not None:
augmented_context = _build_augmented_context(memory_context, state["context"])
debug_texts["current_context_block"] = augmented_context
kwargs["also_return_rows"] = True
state["context"] = augmented_context
(prompt, prompt_rows) = generate_chat_prompt(
user_input,
state,
**kwargs,
)
bot_message = prompt_rows[_LAST_BOT_MESSAGE_INDEX]
print("name:", state["name2"])
print("message:", bot_message)
print("name:", state["name1"])
print("message:", user_input)
print("-----------------------")
return prompt
"""
print("Importing tree_handling.py...")
from extensions.super_story_summarizer.utils.tree_handling import get_custom_prompts
print("Imported!")
characters = {
"main=type_of_character": {
"character": [[
{ "name": "John Mush", },
{ "name": "Paul Mush" },
{ "name": "Amy Harrison" },
{ "name": "Angelina Washington" }
]]
},
"secondary=type_of_character": {
"character": [[{ "name": "Sonya Lopez" }]]
},
"side=type_of_character": {
"character": [[{ "name": "Harry Washington" }]]
}
}
script = get_custom_prompts(characters)
for line in script:
print(line)