Last commit before UI redesign
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@ gi.require_version("Gtk", "4.0")
|
|||||||
from gi.repository import GLib, Gtk, Gdk
|
from gi.repository import GLib, Gtk, Gdk
|
||||||
|
|
||||||
import util
|
import util
|
||||||
|
from chat_session import ChatSession
|
||||||
|
|
||||||
@Gtk.Template(filename="pyllama.ui")
|
@Gtk.Template(filename="pyllama.ui")
|
||||||
class PyLlamaWindow(Gtk.ApplicationWindow):
|
class PyLlamaWindow(Gtk.ApplicationWindow):
|
||||||
@@ -18,6 +19,8 @@ class PyLlamaWindow(Gtk.ApplicationWindow):
|
|||||||
cancel_button = Gtk.Template.Child("cancel_button")
|
cancel_button = Gtk.Template.Child("cancel_button")
|
||||||
gpu_layers_spin = Gtk.Template.Child("gpu_layers_spin")
|
gpu_layers_spin = Gtk.Template.Child("gpu_layers_spin")
|
||||||
low_vram_switch = Gtk.Template.Child("low_vram_switch")
|
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):
|
def __init__(self, application=None, title=None):
|
||||||
super().__init__(application=application, title=title)
|
super().__init__(application=application, title=title)
|
||||||
@@ -97,9 +100,11 @@ class PyLlamaWindow(Gtk.ApplicationWindow):
|
|||||||
|
|
||||||
options = {
|
options = {
|
||||||
"num_gpu": self.gpu_layers_spin.get_value_as_int(),
|
"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():
|
async def task():
|
||||||
await app.send_prompt(model, options)
|
await app.send_prompt(model, options)
|
||||||
|
|
||||||
@@ -112,6 +117,22 @@ class PyLlamaWindow(Gtk.ApplicationWindow):
|
|||||||
def cancel_button_clicked(self, *args):
|
def cancel_button_clicked(self, *args):
|
||||||
app = self.get_application()
|
app = self.get_application()
|
||||||
app.stop_generation()
|
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):
|
class PyLlama(Gtk.Application):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
+1
-1
@@ -2,5 +2,5 @@
|
|||||||
<!DOCTYPE cambalache-project SYSTEM "cambalache-project.dtd">
|
<!DOCTYPE cambalache-project SYSTEM "cambalache-project.dtd">
|
||||||
<!-- Created with Cambalache 0.99.3 -->
|
<!-- Created with Cambalache 0.99.3 -->
|
||||||
<cambalache-project version="0.96.0" target_tk="gtk-4.0">
|
<cambalache-project version="0.96.0" target_tk="gtk-4.0">
|
||||||
<ui template-class="main_window" filename="pyllama.ui" sha256="37b3c167cb000ca8bb319efb8748b43b8bdde99fab64736fa1726c7f73e77327"/>
|
<ui template-class="main_window" filename="pyllama.ui" sha256="94ec27105472f558635f6f113a677ebf9700f7342a6a27dbc1c55de636efdd3f"/>
|
||||||
</cambalache-project>
|
</cambalache-project>
|
||||||
|
|||||||
+55
-1
@@ -46,7 +46,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. -->
|
|||||||
<property name="column-spacing">12</property>
|
<property name="column-spacing">12</property>
|
||||||
<property name="orientation">horizontal</property>
|
<property name="orientation">horizontal</property>
|
||||||
<property name="row-homogeneous">False</property>
|
<property name="row-homogeneous">False</property>
|
||||||
<property name="row-spacing">6</property>
|
<property name="row-spacing">0</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel">
|
<object class="GtkLabel">
|
||||||
<property name="label">GPU layers</property>
|
<property name="label">GPU layers</property>
|
||||||
@@ -69,6 +69,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. -->
|
|||||||
<property name="halign">end</property>
|
<property name="halign">end</property>
|
||||||
<property name="numeric">True</property>
|
<property name="numeric">True</property>
|
||||||
<property name="value">25.0</property>
|
<property name="value">25.0</property>
|
||||||
|
<signal name="change-value" handler="gpu_layers_spin_changed"/>
|
||||||
<layout>
|
<layout>
|
||||||
<property name="column">1</property>
|
<property name="column">1</property>
|
||||||
<property name="row">0</property>
|
<property name="row">0</property>
|
||||||
@@ -90,12 +91,65 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. -->
|
|||||||
<property name="hexpand">False</property>
|
<property name="hexpand">False</property>
|
||||||
<property name="hexpand-set">False</property>
|
<property name="hexpand-set">False</property>
|
||||||
<property name="receives-default">False</property>
|
<property name="receives-default">False</property>
|
||||||
|
<signal name="state-set" handler="low_vram_switch_set"/>
|
||||||
<layout>
|
<layout>
|
||||||
<property name="column">1</property>
|
<property name="column">1</property>
|
||||||
<property name="row">1</property>
|
<property name="row">1</property>
|
||||||
</layout>
|
</layout>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="label">No. threads</property>
|
||||||
|
<layout>
|
||||||
|
<property name="column">0</property>
|
||||||
|
<property name="row">2</property>
|
||||||
|
</layout>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSpinButton" id="threads_spin">
|
||||||
|
<property name="adjustment">
|
||||||
|
<object class="GtkAdjustment">
|
||||||
|
<property name="lower">0.0</property>
|
||||||
|
<property name="step-increment">1.0</property>
|
||||||
|
<property name="upper">32.0</property>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
<signal name="change-value" handler="threads_spin_changed"/>
|
||||||
|
<layout>
|
||||||
|
<property name="column">1</property>
|
||||||
|
<property name="row">2</property>
|
||||||
|
</layout>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="label">Temperature</property>
|
||||||
|
<layout>
|
||||||
|
<property name="column">0</property>
|
||||||
|
<property name="row">3</property>
|
||||||
|
</layout>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSpinButton" id="temperature_spin">
|
||||||
|
<property name="adjustment">
|
||||||
|
<object class="GtkAdjustment">
|
||||||
|
<property name="lower">0.01</property>
|
||||||
|
<property name="step-increment">0.01</property>
|
||||||
|
<property name="upper">5.0</property>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
<property name="digits">2</property>
|
||||||
|
<property name="value">1.0</property>
|
||||||
|
<signal name="change-value" handler="temperature_spin_changed"/>
|
||||||
|
<layout>
|
||||||
|
<property name="column">1</property>
|
||||||
|
<property name="row">3</property>
|
||||||
|
</layout>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</property>
|
</property>
|
||||||
</object>
|
</object>
|
||||||
|
|||||||
Reference in New Issue
Block a user