@@ -42,7 +42,8 @@ def append_response_chunk(self, text):
4242 def on_response_complete (self , tab , model_name ):
4343 msg = {
4444 "role" : "assistant" ,
45- "content" : self .current_response_full_text
45+ "content" : self .current_response_full_text ,
46+ "model" : model_name
4647 }
4748 if self .current_thinking_full_text :
4849 msg ["thinking_content" ] = self .current_thinking_full_text
@@ -62,6 +63,15 @@ def on_response_complete(self, tab, model_name):
6263 thinking_val = getattr (self , 'current_thinking_val' , None )
6364 if thinking_val is not None :
6465 options ['thinking_val' ] = thinking_val
66+
67+ # Save "logprobs" setting if present
68+ logprobs_val = getattr (self , 'current_logprobs' , None )
69+ if logprobs_val is not None :
70+ options ['logprobs' ] = logprobs_val
71+
72+ top_logprobs_val = getattr (self , 'current_top_logprobs' , None )
73+ if top_logprobs_val is not None :
74+ options ['top_logprobs' ] = top_logprobs_val
6575
6676 self .storage .save_chat (self .chat_id , self .history , model = model_name , options = options , system = system )
6777
@@ -84,6 +94,8 @@ def process(self, tab, **kwargs):
8494 self .current_options = kwargs .get ('options' )
8595 self .current_system = system
8696 self .current_thinking_val = kwargs .get ('thinking' )
97+ self .current_logprobs = kwargs .get ('logprobs' )
98+ self .current_top_logprobs = kwargs .get ('top_logprobs' )
8799
88100 # Build messages
89101 messages = []
@@ -94,7 +106,10 @@ def process(self, tab, **kwargs):
94106 messages .append ({"role" : "user" , "content" : prompt })
95107
96108 # Update our history with the user's message now
97- self .history .append ({"role" : "user" , "content" : prompt })
109+ msg = {"role" : "user" , "content" : prompt }
110+ if kwargs .get ('images' ):
111+ msg ['images' ] = kwargs ['images' ]
112+ self .history .append (msg )
98113
99114 # Reset current response accumulator
100115 self .current_response_full_text = ""
@@ -380,9 +395,6 @@ def on_send_clicked(self, widget):
380395 truncated = prompt [:20 ] + "..." if len (prompt ) > 20 else prompt
381396 self .tab_label .set_label (truncated )
382397
383- self .add_message (prompt , sender = _ ("You" ))
384- self .entry .set_text ("" )
385-
386398 # Get selected model
387399 selected_item = self .model_dropdown .get_selected_item ()
388400 model_name = "llama3" # Fallback
@@ -404,13 +416,16 @@ def on_send_clicked(self, widget):
404416 # Clear image after reading
405417 self .on_clear_image_clicked (None )
406418
419+ self .add_message (prompt , sender = _ ("You" ), images = images )
420+ self .entry .set_text ("" )
421+
407422 thread = threading .Thread (target = self .process_request , args = (prompt , model_name , images ))
408423 thread .daemon = True
409424 thread .start ()
410425
411- def add_message (self , text , sender = "System" ):
426+ def add_message (self , text , sender = "System" , images = None ):
412427 if sender == _ ("You" ):
413- bubble = UserBubble (text )
428+ bubble = UserBubble (text , images = images )
414429 self .chat_box .append (bubble )
415430 else :
416431 # System message or error
@@ -529,10 +544,12 @@ def load_initial_history(self, history):
529544 thinking_content = msg .get ('thinking_content' )
530545
531546 if role == 'user' :
532- self .add_message (content , sender = _ ("You" ))
547+ images = msg .get ('images' )
548+ self .add_message (content , sender = _ ("You" ), images = images )
533549 elif role == 'assistant' :
534550 # Reconstruct with AiBubble
535- bubble = AiBubble (model_name = "Assistant" )
551+ model_name = msg .get ('model' , 'Assistant' )
552+ bubble = AiBubble (model_name = model_name )
536553 if thinking_content :
537554 bubble .append_thinking (thinking_content )
538555 bubble .append_text (content )
@@ -611,6 +628,12 @@ def load_chat_settings(self, chat_data):
611628 if 'stats' in options :
612629 self .stats_check .set_active (options ['stats' ])
613630
631+ # Logprobs
632+ if 'logprobs' in options :
633+ self .logprobs_check .set_active (options ['logprobs' ])
634+ if 'top_logprobs' in options and options ['top_logprobs' ] is not None :
635+ self .top_logprobs_entry .set_text (str (options ['top_logprobs' ]))
636+
614637 def process_request (self , prompt , model_name , images = None ):
615638 host = self .host_entry .get_text ()
616639
0 commit comments