@@ -21,6 +21,8 @@ def get_args():
21
21
parser .add_argument ("--promptfile" , type = str , help = "Prompt file containing prompts, overrides config (or use prompt section in config)" , required = False )
22
22
parser .add_argument ("--max_messages" , type = int , default = 20 ,
23
23
help = "Max number of messages to keep in the chat history (default: 20)" , required = False )
24
+ parser .add_argument ("--clear_page" , action = "store_true" ,
25
+ help = "Clear the page too when history is cleared (default: keep, add info message)" , required = False )
24
26
parser .add_argument ('--verbose' , action = "store_true" ,
25
27
help = 'Be more verbose' , required = False )
26
28
parser .add_argument ("--debug" , action = "store_true" , help = "Debug mode, overrides loglevel" , required = False )
@@ -92,6 +94,10 @@ def get_args():
92
94
.chat-bubble-secondary {
93
95
background-color: #0A6C0A; /* or #228B22 */
94
96
color: white; /* Text color for readability */
97
+ }
98
+ .chat-bubble-other {
99
+ background-color: blue; /* or #228B22 */
100
+ color: black; /* Text color for readability */
95
101
}
96
102
.btn.btn-primary.btn-disabled.thinking-red-text {
97
103
color: #EF4444 !important; /* Tailwind's red-500 color, with !important to override disabled styles */
@@ -158,10 +164,14 @@ def ChatMessage(msg, kind):
158
164
# other classes: chat-bubble-accent/neutral/info/success/warning/error
159
165
if kind == "error" :
160
166
bubble_class = "chat-bubble-error"
167
+ elif kind == "warning" :
168
+ bubble_class = "chat-bubble-other"
161
169
elif kind == "user" :
162
170
bubble_class = "chat-bubble-primary"
163
- else :
171
+ elif kind == "assistant" :
164
172
bubble_class = "chat-bubble-secondary"
173
+ else :
174
+ bubble_class = "chat-bubble-other" # Default to warning if kind is unknown
165
175
chat_class = "chat-end" if kind == "user" else 'chat-start'
166
176
return Div (cls = f"chat { chat_class } " )(
167
177
# No content in the Div directly, it will be filled by JS
@@ -314,8 +324,11 @@ def index():
314
324
ChatInput (),
315
325
Button ("Send" , cls = "btn btn-primary" , id = "send-button" , disabled = True , onclick = "sendMessage()" ),
316
326
Button ("Clear" , cls = "btn btn-secondary" , id = "clear-button" ,
317
- hx_post = "/clear_chat" , hx_target = "#chatlist" , hx_swap = "innerHTML" ,
318
- hx_include = "#msg-input, #select-option" , hx_trigger = "click" ),
327
+ hx_post = "/clear_chat" ,
328
+ # hx_target="#chatlist",
329
+ # hx_swap="innerHTML",
330
+ hx_include = "#msg-input, #select-option" ,
331
+ hx_trigger = "click" ),
319
332
)
320
333
),
321
334
Div (cls = "flex space-x-2 mt-2" , id = "info-message" )(
@@ -328,9 +341,20 @@ def index():
328
341
def clear_chat_history (msg :str = "" , selected_option :str = "" ): # Parameters to receive from hx_include
329
342
chatbot .clear_history ()
330
343
# Return empty Div for chatlist to clear it, and an empty input for OOB swap
331
- logger .info ("Chat history cleared" )
332
- return (Div (id = "chatlist" , cls = "chat-box" ), # This clears the chat list, keeping its class
333
- ChatInput (), InfoMessageDiv ("Chat history cleared!" , kind = "info" )) # Updates the info message
344
+ logger .info ("LLM chat history cleared" )
345
+ if config ["clear_page" ]:
346
+ logger .info ("Clearhing web page" )
347
+ # If clear_page is set, return an empty Div to clear the chat list
348
+ return (Div (id = "chatlist" , cls = "chat-box" ), # This clears the chat list, keeping its class
349
+ ChatInput (), InfoMessageDiv ("Chat history cleared!" , kind = "info" ))
350
+ else :
351
+ # Do not clear the chat list, just add an info that the LLM chat history was cleared
352
+ logger .info ("Chat history cleared, but keeping the chat page" )
353
+ return (
354
+ Script ("setAppState('ready');" ), # Reset the app state to ready
355
+ ChatMessage ("LLM chat history has been reset!" , "other" ), # The chatbot's response
356
+ ChatInput (), InfoMessageDiv ("" , "info" )) # And clear the input field via an OOB swap
357
+
334
358
335
359
# Handle the form submission
336
360
@app .post
@@ -360,6 +384,7 @@ def send(msg:str, selected_option:str=""):
360
384
return (
361
385
Script ("setAppState('ready');" ), # Reset the app state to ready
362
386
ChatInput (), InfoMessageDiv (info_txt , kind = "error" ))
387
+ msg = msg .strip () # Ensure no leading/trailing whitespace
363
388
if msg == "help" or msg == "?" or msg == "?help" :
364
389
chatmsg = """
365
390
Available commands:
@@ -375,8 +400,18 @@ def send(msg:str, selected_option:str=""):
375
400
chatbot .clear_history ()
376
401
# Return empty Div for chatlist to clear it, and an empty input for OOB swap
377
402
logger .info ("Chat history cleared" )
378
- return (Div (id = "chatlist" , cls = "chat-box" ), # This clears the chat list, keeping its class
379
- ChatInput (), InfoMessageDiv ("Chat history cleared!" , kind = "info" )) # Updates the info message
403
+ if config ["clear_page" ]:
404
+ logger .info ("Clearing web page" )
405
+ # If clear_page is set, return an empty Div to clear the chat list
406
+ return (Script ("setAppState('ready');" ),
407
+ Div (id = "chatlist" , cls = "chat-box" ), # This clears the chat list, keeping its class
408
+ ChatInput (), InfoMessageDiv ("Chat history cleared!" , kind = "info" ))
409
+ else :
410
+ # Do not clear the chat list, just add an info that the chat history was cleared
411
+ logger .info ("Chat history cleared, but keeping the chat page" )
412
+ return ( Script ("setAppState('ready');" ),
413
+ ChatMessage ("LLM chat history cleared" , "other" ),
414
+ ChatInput (), InfoMessageDiv ("Chat history cleared!" , kind = "info" )) # Updates the info message
380
415
elif msg == "?history" :
381
416
# Show the history of all user requests
382
417
history = chatbot .history
0 commit comments