Thu, 08 Aug 2024 18:33:49 +0200
Implemented a menu, dialog and actions to start a local 'ollama' server with the capability to monitor its log output.
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 | |
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
|
3 | # Copyright (c) 2020 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
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, |
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
|
79 | self.tr("Run Local 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
|
80 | self.tr("""The loacl ollama server process could not be started."""), |
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 | self.restartServerButton.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
|
89 | |
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 | 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
|
91 | |
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 | 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
|
93 | |
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 | 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
|
95 | """ |
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 | 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
|
97 | |
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 | @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
|
99 | @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
|
100 | """ |
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 | 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
|
102 | 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
|
103 | |
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 | @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
|
105 | 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
|
106 | """ |
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 | 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
|
108 | """ |
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 | 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
|
110 | 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
|
111 | self.outputEdit.insertPlainText(out) |
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.restartServerButton.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
|
129 | 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
|
130 | 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
|
131 | 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
|
132 | 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
|
133 | 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
|
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 | |
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 | 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
|
137 | |
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 | @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
|
139 | 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
|
140 | """ |
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 | 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
|
142 | """ |
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
|
143 | 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
|
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 |
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
|
155 | self.startServer() |