10 import json |
10 import json |
11 import os |
11 import os |
12 import uuid |
12 import uuid |
13 |
13 |
14 from PyQt6.QtCore import pyqtSignal, pyqtSlot |
14 from PyQt6.QtCore import pyqtSignal, pyqtSlot |
15 from PyQt6.QtWidgets import QInputDialog, QLineEdit, QWidget |
15 from PyQt6.QtWidgets import QDialog, QWidget |
16 |
16 |
17 from eric7.EricGui import EricPixmapCache |
17 from eric7.EricGui import EricPixmapCache |
18 from eric7.EricWidgets.EricApplication import ericApp |
18 from eric7.EricWidgets.EricApplication import ericApp |
19 |
19 |
20 from .Ui_OllamaHistoryWidget import Ui_OllamaHistoryWidget |
20 from .Ui_OllamaHistoryWidget import Ui_OllamaHistoryWidget |
29 @signal newChatWithHistory(id:str) emitted to indicate, that a new chat using |
29 @signal newChatWithHistory(id:str) emitted to indicate, that a new chat using |
30 the saved history should be started |
30 the saved history should be started |
31 @signal viewChatHistory(id:str) emitted to indicate, that this chat history |
31 @signal viewChatHistory(id:str) emitted to indicate, that this chat history |
32 should be shown in a separate window |
32 should be shown in a separate window |
33 @signal dataChanged(id:str) emitted to indicate a change of the chat history data |
33 @signal dataChanged(id:str) emitted to indicate a change of the chat history data |
|
34 @signal parametersChanged(id:str, title:str, model:str) emitted to indicate a |
|
35 change of editable chat parameters |
34 """ |
36 """ |
35 |
37 |
36 deleteChatHistory = pyqtSignal(str) |
38 deleteChatHistory = pyqtSignal(str) |
37 newChatWithHistory = pyqtSignal(str) |
39 newChatWithHistory = pyqtSignal(str) |
38 viewChatHistory = pyqtSignal(str) |
40 viewChatHistory = pyqtSignal(str) |
39 dataChanged = pyqtSignal(str) |
41 dataChanged = pyqtSignal(str) |
40 |
42 parametersChanged = pyqtSignal(str, str, str) |
41 def __init__(self, title, model, jsonStr=None, parent=None): |
43 |
|
44 def __init__(self, title, model, mainWidget, jsonStr=None, parent=None): |
42 """ |
45 """ |
43 Constructor |
46 Constructor |
44 |
47 |
45 @param title title of the ollama chat |
48 @param title title of the ollama chat |
46 @type str |
49 @type str |
47 @param model name of the model used for the chat |
50 @param model name of the model used for the chat |
48 @type str |
51 @type str |
49 @param jsonStr string containing JSON serialize chat history data |
52 @param mainWidget reference to the Ollama main widget |
|
53 @type OllamaWidget |
|
54 @param jsonStr string containing JSON serialized chat history data |
50 (defaults to None) |
55 (defaults to None) |
51 @type str (optional) |
56 @type str (optional) |
52 @param parent reference to the parent widget (defaults to None) |
57 @param parent reference to the parent widget (defaults to None) |
53 @type QWidget (optional) |
58 @type QWidget (optional) |
54 """ |
59 """ |
131 @pyqtSlot() |
138 @pyqtSlot() |
132 def on_editButton_clicked(self): |
139 def on_editButton_clicked(self): |
133 """ |
140 """ |
134 Private slot to edit the chat title. |
141 Private slot to edit the chat title. |
135 """ |
142 """ |
136 title, ok = QInputDialog.getText( |
143 from .OllamaHistoryEditDialog import OllamaHistoryEditDialog |
137 self, |
144 |
138 self.tr("Edit Chat Title"), |
145 dlg = OllamaHistoryEditDialog( |
139 self.tr("Enter the new title:"), |
146 title=self.__title, |
140 QLineEdit.EchoMode.Normal, |
147 model=self.__model, |
141 self.__title, |
148 selectableModels=self.__ollamaWidget.getSelectableModels(), |
142 ) |
149 ) |
143 if ok and bool(title): |
150 if dlg.exec() == QDialog.DialogCode.Accepted: |
144 self.__title = title |
151 self.__title, self.__model = dlg.getData() |
145 self.titleEdit.setText(title) |
152 self.titleEdit.setText(self.__title) |
|
153 self.modelEdit.setText(self.__model) |
146 self.dataChanged.emit(self.__id) |
154 self.dataChanged.emit(self.__id) |
|
155 self.parametersChanged.emit(self.__id, self.__title, self.__model) |
147 |
156 |
148 @pyqtSlot() |
157 @pyqtSlot() |
149 def on_viewButton_clicked(self): |
158 def on_viewButton_clicked(self): |
150 """ |
159 """ |
151 Private slot to view the current chat history in a separate window.. |
160 Private slot to view the current chat history in a separate window.. |