OllamaInterface/RunOllamaServerDialog.py

Tue, 10 Dec 2024 15:48:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 10 Dec 2024 15:48:48 +0100
changeset 67
3c2bcbf7eeaf
parent 47
178d52749f25
permissions
-rw-r--r--

Updated copyright for 2025.

7
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
67
3c2bcbf7eeaf Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 47
diff changeset
3 # Copyright (c) 2020 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
7
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to run the ollama server locally.
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt6.QtCore import QProcess, Qt, QTimer, pyqtSignal, pyqtSlot
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from eric7.EricWidgets import EricMessageBox
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_RunOllamaServerDialog import Ui_RunOllamaServerDialog
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class RunOllamaServerDialog(QDialog, Ui_RunOllamaServerDialog):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing a dialog to run the ollama server locally.
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 @signal serverStarted() emitted after the start of the 'ollama' server
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 @signal serverStopped() emitted after the 'ollama' server was stopped
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 serverStarted = pyqtSignal()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 serverStopped = pyqtSignal()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 def __init__(self, ollamaClient, plugin, parent=None):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param ollamaClient reference to the 'ollama' client object
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @type OllamaClient
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param plugin reference to the plug-in object
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @type PluginOllamaInterface
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param parent reference to the parent widget
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @type QWidget
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 super().__init__(parent)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.setupUi(self)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.__plugin = plugin
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__ui = parent
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.__client = ollamaClient
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.__process = None
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__defaultTextFormat = self.outputEdit.currentCharFormat()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def startServer(self):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Public method to start the ollama server process.
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @return flag indicating success
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @rtype bool
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 env = self.__ui.prepareServerRuntimeEnvironment()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.__process = QProcess()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.__process.setProcessEnvironment(env)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.__process.setProcessChannelMode(QProcess.ProcessChannelMode.MergedChannels)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.__process.readyReadStandardOutput.connect(self.__readStdOut)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__process.finished.connect(self.__processFinished)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.outputEdit.clear()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 command = "ollama"
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 args = ["serve"]
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.__process.start(command, args)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 ok = self.__process.waitForStarted(10000)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 if not ok:
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 EricMessageBox.critical(
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 None,
8
3118d16e526e Implemented some more menu actions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
79 self.tr("Run Local 'ollama' Server"),
20
8cb7bfe07e15 Did the German translations and corrected some typing issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 14
diff changeset
80 self.tr("""The local 'ollama' server process could not be started."""),
7
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 )
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 else:
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 False
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 )
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.stopServerButton.setEnabled(True)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.stopServerButton.setDefault(True)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.serverStarted.emit()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 return ok
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 def closeEvent(self, evt):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 Protected method handling a close event.
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @param evt reference to the close event
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @type QCloseEvent
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.on_stopServerButton_clicked()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 evt.accept()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 @pyqtSlot()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 def __readStdOut(self):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 Private slot to add the server process output to the output pane.
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if self.__process is not None:
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 out = str(self.__process.readAllStandardOutput(), "utf-8")
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.outputEdit.insertPlainText(out)
14
08932ee12a69 Ensure local server output pane is scrolled to the last line when new data was added.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8
diff changeset
111 self.outputEdit.ensureCursorVisible()
7
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @pyqtSlot()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 def __processFinished(self):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 Private slot handling the finishing of the server process.
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 if (
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.__process is not None
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 and self.__process.state() != QProcess.ProcessState.NotRunning
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 ):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 self.__process.terminate()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 QTimer.singleShot(2000, self.__process.kill)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__process.waitForFinished(3000)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.__process = None
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 self.stopServerButton.setEnabled(False)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setFocus(
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 Qt.FocusReason.OtherFocusReason
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 )
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 self.serverStopped.emit()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 @pyqtSlot()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 def on_stopServerButton_clicked(self):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 Private slot to stop the running server.
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 """
8
3118d16e526e Implemented some more menu actions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
142 if self.__process is not None:
3118d16e526e Implemented some more menu actions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
143 self.__process.terminate()
7
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 @pyqtSlot()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def on_restartServerButton_clicked(self):
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 Private slot to re-start the ollama server.
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 """
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 # step 1: stop the current server
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 if self.__process is not None:
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 self.on_stopServerButton_clicked()
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
eb1dec15b2f0 Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 # step 2: start a new server
47
178d52749f25 Fixed a bug in the Run Server dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
155 QTimer.singleShot(1000, self.startServer)

eric ide

mercurial