Added interrupt 'stop' button

This commit is contained in:
jeffser 2024-05-19 18:29:20 -06:00
parent 0096346b0c
commit 15fdd0ae1a
2 changed files with 57 additions and 35 deletions

View File

@ -294,6 +294,9 @@ class AlpacaWindow(Adw.ApplicationWindow):
self.bot_message_box = None
def update_bot_message(self, data):
if self.bot_message is None:
self.save_history()
sys.exit()
vadjustment = self.chat_window.get_vadjustment()
if vadjustment.get_value() + 50 >= vadjustment.get_upper() - vadjustment.get_page_size():
GLib.idle_add(vadjustment.set_value, vadjustment.get_upper())
@ -318,10 +321,12 @@ class AlpacaWindow(Adw.ApplicationWindow):
def run_message(self, messages, model):
response = stream_post(f"{self.ollama_url}/api/chat", data=json.dumps({"model": model, "messages": messages}), callback=self.update_bot_message)
GLib.idle_add(self.add_code_blocks)
GLib.idle_add(self.send_button.set_sensitive, True)
GLib.idle_add(self.send_button.set_css_classes, ["suggested-action"])
GLib.idle_add(self.send_button.get_child().set_label, "Send")
GLib.idle_add(self.send_button.get_child().set_icon_name, "send-to-symbolic")
GLib.idle_add(self.chat_list_box.set_sensitive, True)
GLib.idle_add(self.add_chat_button.set_sensitive, True)
GLib.idle_add(self.image_button.set_sensitive, True)
if self.verify_if_image_can_be_used(): GLib.idle_add(self.image_button.set_sensitive, True)
GLib.idle_add(self.image_button.set_css_classes, [])
GLib.idle_add(self.image_button.get_child().set_icon_name, "image-x-generic-symbolic")
self.attached_image = {"path": None, "base64": None}
@ -331,6 +336,22 @@ class AlpacaWindow(Adw.ApplicationWindow):
GLib.idle_add(self.show_connection_dialog, True)
def send_message(self, button=None):
if button and self.bot_message: #STOP BUTTON
if self.loading_spinner: self.chat_container.remove(self.loading_spinner)
if self.verify_if_image_can_be_used(): self.image_button.set_sensitive(True)
self.image_button.set_css_classes([])
self.image_button.get_child().set_icon_name("image-x-generic-symbolic")
self.attached_image = {"path": None, "base64": None}
self.chat_list_box.set_sensitive(True)
self.add_chat_button.set_sensitive(True)
self.message_text_view.set_sensitive(True)
self.send_button.set_css_classes(["suggested-action"])
self.send_button.get_child().set_label("Send")
self.send_button.get_child().set_icon_name("send-to-symbolic")
self.bot_message = None
self.bot_message_box = None
self.bot_message_view = None
else:
if not self.message_text_view.get_buffer().get_text(self.message_text_view.get_buffer().get_start_iter(), self.message_text_view.get_buffer().get_end_iter(), False): return
current_model = self.model_drop_down.get_selected_item()
if current_model is None:
@ -350,7 +371,9 @@ class AlpacaWindow(Adw.ApplicationWindow):
if self.verify_if_image_can_be_used() and self.attached_image["base64"] is not None:
data["messages"][-1]["images"] = [self.attached_image["base64"]]
self.message_text_view.set_sensitive(False)
self.send_button.set_sensitive(False)
self.send_button.set_css_classes(["destructive-action"])
self.send_button.get_child().set_label("Stop")
self.send_button.get_child().set_icon_name("edit-delete-symbolic")
self.chat_list_box.set_sensitive(False)
self.add_chat_button.set_sensitive(False)
self.image_button.set_sensitive(False)

View File

@ -4,7 +4,7 @@
<requires lib="Adw" version="1.0"/>
<template class="AlpacaWindow" parent="AdwApplicationWindow">
<property name="resizable">True</property>
<property name="width-request">360</property>
<property name="width-request">350</property>
<property name="height-request">500</property>
<property name="default-width">1300</property>
<property name="default-height">800</property>
@ -81,7 +81,6 @@
<property name="hexpand">true</property>
<child>
<object class="GtkListBox" id="chat_list_box">
<property name="selection-mode">single</property>
<style>
<class name="boxed-list"/>