81 self.historyScrollWidget.setLayout(self.__chatHistoryLayout) |
81 self.historyScrollWidget.setLayout(self.__chatHistoryLayout) |
82 self.__chatHistoryLayout.addStretch(1) |
82 self.__chatHistoryLayout.addStretch(1) |
83 |
83 |
84 self.mainSplitter.setSizes([200, 2000, 100]) |
84 self.mainSplitter.setSizes([200, 2000, 100]) |
85 |
85 |
86 self.newChatButton.setEnabled(False) |
|
87 self.__handleServerStateChanged(False) |
|
88 |
|
89 self.__pullProgressDialog = None |
86 self.__pullProgressDialog = None |
90 self.__pulling = False |
87 self.__pulling = False |
91 |
88 |
92 self.__localServerDialog = None |
89 self.__localServerDialog = None |
93 self.__localServerProcess = None |
90 self.__localServerProcess = None |
94 |
91 |
95 self.__availableModels = [] |
92 self.__availableModels = [] |
96 |
93 |
|
94 self.__initOllamaMenu() |
|
95 |
|
96 self.newChatButton.setEnabled(False) |
|
97 self.__handleServerStateChanged(False, "") |
|
98 |
97 self.__connectClient() |
99 self.__connectClient() |
98 |
|
99 self.__initOllamaMenu() |
|
100 |
100 |
101 self.sendButton.clicked.connect(self.__sendMessage) |
101 self.sendButton.clicked.connect(self.__sendMessage) |
102 |
102 |
103 self.__loadHistory() |
103 self.__loadHistory() |
104 self.__updateMessageEditState() |
104 self.__updateMessageEditState() |
116 self.__client.pullError.connect(self.__handlePullError) |
116 self.__client.pullError.connect(self.__handlePullError) |
117 |
117 |
118 self.__client.errorOccurred.connect(self.__handleClientError) |
118 self.__client.errorOccurred.connect(self.__handleClientError) |
119 self.__client.finished.connect(self.__handleClientFinished) |
119 self.__client.finished.connect(self.__handleClientFinished) |
120 |
120 |
121 @pyqtSlot(bool) |
121 @pyqtSlot() |
122 def __handleServerStateChanged(self, ok): |
122 def __finishSetup(self): |
|
123 """ |
|
124 Private slot to finish the UI setup. |
|
125 """ |
|
126 self.__client.version() |
|
127 self.__client.list() |
|
128 |
|
129 @pyqtSlot() |
|
130 def on_reloadModelsButton_clicked(self): |
|
131 """ |
|
132 Private slot to reload the list of available models. |
|
133 """ |
|
134 self.__finishSetup() |
|
135 |
|
136 @pyqtSlot(str) |
|
137 def on_modelComboBox_currentTextChanged(self, model): |
|
138 """ |
|
139 Private slot handling the selection of a model. |
|
140 |
|
141 @param model name of the selected model |
|
142 @type str |
|
143 """ |
|
144 self.newChatButton.setEnabled(bool(model)) |
|
145 |
|
146 def __setEnabledState(self, enable): |
|
147 """ |
|
148 Private method to set the enabled state of the main widget. |
|
149 |
|
150 @param enable enabled state |
|
151 @type bool |
|
152 """ |
|
153 for widget in ( |
|
154 self.reloadModelsButton, |
|
155 self.modelComboBox, |
|
156 self.newChatButton, |
|
157 self.mainSplitter, |
|
158 self.__modelMenuAct, |
|
159 ): |
|
160 widget.setEnabled(enable) |
|
161 |
|
162 ############################################################################ |
|
163 ## Methods handling signals from the 'ollama' client. |
|
164 ############################################################################ |
|
165 |
|
166 @pyqtSlot(bool, str) |
|
167 def __handleServerStateChanged(self, ok, msg): |
123 """ |
168 """ |
124 Private slot handling a change in the 'ollama' server responsiveness. |
169 Private slot handling a change in the 'ollama' server responsiveness. |
125 |
170 |
126 @param ok flag indicating a responsive 'ollama' server |
171 @param ok flag indicating a responsive 'ollama' server |
127 @type bool |
172 @type bool |
|
173 @param msg status message |
|
174 @type str |
128 """ |
175 """ |
129 if ok: |
176 if ok: |
130 self.__finishSetup() |
177 self.__finishSetup() |
131 else: |
178 else: |
132 self.ollamaVersionLabel.setText( |
179 self.ollamaVersionLabel.setText(msg) |
133 self.tr("<b>Error: The configured server is not responding.</b>") |
180 self.__setEnabledState(ok) |
134 ) |
|
135 self.setEnabled(ok) |
|
136 |
|
137 @pyqtSlot() |
|
138 def __finishSetup(self): |
|
139 """ |
|
140 Private slot to finish the UI setup. |
|
141 """ |
|
142 self.__client.version() |
|
143 self.__client.list() |
|
144 |
|
145 @pyqtSlot() |
|
146 def on_reloadModelsButton_clicked(self): |
|
147 """ |
|
148 Private slot to reload the list of available models. |
|
149 """ |
|
150 self.__finishSetup() |
|
151 |
|
152 @pyqtSlot(str) |
|
153 def on_modelComboBox_currentTextChanged(self, model): |
|
154 """ |
|
155 Private slot handling the selection of a model. |
|
156 |
|
157 @param model name of the selected model |
|
158 @type str |
|
159 """ |
|
160 self.newChatButton.setEnabled(bool(model)) |
|
161 |
|
162 ############################################################################ |
|
163 ## Methods handling signals from the 'ollama' client. |
|
164 ############################################################################ |
|
165 |
181 |
166 @pyqtSlot(str) |
182 @pyqtSlot(str) |
167 def __setHeaderLabel(self, version): |
183 def __setHeaderLabel(self, version): |
168 """ |
184 """ |
169 Private slot to receive the 'ollama' server version and set the header. |
185 Private slot to receive the 'ollama' server version and set the header. |
665 ################################################################### |
681 ################################################################### |
666 |
682 |
667 self.__ollamaMenu = QMenu() |
683 self.__ollamaMenu = QMenu() |
668 self.__ollamaMenu.addMenu(self.__chatHistoryMenu) |
684 self.__ollamaMenu.addMenu(self.__chatHistoryMenu) |
669 self.__ollamaMenu.addSeparator() |
685 self.__ollamaMenu.addSeparator() |
670 self.__ollamaMenu.addMenu(self.__modelMenu) |
686 self.__modelMenuAct = self.__ollamaMenu.addMenu(self.__modelMenu) |
671 self.__ollamaMenu.addSeparator() |
687 self.__ollamaMenu.addSeparator() |
672 self.__ollamaMenu.addMenu(self.__localServerMenu) |
688 self.__ollamaMenu.addMenu(self.__localServerMenu) |
673 self.__ollamaMenu.addSeparator() |
689 self.__ollamaMenu.addSeparator() |
674 self.__ollamaMenu.addAction(self.tr("Configure..."), self.__ollamaConfigure) |
690 self.__ollamaMenu.addAction(self.tr("Configure..."), self.__ollamaConfigure) |
675 |
691 |
813 def __serverStarted(self): |
829 def __serverStarted(self): |
814 """ |
830 """ |
815 Private slot to handle the start of a local server. |
831 Private slot to handle the start of a local server. |
816 """ |
832 """ |
817 self.__client.setMode(True) |
833 self.__client.setMode(True) |
818 self.on_reloadModelsButton_clicked() |
|
819 |
834 |
820 @pyqtSlot() |
835 @pyqtSlot() |
821 def __serverStopped(self): |
836 def __serverStopped(self): |
822 """ |
837 """ |
823 Private slot to handle the stopping of a local server. |
838 Private slot to handle the stopping of a local server. |
824 """ |
839 """ |
825 self.__client.setMode(False) |
840 self.__client.setMode(False) |
826 self.on_reloadModelsButton_clicked() |
|
827 |
841 |
828 @pyqtSlot() |
842 @pyqtSlot() |
829 def __serverDialogClosed(self): |
843 def __serverDialogClosed(self): |
830 """ |
844 """ |
831 Private slot handling the closing of the local server dialog. |
845 Private slot handling the closing of the local server dialog. |