8000 add each conv unit result for analyzing #2 · ag-python-qt/pyqt-openai@1de2388 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1de2388

Browse files
committed
add each conv unit result for analyzing yjg30737#2
1 parent 286736e commit 1de2388

File tree

6 files changed

+27
-65
lines changed

6 files changed

+27
-65
lines changed

pyqt_openai/chat_widget/aiChatUnit.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ def __initUi(self):
8989
self.__icon = RoundedImage()
9090
self.__icon.setMaximumSize(24, 24)
9191

92-
self.__finishReasonLbl = QLabel()
93-
self.__finishReasonLbl.setObjectName('finishReasonLbl')
94-
9592
self.__infoBtn = SvgButton()
9693
self.__infoBtn.setIcon('ico/info.svg')
9794
self.__infoBtn.clicked.connect(self.__showInfo)
@@ -104,7 +101,6 @@ def __initUi(self):
104101
lay.addWidget(self.__icon)
105102
lay.addSpacerItem(QSpacerItem(10, 10, QSizePolicy.MinimumExpanding))
106103
lay.addWidget(self.__infoBtn)
107-
lay.addWidget(self.__finishReasonLbl)
108104
lay.addWidget(self.__copyBtn)
109105
lay.setContentsMargins(2, 2, 2, 2)
110106
lay.setSpacing(1)
@@ -168,13 +164,6 @@ def disableGUIDuringGenerateResponse(self):
168164
def showConvResultInfo(self, finish_reason):
169165
self.__copyBtn.setEnabled(True)
170166
self.__infoBtn.setEnabled(True)
171-
self.__finishReasonLbl.setText(f'Finish Reason: {finish_reason}')
172-
173-
def showFinishReason(self, f):
174-
self.__finishReasonLbl.setVisible(f)
175-
176-
def getFinishReason(self):
177-
return self.__finishReasonLbl.text()
178167

179168
def setText(self, text: str):
180169
self.__lbl = QLabel(text)

pyqt_openai/chat_widget/chatBrowser.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ class ChatBrowser(QScrollArea):
1212
convUnitUpdated = Signal(int, int, str, str)
1313
onReplacedCurrentPage = Signal(int)
1414

15-
def __init__(self, finish_reason=True):
15+
def __init__(self):
1616
super().__init__()
17-
self.__initVal(finish_reason)
17+
self.__initVal()
1818
self.__initUi()
1919

20-
def __initVal(self, finish_reason):
20+
def __initVal(self):
2121
self.__cur_id = 0
22-
self.__show_finished_reason_f = finish_reason
2322

2423
self.__user_image = ''
2524
self.__ai_image = ''
@@ -87,7 +86,6 @@ def __setLabel(self, text, stream_f, user_f):
8786
unit.addText(text)
8887
return
8988
chatUnit.setText(text)
90-
chatUnit.showFinishReason(self.__show_finished_reason_f)
9189

9290
self.widget().layout().addWidget(chatUnit)
9391
return chatUnit
121119
return widget.text()
122120
return ''
123121

124-
def getLastFinishReason(self):
125-
lay = self.widget().layout()
126-
if lay:
127-
i = lay.count()-1
128-
if lay.itemAt(i) and lay.itemAt(i).widget():
129-
widget = lay.itemAt(i).widget()
130-
if isinstance(widget, AIChatUnit):
131-
return widget.getFinishReason()
132-
return ''
133-
134122
def getEveryResponse(self):
135123
lay = self.widget().layout()
136124
if lay:
@@ -176,6 +164,10 @@ def __getEveryAILabels(self):
176164
labels = [lay.itemAt(i).widget() for i in range(lay.count()) if lay.itemAt(i) and isinstance(lay.itemAt(i).widget(), AIChatUnit)]
177165
return labels
178166

167+
def getLastFinishReason(self):
168+
# 1 is continue 0 is not continue
169+
return 1
170+
179171
def setCurrentLabelIncludingTextBySliderPosition(self, text, case_sensitive=False, word_only=False, is_regex=False):
180172
labels = self.__getEveryLabels()
181173
label_info = [{'class':label, 'text':label.text(), 'pos':label.y()} for label in labels]
@@ -231,19 +223,6 @@ def replaceConv(self, id, conv_data):
231223
unit = self.__setLabel(conv_data[i]['conv'], False, conv_data[i]['is_user'])
232224
self.__showConvResultInfo(unit, conv_data[i]['finish_reason'])
233225

234-
def toggle_show_finished_reason_f(self, f):
235-
self.__show_finished_reason_f = f
236-
lay = self.widget().layout()
237-
if lay:
238-
for i in range(lay.count()):
239-
item = lay.itemAt(i)
240-
if item and item.widget():
241-
unit = item.widget()
242-
if isinstance(unit, AIChatUnit):
243-
lbl = unit.findChild(QLabel, 'finishReasonLbl')
244-
if isinstance(lbl, QLabel):
245-
lbl.setVisible(self.__show_finished_reason_f)
246-
247226
def setUserImage(self, img):
248227
self.__user_image = img
249228
lbls = self.__getEveryUserLabels()

pyqt_openai/openAiChatBotWidget.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def __initUi(self):
5555
self.__lineEdit = self.__prompt.getTextEdit()
5656
self.__aiPlaygroundWidget = AIPlaygroundWidget()
5757
self.__aiPlaygroundWidget.onDirectorySelected.connect(self.__llama_class.set_directory)
58-
self.__aiPlaygroundWidget.onFinishReasonToggled.connect(self.__onFinishReasonToggled)
5958
self.__promptGeneratorWidget = PromptGeneratorWidget(self.__db)
6059

6160
self.__sideBarBtn = SvgButton()
@@ -274,6 +273,7 @@ def __beforeGenerated(self):
274273
self.__lineEdit.clear()
275274

276275
def __afterGenerated(self):
276+
# TODO 2023-11-11
277277
continue_f = self.__browser.getLastFinishReason() == 'Finish Reason: length'
278278
self.__toggleWidgetWhileChatting(True, continue_f)
279279
self.__lineEdit.setFocus()
@@ -306,9 +306,6 @@ def __deleteConv(self, id_lst):
306306
for id in id_lst:
307307
self.__db.deleteConv(id)
308308

309-
def __onFinishReasonToggled(self, f):
310-
self.__browser.toggle_show_finished_reason_f(f)
311-
312309
def __export(self, ids):
313310
file_data = QFileDialog.getSaveFileName(self, LangClass.TRANSLATIONS['Save'], os.path.expanduser('~'), 'SQLite DB file (*.db);;txt files Compressed File (*.zip);;html files Compressed File (*.zip)')
314311
if file_data[0]:

pyqt_openai/right_sidebar/aiPlaygroundWidget.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
class AIPlaygroundWidget(QScrollArea):
1313
onDirectorySelected = Signal(str)
14-
onFinishReasonToggled = Signal(bool)
1514

1615
def __init__(self):
1716
super().__init__()
@@ -49,7 +48,6 @@ def __initUi(self):
4948

5049
partial_func = partial(tabWidget.setTabEnabled, 1)
5150
chatPage.onToggleLlama.connect(lambda x: partial_func(x))
52-
chatPage.onFinishReasonToggled.connect(self.onFinishReasonToggled)
5351

5452
lay = QGridLayout()
5553
lay.addWidget(tabWidget)

pyqt_openai/right_sidebar/chatPage.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
class ChatPage(QWidget):
1010
onToggleLlama = Signal(bool)
11-
onFinishReasonToggled = Signal(bool)
1211

1312
def __init__(self):
1413
super().__init__()
@@ -126,10 +125,6 @@ def __initUi(self):
126125
useMaxTokenChkBox.setText(LangClass.TRANSLATIONS['Use Max Tokens'])
127126
self.__maxTokensSpinBox.setEnabled(self.__use_max_tokens)
128127

129-
finishReasonChkBox = QCheckBox(LangClass.TRANSLATIONS['Show Finish Reason'])
130-
finishReasonChkBox.toggled.connect(self.__finishReasonChecked)
131-
finishReasonChkBox.setChecked(self.__finish_reason)
132-
133128
lay = QFormLayout()
134129

135130
lay.addRow('temperature', temperatureSpinBox)
@@ -149,7 +144,6 @@ def __initUi(self):
149144
lay.addWidget(modelCmbBox)
150145
lay.addWidget(streamChkBox)
151146
lay.addWidget(useMaxTokenChkBox)
152-
lay.addWidget(finishReasonChkBox)
153147
lay.addWidget(llamaChkBox)
154148
lay.addWidget(sep)
155149
lay.addWidget(paramWidget)
@@ -179,11 +173,6 @@ def __useMaxChecked(self, f):
179173
self.__settings_ini.setValue('use_max_tokens', f)
180174
self.__maxTokensSpinBox.setEnabled(f)
181175

182-
def __finishReasonChecked(self, f):
183-
self.__finish_reason = f
184-
self.__settings_ini.setValue('finish_reason', f)
185-
self.onFinishReasonToggled.emit(f)
186-
187176
def __temperatureChanged(self, v):
188177
self.__temperature = v
189178
self.__settings_ini.setValue('temperature', v)

pyqt_openai/sqlite.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,21 +450,23 @@ def __alterConvUnit(self):
450450

451451
# get the columns
452452
for name in res.fetchall():
453-
col_to_add = [{'name': 'finish_reason', 'type': 'TEXT' }]
453+
col_to_add = [{'field_name': 'finish_reason', 'type': 'TEXT'},
454+
{'field_name': 'model_name', 'type': 'VARCHAR(255)'},
455+
{'field_name': 'prompt_tokens', 'type': 'INTEGER'},
456+
{'field_name': 'completion_tokens', 'type': 'INTEGER'},
457+
{'field_name': 'total_tokens', 'type': 'INTEGER'}]
454458

455459
self.__c.execute(f"PRAGMA table_info({name[0]})")
456460
existing_columns_to_add = [column[1] for column in self.__c.fetchall()]
457461

458-
col_to_add = list(filter(lambda x: x['name'] not in existing_columns_to_add, col_to_add))
462+
col_to_add = list(filter(lambda x: x['field_name'] not in existing_columns_to_add, col_to_add))
459463

460464
if len(col_to_add) > 0:
461-
statement = f'ALTER TABLE {name[0]}'
462465
for col in col_to_add:
463-
name = col['name']
466+
field_name = col['field_name']
464467
type = col['type']
465-
1241 statement += f' ADD COLUMN {name} {type}'
466-
467-
self.__c.execute(statement)
468+
E769 statement = f'ALTER TABLE {name[0]} ADD COLUMN {field_name} {type}'
469+
self.__c.execute(statement)
468470

469471
# self.__c.execute(f'''ALTER TABLE {self.__conv_unit_tb_nm}{id_fk}
470472
# ADD COLUMN new_column_name data_type''')
@@ -483,7 +485,11 @@ def __createConvUnit(self, id_fk):
483485
id_fk INTEGER,
484486
is_user INTEGER,
485487
conv TEXT,
486-
finish_reason TEXT,
488+
finish_reason VARCHAR(255),
489+
model_name VARCHAR(255),
490+
prompt_tokens INTEGER,
491+
completion_tokens INTEGER,
492+
total_tokens INTEGER,
487493
update_dt DATETIME DEFAULT CURRENT_TIMESTAMP,
488494
insert_dt DATETIME DEFAULT CURRENT_TIMESTAMP,
489495
FOREIGN KEY (id_fk) REFERENCES {self.__conv_tb_nm}(id) ON DELETE CASCADE)''')
@@ -530,7 +536,11 @@ def selectCertainConv(self, id):
530536
'is_user': elem[2],
531537
'conv': elem[3],
532538
'finish_reason': elem[4],
533-
'update_dt': elem[5]} for elem in self.selectCertainConvRaw(id)]
539+
'model_name': elem[5],
540+
'prompt_tokens': elem[6],
541+
'completion_tokens': elem[7],
542+
'total_tokens': elem[8],
543+
'update_dt': elem[9]} for elem in self.selectCertainConvRaw(id)]
534544

535545
def selectAllContentOfConv(self):
536546
arr = []

0 commit comments

Comments
 (0)
0