diff -r 8cb7bfe07e15 -r 22245a10b118 OllamaInterface/OllamaWidget.py --- a/OllamaInterface/OllamaWidget.py Fri Aug 30 12:04:28 2024 +0200 +++ b/OllamaInterface/OllamaWidget.py Fri Aug 30 15:22:47 2024 +0200 @@ -7,6 +7,7 @@ Module implementing the main ollama interface widget. """ +import contextlib import json import os @@ -27,7 +28,7 @@ from eric7.EricWidgets.EricApplication import ericApp from eric7.EricWidgets.EricListSelectionDialog import EricListSelectionDialog -from .OllamaChatWidget import OllamaChatWidget +from .OllamaChatWidget import OllamaChatDialog, OllamaChatWidget from .OllamaClient import OllamaClient from .OllamaHistoryWidget import OllamaHistoryWidget from .Ui_OllamaWidget import Ui_OllamaWidget @@ -90,6 +91,7 @@ self.__localServerProcess = None self.__availableModels = [] + self.__chatHistoryDialogs = {} self.__initOllamaMenu() @@ -249,6 +251,7 @@ history.deleteChatHistory.connect(self.__deleteHistory) history.dataChanged.connect(self.__saveHistory) history.newChatWithHistory.connect(self.__newChatWithHistory) + history.viewChatHistory.connect(self.__viewChatHistory) self.__saveHistory() @@ -515,6 +518,46 @@ self.__updateMessageEditState() self.messageEdit.setFocus(Qt.FocusReason.OtherFocusReason) + @pyqtSlot(str) + def __viewChatHistory(self, hid): + """ + Private slot to show the chat history in a separate window. + + @param hid ID of the history to be shown + @type str + """ + historyWidget = self.__findHistoryWidget(hid) + if historyWidget is None: + # Oops, just ignore it + return + + try: + dlg = self.__chatHistoryDialogs[hid] + except KeyError: + dlg = OllamaChatDialog( + hid=hid, + title=historyWidget.getTitle(), + model=historyWidget.getModel(), + parent=self, + ) + dlg.rejected.connect(lambda: self.__chatHistoryDialogClosed(dlg)) + self.__chatHistoryDialogs[hid] = dlg + + dlg.setHistory(historyWidget.getMessages()) + dlg.show() + dlg.raise_() + + def __chatHistoryDialogClosed(self, dialog): + """ + Private method to handle the closing of a chat history dialog. + + @param dialog reference to the closed dialog + @type OllamaChatDialog + """ + hid = dialog.getHistoryId() + with contextlib.suppress(KeyError): + del self.__chatHistoryDialogs[hid] + def __removeChatWidget(self, hid): """ Private method to remove a chat widget given its chat history ID.