Skip to content

Commit 53f33f5

Browse files
authored
Add files via upload
1 parent adf3eb2 commit 53f33f5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

LLM API Price Comperator.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ class NumericLineEdit(QLineEdit):
2222
def __init__(self, placeholder_text='', parent=None):
2323
super().__init__(parent)
2424
self.setPlaceholderText(placeholder_text)
25-
25+
2626
def focusOutEvent(self, event):
2727
text = self.text()
2828
if text and not validate_float(text):
29-
QMessageBox.warning(self, "输入错误", "请输入有效的数字。")
29+
QMessageBox.warning(self, "输入错误", "请输入有效数字。")
3030
self.clear()
3131
super().focusOutEvent(event)
3232

3333
class LLMComparisonTool(QMainWindow):
3434
def __init__(self):
3535
super().__init__()
3636
self.setWindowTitle("LLM API价格比较器")
37-
self.setWindowIcon(QIcon("D:\\Price\\LLM API Price Comperator.ico")) # Set the window icon
38-
self.setGeometry(100, 100, 1200, 350) # Adjust window size
37+
self.setWindowIcon(QIcon("D:\\Price\\LLM API Price Comperator.ico"))
38+
self.setGeometry(100, 100, 1200, 350)
3939
self.exchange_rate = 1.0
4040
self.initUI()
4141
self.get_exchange_rate()
@@ -96,7 +96,7 @@ def initUI(self):
9696
self.github_link.setAlignment(Qt.AlignCenter)
9797
self.layout.addWidget(self.github_link)
9898

99-
self.clear_all_data() # Initially setup with two default rows
99+
self.clear_all_data()
100100

101101
def add_provider_row(self):
102102
index = self.providers_grid.rowCount()
@@ -108,6 +108,7 @@ def add_provider_row(self):
108108
input_price = NumericLineEdit("仅数字")
109109
output_price = NumericLineEdit("仅数字")
110110
input_output_checkbox = QCheckBox()
111+
input_output_checkbox.stateChanged.connect(lambda state, x=output_price: self.toggle_output_price(state, x))
111112
token_unit_combo = QComboBox()
112113
token_unit_combo.addItems(["1K token", "1M token"])
113114
delete_button = QPushButton("删除")
@@ -117,6 +118,12 @@ def add_provider_row(self):
117118
for i, widget in enumerate(row_widgets):
118119
self.providers_grid.addWidget(widget, index, i)
119120

121+
def toggle_output_price(self, state, output_price_widget):
122+
if state == Qt.Checked:
123+
output_price_widget.setDisabled(True)
124+
else:
125+
output_price_widget.setDisabled(False)
126+
120127
def delete_provider_row(self, index):
121128
for j in range(9):
122129
item = self.providers_grid.itemAtPosition(index, j)
@@ -155,7 +162,7 @@ def calculate_costs(self):
155162
currency = self.providers_grid.itemAtPosition(i, 2).widget().currentText()
156163
balance = float(self.providers_grid.itemAtPosition(i, 3).widget().text())
157164
input_price = float(self.providers_grid.itemAtPosition(i, 4).widget().text())
158-
output_price = float(self.providers_grid.itemAtPosition(i, 5).widget().text()) if not self.providers_grid.itemAtPosition(i, 6).widget().isChecked() else input_price
165+
output_price = float(self.providers_grid.itemAtPosition(i, 5).widget().text()) if self.providers_grid.itemAtPosition(i, 6).widget().checkState() == Qt.Unchecked else input_price
159166
tokens_per_unit = {'1K token': 1000, '1M token': 1000000}[self.providers_grid.itemAtPosition(i, 7).widget().currentText()]
160167

161168
if currency == "USD":

0 commit comments

Comments
 (0)