Spaces:
Sleeping
Sleeping
abrakjamson
commited on
Commit
•
f7a1bd4
1
Parent(s):
5f7f1fd
Implementing streaming chat, moving models, generalizing preset buttons
Browse files- anger.gguf +0 -0
- app.py +147 -84
- control_models/Angry.gguf +0 -0
- control_models/Confident.gguf +0 -0
- control_models/Conspiracies.gguf +0 -0
- creative.gguf → control_models/Creative.gguf +0 -0
- control_models/Empathatic.gguf +0 -0
- control_models/Joking.gguf +0 -0
- lazy.gguf → control_models/Lazy.gguf +0 -0
- control_models/Optimistic.gguf +0 -0
- right-leaning.gguf → control_models/Right-leaning.gguf +0 -0
- control_models/Tripping.gguf +0 -0
- tripping.gguf +0 -0
- truthful.gguf +0 -0
anger.gguf
DELETED
Binary file (509 kB)
|
|
app.py
CHANGED
@@ -25,6 +25,9 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
25 |
use_safetensors=True
|
26 |
)
|
27 |
model = model.to("cuda:0" if torch.cuda.is_available() else "cpu")
|
|
|
|
|
|
|
28 |
model = ControlModel(model, list(range(-5, -18, -1)))
|
29 |
|
30 |
# Generation settings
|
@@ -39,17 +42,50 @@ default_generation_settings = {
|
|
39 |
user_tag, asst_tag = "[INST]", "[/INST]"
|
40 |
|
41 |
# List available control vectors
|
42 |
-
control_vector_files = [f for f in os.listdir('
|
43 |
|
44 |
if not control_vector_files:
|
45 |
-
raise FileNotFoundError("No .gguf control vector files found in the
|
46 |
|
47 |
# Function to toggle slider visibility based on checkbox state
|
48 |
def toggle_slider(checked):
|
49 |
return gr.update(visible=checked)
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
def generate_response(system_prompt, user_message, history, max_new_tokens, repitition_penalty, do_sample, *args):
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
# Separate checkboxes and sliders based on type
|
55 |
# The first x in args are the checkbox names (the file names)
|
@@ -69,7 +105,7 @@ def generate_response(system_prompt, user_message, history, max_new_tokens, repi
|
|
69 |
weight = sliders[i]
|
70 |
try:
|
71 |
# Set the control vector's weight (and sign) by multiplying by its slider value
|
72 |
-
control_vectors.append(ControlVector.import_gguf(cv_file) * weight)
|
73 |
assistant_message_title += f"{cv_file.split('.')[0]}: {weight};"
|
74 |
except Exception as e:
|
75 |
print(f"Failed to set control vector {cv_file}: {e}")
|
@@ -83,32 +119,14 @@ def generate_response(system_prompt, user_message, history, max_new_tokens, repi
|
|
83 |
else:
|
84 |
combined_vector += control_vectors[i]
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
if len(history) > 0:
|
93 |
-
formatted_prompt += "<s>"
|
94 |
-
|
95 |
-
# Append the system prompt if provided
|
96 |
-
if system_prompt.strip():
|
97 |
-
formatted_prompt += f"{user_tag} {system_prompt}{asst_tag} "
|
98 |
-
|
99 |
-
# Construct the formatted prompt based on history
|
100 |
-
#TODO move back to ChatMessage type instead of Tuple, because the message title gets into the history
|
101 |
-
if len(history) > 0:
|
102 |
-
for turn in history:
|
103 |
-
user_msg, asst_msg = turn
|
104 |
-
formatted_prompt += f"{user_tag} {user_msg} {asst_tag} {asst_msg}"
|
105 |
-
|
106 |
-
|
107 |
-
if len(history) > 0:
|
108 |
-
formatted_prompt += "</s>"
|
109 |
|
110 |
-
|
111 |
-
formatted_prompt += f"{user_tag} {user_message} {asst_tag}"
|
112 |
|
113 |
# Tokenize the input
|
114 |
input_ids = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
|
@@ -120,40 +138,81 @@ def generate_response(system_prompt, user_message, history, max_new_tokens, repi
|
|
120 |
"repetition_penalty": repetition_penalty.value,
|
121 |
}
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
|
|
|
|
127 |
def get_assistant_response(input_string):
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
134 |
|
135 |
-
assistant_response = get_assistant_response(response)
|
136 |
-
|
137 |
# Update conversation history
|
138 |
-
assistant_response = get_assistant_response(
|
139 |
assistant_response_display = f"*{assistant_message_title}*\n\n{assistant_response}"
|
140 |
|
141 |
# Update conversation history
|
142 |
history.append((user_message, assistant_response_display))
|
143 |
-
|
144 |
|
145 |
def generate_response_with_retry(system_prompt, user_message, history, max_new_tokens, repitition_penalty, do_sample, *args):
|
146 |
# Remove last user input and assistant response from history, then call generate_response()
|
147 |
if history:
|
148 |
history = history[0:-1]
|
149 |
-
|
|
|
150 |
|
151 |
# Function to reset the conversation history
|
152 |
def reset_chat():
|
153 |
# returns a blank state
|
154 |
-
return [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
-
# I'm not a good enough coder with Python and Gradio to figure out how to generalize this. PRs accepted!
|
157 |
def set_preset_helpful(*args):
|
158 |
# gets the list of all checkboxes and sliders
|
159 |
# sets checkboxes and sliders accordingly to this persona
|
@@ -162,18 +221,20 @@ def set_preset_helpful(*args):
|
|
162 |
count_checkboxes = int(len(args)/2)
|
163 |
new_checkbox_values = []
|
164 |
new_slider_values = []
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
167 |
new_checkbox_values.append(True)
|
168 |
-
# set slider value (sliders are after the checkboxes)
|
169 |
new_slider_values.append(1.0)
|
170 |
-
elif
|
171 |
new_checkbox_values.append(True)
|
172 |
-
# set slider value (sliders are after the checkboxes)
|
173 |
new_slider_values.append(1.0)
|
174 |
else:
|
175 |
new_checkbox_values.append(False)
|
176 |
new_slider_values.append(0.0)
|
|
|
177 |
return new_checkbox_values + new_slider_values
|
178 |
|
179 |
def set_preset_conspiracist(*args):
|
@@ -181,29 +242,29 @@ def set_preset_conspiracist(*args):
|
|
181 |
# sets checkboxes and sliders accordingly to this persona
|
182 |
# args is a list of checkboxes and then slider values
|
183 |
# must return the updated list of checkboxes and sliders
|
184 |
-
|
185 |
new_checkbox_values = []
|
186 |
new_slider_values = []
|
187 |
-
|
188 |
-
|
|
|
|
|
|
|
189 |
new_checkbox_values.append(True)
|
190 |
-
# set slider value (sliders are after the checkboxes)
|
191 |
new_slider_values.append(1.5)
|
192 |
-
elif
|
193 |
new_checkbox_values.append(True)
|
194 |
-
# set slider value (sliders are after the checkboxes)
|
195 |
new_slider_values.append(1.0)
|
196 |
-
elif
|
197 |
new_checkbox_values.append(True)
|
198 |
-
# set slider value (sliders are after the checkboxes)
|
199 |
new_slider_values.append(-0.5)
|
200 |
-
elif
|
201 |
new_checkbox_values.append(True)
|
202 |
-
# set slider value (sliders are after the checkboxes)
|
203 |
new_slider_values.append(-1.0)
|
204 |
else:
|
205 |
new_checkbox_values.append(False)
|
206 |
new_slider_values.append(0.0)
|
|
|
207 |
return new_checkbox_values + new_slider_values
|
208 |
|
209 |
def set_preset_stoner(*args):
|
@@ -211,25 +272,25 @@ def set_preset_stoner(*args):
|
|
211 |
# sets checkboxes and sliders accordingly to this persona
|
212 |
# args is a list of checkboxes and then slider values
|
213 |
# must return the updated list of checkboxes and sliders
|
214 |
-
count_checkboxes = int(len(args)/2)
|
215 |
new_checkbox_values = []
|
216 |
new_slider_values = []
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
219 |
new_checkbox_values.append(True)
|
220 |
-
# set slider value (sliders are after the checkboxes)
|
221 |
new_slider_values.append(0.5)
|
222 |
-
elif
|
223 |
new_checkbox_values.append(True)
|
224 |
-
# set slider value (sliders are after the checkboxes)
|
225 |
new_slider_values.append(-0.5)
|
226 |
-
elif
|
227 |
new_checkbox_values.append(True)
|
228 |
-
# set slider value (sliders are after the checkboxes)
|
229 |
new_slider_values.append(0.6)
|
230 |
else:
|
231 |
new_checkbox_values.append(False)
|
232 |
new_slider_values.append(0.0)
|
|
|
233 |
return new_checkbox_values + new_slider_values
|
234 |
|
235 |
def set_preset_facts(*args):
|
@@ -237,29 +298,28 @@ def set_preset_facts(*args):
|
|
237 |
# sets checkboxes and sliders accordingly to this persona
|
238 |
# args is a list of checkboxes and then slider values
|
239 |
# must return the updated list of checkboxes and sliders
|
240 |
-
count_checkboxes = int(len(args)/2)
|
241 |
new_checkbox_values = []
|
242 |
new_slider_values = []
|
243 |
-
|
244 |
-
|
|
|
|
|
|
|
245 |
new_checkbox_values.append(True)
|
246 |
-
# set slider value (sliders are after the checkboxes)
|
247 |
new_slider_values.append(0.5)
|
248 |
-
elif
|
249 |
new_checkbox_values.append(True)
|
250 |
-
# set slider value (sliders are after the checkboxes)
|
251 |
new_slider_values.append(-0.5)
|
252 |
-
elif
|
253 |
new_checkbox_values.append(True)
|
254 |
-
# set slider value (sliders are after the checkboxes)
|
255 |
new_slider_values.append(-0.5)
|
256 |
-
elif
|
257 |
new_checkbox_values.append(True)
|
258 |
-
# set slider value (sliders are after the checkboxes)
|
259 |
new_slider_values.append(0.5)
|
260 |
else:
|
261 |
new_checkbox_values.append(False)
|
262 |
new_slider_values.append(0.0)
|
|
|
263 |
return new_checkbox_values + new_slider_values
|
264 |
|
265 |
tooltip_css = """
|
@@ -315,6 +375,7 @@ with gr.Blocks(
|
|
315 |
theme=dark_theme,
|
316 |
css=tooltip_css,
|
317 |
) as app:
|
|
|
318 |
|
319 |
# Header
|
320 |
gr.Markdown("# 🧠 LLM Brain Control")
|
@@ -326,7 +387,7 @@ with gr.Blocks(
|
|
326 |
gr.Markdown("### ⚡ Control Vectors")
|
327 |
control_vector_label = gr.HTML("""
|
328 |
<div class="tooltip">
|
329 |
-
<span>Select how you want to control the LLM - towards (+) or away (-). Or start with a preset:</span>
|
330 |
<span class="tooltiptext">+/- 1.0 is a good start. Check the examples for each vector.</span>
|
331 |
</div>
|
332 |
""")
|
@@ -334,7 +395,7 @@ with gr.Blocks(
|
|
334 |
with gr.Row():
|
335 |
|
336 |
button_helpful = gr.Button(
|
337 |
-
value="Kind and helpful"
|
338 |
)
|
339 |
button_facts = gr.Button(
|
340 |
value="Just the facts"
|
@@ -353,7 +414,7 @@ with gr.Blocks(
|
|
353 |
for cv_file in control_vector_files:
|
354 |
with gr.Row():
|
355 |
# Checkbox to select the control vector
|
356 |
-
checkbox = gr.Checkbox(label=cv_file, value=False)
|
357 |
control_checks.append(checkbox)
|
358 |
|
359 |
# Slider to adjust the control vector's weight
|
@@ -362,7 +423,7 @@ with gr.Blocks(
|
|
362 |
maximum=2.5,
|
363 |
value=0.0,
|
364 |
step=0.1,
|
365 |
-
label=f"
|
366 |
visible=False
|
367 |
)
|
368 |
control_sliders.append(slider)
|
@@ -390,7 +451,7 @@ with gr.Blocks(
|
|
390 |
max_tokens_label = gr.HTML("""
|
391 |
<div class="tooltip">
|
392 |
<span>Max Response Length (in tokens)</span>
|
393 |
-
<span class="tooltiptext">
|
394 |
</div>
|
395 |
""")
|
396 |
max_new_tokens = gr.Number(
|
@@ -433,7 +494,9 @@ with gr.Blocks(
|
|
433 |
gr.Markdown("### 🗨️ Conversation")
|
434 |
|
435 |
# Chatbot to display conversation
|
436 |
-
chatbot = gr.Chatbot(
|
|
|
|
|
437 |
|
438 |
# User Message Input with tooltip
|
439 |
#with gr.Row():
|
|
|
25 |
use_safetensors=True
|
26 |
)
|
27 |
model = model.to("cuda:0" if torch.cuda.is_available() else "cpu")
|
28 |
+
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
29 |
+
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
30 |
+
|
31 |
model = ControlModel(model, list(range(-5, -18, -1)))
|
32 |
|
33 |
# Generation settings
|
|
|
42 |
user_tag, asst_tag = "[INST]", "[/INST]"
|
43 |
|
44 |
# List available control vectors
|
45 |
+
control_vector_files = [f for f in os.listdir('control_models') if f.endswith('.gguf')]
|
46 |
|
47 |
if not control_vector_files:
|
48 |
+
raise FileNotFoundError("No .gguf control vector files found in the control_models directory.")
|
49 |
|
50 |
# Function to toggle slider visibility based on checkbox state
|
51 |
def toggle_slider(checked):
|
52 |
return gr.update(visible=checked)
|
53 |
|
54 |
+
def construct_prompt(history, system_prompt, user_message):
|
55 |
+
"""
|
56 |
+
Converts the history (list of tuples) back into the string format Mistral expects
|
57 |
+
"""
|
58 |
+
formatted_prompt = ""
|
59 |
+
|
60 |
+
# <s>[INST] user message[/INST] assistant message</s>[INST] new user message[/INST]
|
61 |
+
# Mistral expects the history to be wrapped in <s>history</s>, so it's added here
|
62 |
+
if len(history) > 0:
|
63 |
+
formatted_prompt += "<s>"
|
64 |
+
|
65 |
+
# Append the system prompt if provided
|
66 |
+
if system_prompt.strip():
|
67 |
+
formatted_prompt += f"{user_tag} {system_prompt}{asst_tag} "
|
68 |
+
|
69 |
+
# Construct the formatted prompt based on history
|
70 |
+
if len(history) > 0:
|
71 |
+
for turn in history:
|
72 |
+
user_msg, asst_msg = turn
|
73 |
+
asst_msg = asst_msg.split("\n")[1:]
|
74 |
+
formatted_prompt += f"{user_tag} {user_msg} {asst_tag} {asst_msg}"
|
75 |
+
|
76 |
+
if len(history) > 0:
|
77 |
+
formatted_prompt += "</s>"
|
78 |
+
|
79 |
+
# Append the new user message
|
80 |
+
formatted_prompt += f"{user_tag} {user_message} {asst_tag}"
|
81 |
+
return formatted_prompt
|
82 |
+
|
83 |
def generate_response(system_prompt, user_message, history, max_new_tokens, repitition_penalty, do_sample, *args):
|
84 |
+
"""
|
85 |
+
Applies the control vectors and calls the language model.
|
86 |
+
Returns a list of tuples, the user message and the assistant response,
|
87 |
+
which Gradio uses to update the chatbot history
|
88 |
+
"""
|
89 |
|
90 |
# Separate checkboxes and sliders based on type
|
91 |
# The first x in args are the checkbox names (the file names)
|
|
|
105 |
weight = sliders[i]
|
106 |
try:
|
107 |
# Set the control vector's weight (and sign) by multiplying by its slider value
|
108 |
+
control_vectors.append(ControlVector.import_gguf(f"control_models/{cv_file}") * weight)
|
109 |
assistant_message_title += f"{cv_file.split('.')[0]}: {weight};"
|
110 |
except Exception as e:
|
111 |
print(f"Failed to set control vector {cv_file}: {e}")
|
|
|
119 |
else:
|
120 |
combined_vector += control_vectors[i]
|
121 |
|
122 |
+
# Set the combined set of vectors as the control for the model
|
123 |
+
try:
|
124 |
+
if combined_vector is not None:
|
125 |
+
model.set_control(combined_vector)
|
126 |
+
except Exception as e:
|
127 |
+
print(f"Failed to set Control: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
+
formatted_prompt = construct_prompt(history, system_prompt, user_message)
|
|
|
130 |
|
131 |
# Tokenize the input
|
132 |
input_ids = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
|
|
|
138 |
"repetition_penalty": repetition_penalty.value,
|
139 |
}
|
140 |
|
141 |
+
_streamer = TextIteratorStreamer(tokenizer, timeout=10., skip_prompt=True, skip_special_tokens=False,)
|
142 |
+
|
143 |
+
generate_kwargs = dict(
|
144 |
+
input_ids,
|
145 |
+
streamer=_streamer,
|
146 |
+
pad_token_id= tokenizer.eos_token_id,
|
147 |
+
do_sample= do_sample,
|
148 |
+
max_new_tokens= int(max_new_tokens),
|
149 |
+
repetition_penalty= repetition_penalty.value,
|
150 |
+
)
|
151 |
+
t = threading.Thread(target=model.generate, kwargs=generate_kwargs)
|
152 |
+
|
153 |
+
t.start()
|
154 |
+
|
155 |
+
# Display the response as it streams in, prepending the control vector info
|
156 |
+
partial_message = ""
|
157 |
+
for new_token in _streamer:
|
158 |
+
if new_token != '<' and new_token != '</s>': # seems to hit EOS correctly without this needed
|
159 |
+
partial_message += new_token
|
160 |
+
partial_with_title = "*" + assistant_message_title + "*" + "\n\n" + partial_message
|
161 |
+
temp_history = history + [(user_message, partial_with_title)]
|
162 |
+
yield temp_history
|
163 |
+
else:
|
164 |
+
_streamer.end()
|
165 |
|
166 |
+
# remove the trailing </s> if present
|
167 |
+
# it won't be present if the model ran out from max_tokens
|
168 |
def get_assistant_response(input_string):
|
169 |
+
if len(input_string) >= 4:
|
170 |
+
if input_string[-4:] == "</s>":
|
171 |
+
return input_string[:-4]
|
172 |
+
else:
|
173 |
+
return input_string
|
174 |
+
else:
|
175 |
+
return input_string
|
176 |
|
|
|
|
|
177 |
# Update conversation history
|
178 |
+
assistant_response = get_assistant_response(partial_message)
|
179 |
assistant_response_display = f"*{assistant_message_title}*\n\n{assistant_response}"
|
180 |
|
181 |
# Update conversation history
|
182 |
history.append((user_message, assistant_response_display))
|
183 |
+
yield history
|
184 |
|
185 |
def generate_response_with_retry(system_prompt, user_message, history, max_new_tokens, repitition_penalty, do_sample, *args):
|
186 |
# Remove last user input and assistant response from history, then call generate_response()
|
187 |
if history:
|
188 |
history = history[0:-1]
|
189 |
+
for output in generate_response(system_prompt, user_message, history, max_new_tokens, repetition_penalty, do_sample, *args):
|
190 |
+
yield output
|
191 |
|
192 |
# Function to reset the conversation history
|
193 |
def reset_chat():
|
194 |
# returns a blank state
|
195 |
+
return [], ""
|
196 |
+
|
197 |
+
def get_checkboxes():
|
198 |
+
# rebuilding the list of checkboxes, so that these presets don't have to change
|
199 |
+
# when adding a new control model
|
200 |
+
checkbox_column = app.children[2].children[0].children
|
201 |
+
model_names_and_indexes = {}
|
202 |
+
checkbox_index = 0
|
203 |
+
for i in range(len(checkbox_column)):
|
204 |
+
if isinstance(checkbox_column[i], gr.Row):
|
205 |
+
try:
|
206 |
+
model_name = checkbox_column[i].children[0].children[0].label
|
207 |
+
model_names_and_indexes[model_name] = checkbox_index
|
208 |
+
checkbox_index += 1
|
209 |
+
except IndexError:
|
210 |
+
# allow for other rows to be in the interface
|
211 |
+
pass
|
212 |
+
except AttributeError:
|
213 |
+
pass
|
214 |
+
return model_names_and_indexes
|
215 |
|
|
|
216 |
def set_preset_helpful(*args):
|
217 |
# gets the list of all checkboxes and sliders
|
218 |
# sets checkboxes and sliders accordingly to this persona
|
|
|
221 |
count_checkboxes = int(len(args)/2)
|
222 |
new_checkbox_values = []
|
223 |
new_slider_values = []
|
224 |
+
|
225 |
+
model_names_and_indexes = get_checkboxes()
|
226 |
+
|
227 |
+
for check in model_names_and_indexes:
|
228 |
+
if check == "Empathatic":
|
229 |
new_checkbox_values.append(True)
|
|
|
230 |
new_slider_values.append(1.0)
|
231 |
+
elif check == "Optimistic":
|
232 |
new_checkbox_values.append(True)
|
|
|
233 |
new_slider_values.append(1.0)
|
234 |
else:
|
235 |
new_checkbox_values.append(False)
|
236 |
new_slider_values.append(0.0)
|
237 |
+
|
238 |
return new_checkbox_values + new_slider_values
|
239 |
|
240 |
def set_preset_conspiracist(*args):
|
|
|
242 |
# sets checkboxes and sliders accordingly to this persona
|
243 |
# args is a list of checkboxes and then slider values
|
244 |
# must return the updated list of checkboxes and sliders
|
245 |
+
|
246 |
new_checkbox_values = []
|
247 |
new_slider_values = []
|
248 |
+
|
249 |
+
model_names_and_indexes = get_checkboxes()
|
250 |
+
|
251 |
+
for check in model_names_and_indexes:
|
252 |
+
if check == "Conspiracies":
|
253 |
new_checkbox_values.append(True)
|
|
|
254 |
new_slider_values.append(1.5)
|
255 |
+
elif check == "Creative":
|
256 |
new_checkbox_values.append(True)
|
|
|
257 |
new_slider_values.append(1.0)
|
258 |
+
elif check == "Lazy":
|
259 |
new_checkbox_values.append(True)
|
|
|
260 |
new_slider_values.append(-0.5)
|
261 |
+
elif check == "Truthful":
|
262 |
new_checkbox_values.append(True)
|
|
|
263 |
new_slider_values.append(-1.0)
|
264 |
else:
|
265 |
new_checkbox_values.append(False)
|
266 |
new_slider_values.append(0.0)
|
267 |
+
|
268 |
return new_checkbox_values + new_slider_values
|
269 |
|
270 |
def set_preset_stoner(*args):
|
|
|
272 |
# sets checkboxes and sliders accordingly to this persona
|
273 |
# args is a list of checkboxes and then slider values
|
274 |
# must return the updated list of checkboxes and sliders
|
|
|
275 |
new_checkbox_values = []
|
276 |
new_slider_values = []
|
277 |
+
|
278 |
+
model_names_and_indexes = get_checkboxes()
|
279 |
+
|
280 |
+
for check in model_names_and_indexes:
|
281 |
+
if check == "Angry":
|
282 |
new_checkbox_values.append(True)
|
|
|
283 |
new_slider_values.append(0.5)
|
284 |
+
elif check == "Right-leaning":
|
285 |
new_checkbox_values.append(True)
|
|
|
286 |
new_slider_values.append(-0.5)
|
287 |
+
elif check == "Tripping":
|
288 |
new_checkbox_values.append(True)
|
|
|
289 |
new_slider_values.append(0.6)
|
290 |
else:
|
291 |
new_checkbox_values.append(False)
|
292 |
new_slider_values.append(0.0)
|
293 |
+
|
294 |
return new_checkbox_values + new_slider_values
|
295 |
|
296 |
def set_preset_facts(*args):
|
|
|
298 |
# sets checkboxes and sliders accordingly to this persona
|
299 |
# args is a list of checkboxes and then slider values
|
300 |
# must return the updated list of checkboxes and sliders
|
|
|
301 |
new_checkbox_values = []
|
302 |
new_slider_values = []
|
303 |
+
|
304 |
+
model_names_and_indexes = get_checkboxes()
|
305 |
+
|
306 |
+
for check in model_names_and_indexes:
|
307 |
+
if check == "Confident":
|
308 |
new_checkbox_values.append(True)
|
|
|
309 |
new_slider_values.append(0.5)
|
310 |
+
elif check == "Joking":
|
311 |
new_checkbox_values.append(True)
|
|
|
312 |
new_slider_values.append(-0.5)
|
313 |
+
elif check == "Lazy":
|
314 |
new_checkbox_values.append(True)
|
|
|
315 |
new_slider_values.append(-0.5)
|
316 |
+
elif check == "Truthful":
|
317 |
new_checkbox_values.append(True)
|
|
|
318 |
new_slider_values.append(0.5)
|
319 |
else:
|
320 |
new_checkbox_values.append(False)
|
321 |
new_slider_values.append(0.0)
|
322 |
+
|
323 |
return new_checkbox_values + new_slider_values
|
324 |
|
325 |
tooltip_css = """
|
|
|
375 |
theme=dark_theme,
|
376 |
css=tooltip_css,
|
377 |
) as app:
|
378 |
+
|
379 |
|
380 |
# Header
|
381 |
gr.Markdown("# 🧠 LLM Brain Control")
|
|
|
387 |
gr.Markdown("### ⚡ Control Vectors")
|
388 |
control_vector_label = gr.HTML("""
|
389 |
<div class="tooltip">
|
390 |
+
<span>Select how you want to control the LLM per turn - towards (+) or away (-). Or start with a preset:</span>
|
391 |
<span class="tooltiptext">+/- 1.0 is a good start. Check the examples for each vector.</span>
|
392 |
</div>
|
393 |
""")
|
|
|
395 |
with gr.Row():
|
396 |
|
397 |
button_helpful = gr.Button(
|
398 |
+
value="Kind and helpful",
|
399 |
)
|
400 |
button_facts = gr.Button(
|
401 |
value="Just the facts"
|
|
|
414 |
for cv_file in control_vector_files:
|
415 |
with gr.Row():
|
416 |
# Checkbox to select the control vector
|
417 |
+
checkbox = gr.Checkbox(label=cv_file.split('.')[0], value=False)
|
418 |
control_checks.append(checkbox)
|
419 |
|
420 |
# Slider to adjust the control vector's weight
|
|
|
423 |
maximum=2.5,
|
424 |
value=0.0,
|
425 |
step=0.1,
|
426 |
+
label=f"Voltage",
|
427 |
visible=False
|
428 |
)
|
429 |
control_sliders.append(slider)
|
|
|
451 |
max_tokens_label = gr.HTML("""
|
452 |
<div class="tooltip">
|
453 |
<span>Max Response Length (in tokens)</span>
|
454 |
+
<span class="tooltiptext">Lower for faster output, higher to allow longer answers</span>
|
455 |
</div>
|
456 |
""")
|
457 |
max_new_tokens = gr.Number(
|
|
|
494 |
gr.Markdown("### 🗨️ Conversation")
|
495 |
|
496 |
# Chatbot to display conversation
|
497 |
+
chatbot = gr.Chatbot(
|
498 |
+
type="tuples"
|
499 |
+
)
|
500 |
|
501 |
# User Message Input with tooltip
|
502 |
#with gr.Row():
|
control_models/Angry.gguf
ADDED
Binary file (509 kB). View file
|
|
control_models/Confident.gguf
ADDED
Binary file (509 kB). View file
|
|
control_models/Conspiracies.gguf
ADDED
Binary file (509 kB). View file
|
|
creative.gguf → control_models/Creative.gguf
RENAMED
File without changes
|
control_models/Empathatic.gguf
ADDED
Binary file (509 kB). View file
|
|
control_models/Joking.gguf
ADDED
Binary file (509 kB). View file
|
|
lazy.gguf → control_models/Lazy.gguf
RENAMED
File without changes
|
control_models/Optimistic.gguf
ADDED
Binary file (509 kB). View file
|
|
right-leaning.gguf → control_models/Right-leaning.gguf
RENAMED
File without changes
|
control_models/Tripping.gguf
ADDED
Binary file (509 kB). View file
|
|
tripping.gguf
DELETED
Binary file (509 kB)
|
|
truthful.gguf
DELETED
Binary file (509 kB)
|
|