From a22b7d13ac9c6a5f600c97ec1008cce21464cbd6 Mon Sep 17 00:00:00 2001 From: Emil Kosz Date: Mon, 23 Mar 2026 05:29:18 +0100 Subject: [PATCH] Last commit before UI redesign --- TODO.org | 5 ++++- chat_session.py | 28 +++++++++++++++++++++++++ main.py | 25 ++++++++++++++++++++-- pyllama.cmb | 2 +- pyllama.ui | 56 ++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 chat_session.py diff --git a/TODO.org b/TODO.org index a4db6aa..9de86ad 100644 --- a/TODO.org +++ b/TODO.org @@ -1 +1,4 @@ -* TODO Make it possible to stop the model from generating +* DONE Make it possible to stop the model from generating +* TODO Add system prompt configuration +* TODO Add multiple chats +* TODO Make a ChatSession class with all chat data diff --git a/chat_session.py b/chat_session.py new file mode 100644 index 0000000..008acf5 --- /dev/null +++ b/chat_session.py @@ -0,0 +1,28 @@ +class ChatSettings(): + def __init__(self): + self.num_gpu: int = 15 + self.low_vram: bool = False + self.num_thread: int = 0 + self.temperature: int = 1.0 + self.system_prompt: str = None + + def convert_to_ollama(self): + return { + "num_gpu": self.num_gpu, + "low_vram": self.low_vram, + "num_thread": self.num_thread, + "temperature": self.temperature, + } + +class ChatSession(): + def __init__(self, model_name): + self.model_name: str = model_name + self.history = [] + self.settings: ChatSettings = ChatSettings() + + def push_history(self, text: str, role: str = "user"): + if not self.history or self.history[-1]["role"] != role: + self.history.append({"role": role, "content": text}) + else: + self.history[-1]["content"] += text + diff --git a/main.py b/main.py index 77c41d0..b6359a2 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ gi.require_version("Gtk", "4.0") from gi.repository import GLib, Gtk, Gdk import util +from chat_session import ChatSession @Gtk.Template(filename="pyllama.ui") class PyLlamaWindow(Gtk.ApplicationWindow): @@ -18,6 +19,8 @@ class PyLlamaWindow(Gtk.ApplicationWindow): cancel_button = Gtk.Template.Child("cancel_button") gpu_layers_spin = Gtk.Template.Child("gpu_layers_spin") low_vram_switch = Gtk.Template.Child("low_vram_switch") + threads_spin = Gtk.Template.Child("threads_spin") + temperature_spin = Gtk.Template.Child("temperature_spin") def __init__(self, application=None, title=None): super().__init__(application=application, title=title) @@ -97,9 +100,11 @@ class PyLlamaWindow(Gtk.ApplicationWindow): options = { "num_gpu": self.gpu_layers_spin.get_value_as_int(), - "low_vram": self.low_vram_switch.get_state() + "low_vram": self.low_vram_switch.get_state(), + "num_thread": self.threads_spin.get_value_as_int(), + "temperature": self.temperature_spin.get_value_as_int() } - + async def task(): await app.send_prompt(model, options) @@ -112,6 +117,22 @@ class PyLlamaWindow(Gtk.ApplicationWindow): def cancel_button_clicked(self, *args): app = self.get_application() app.stop_generation() + + @Gtk.Template.Callback() + def gpu_layers_spin_changed(self, *args): + pass + + @Gtk.Template.Callback() + def low_vram_switch_set(self, *args): + pass + + @Gtk.Template.Callback() + def threads_spin_changed(self, *args): + pass + + @Gtk.Template.Callback() + def temperature_spin_changed(self, *args): + pass class PyLlama(Gtk.Application): def __init__(self): diff --git a/pyllama.cmb b/pyllama.cmb index f53c030..de4fd39 100644 --- a/pyllama.cmb +++ b/pyllama.cmb @@ -2,5 +2,5 @@ - + diff --git a/pyllama.ui b/pyllama.ui index 48f35da..2015c31 100644 --- a/pyllama.ui +++ b/pyllama.ui @@ -46,7 +46,7 @@ along with this program. If not, see . --> 12 horizontal False - 6 + 0 GPU layers @@ -69,6 +69,7 @@ along with this program. If not, see . --> end True 25.0 + 1 0 @@ -90,12 +91,65 @@ along with this program. If not, see . --> False False False + 1 1 + + + No. threads + + 0 + 2 + + + + + + + + 0.0 + 1.0 + 32.0 + + + + + 1 + 2 + + + + + + Temperature + + 0 + 3 + + + + + + + + 0.01 + 0.01 + 5.0 + + + 2 + 1.0 + + + 1 + 3 + + +