Skip to content

Commit

Permalink
Fix for API key check (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus authored Jul 11, 2024
1 parent 3ac0988 commit af48f32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
24 changes: 15 additions & 9 deletions buzz/locale/lv_LV/LC_MESSAGES/buzz.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-02 22:07+0300\n"
"PO-Revision-Date: 2024-07-02 22:09+0300\n"
"POT-Creation-Date: 2024-07-11 19:46+0300\n"
"PO-Revision-Date: 2024-07-11 19:48+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: lv_LV\n"
Expand Down Expand Up @@ -97,18 +97,24 @@ msgstr "OpenAI API atslēgas pārbaude"
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:139
msgid ""
"Your API key is valid. Buzz will use this key to perform Whisper API "
"transcriptions and AI translations with ChatGPT."
"transcriptions and AI translations."
msgstr ""
"Jūsu API atslēga ir derīga. Buzz izmantos to runas atpazīšanai ar Whisper "
"API un tulkošanai ar ChatGPT."
"API un tulkošanai."

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:166
msgid "Select Export Folder"
msgstr "Izvēlieties mapi kurā eksportēt"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:207
msgid "OpenAI API returned invalid response, status code: "
msgstr "OpenAI API atbildēja ar nederīgu atbildi, statusa kods: "
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:216
msgid ""
"OpenAI API returned invalid response. Please check the API url or your key. "
"Transcription and translation may still work if the API does not support key "
"validation."
msgstr ""
"OpenAI API atbilde ir nederīga. Lūdzu pārbaudiet API Adresi un savu atslēgu. "
"Atpazīšana un tulkošana joprojām var strādāt, ja API neatbalsta atslēgu "
"pārbaudi. "

#: buzz/widgets/preferences_dialog/folder_watch_preferences_widget.py:42
msgid "Enable folder watch"
Expand Down Expand Up @@ -195,7 +201,7 @@ msgid "Download failed"
msgstr "Lejupielāde neizdevās"

#: buzz/widgets/preferences_dialog/models_preferences_widget.py:259
#: buzz/widgets/main_window.py:291 buzz/model_loader.py:450
#: buzz/widgets/main_window.py:291 buzz/model_loader.py:462
msgid "Error"
msgstr "Kļūda"

Expand Down Expand Up @@ -519,7 +525,7 @@ msgstr "Neizdevās saglabāt OpenAI API atslēgu atslēgu saišķī"
msgid "Transcribe"
msgstr "Atpazīt"

#: buzz/model_loader.py:478
#: buzz/model_loader.py:490
msgid "A connection error occurred"
msgstr "Notika savienojuma kļūda"

Expand Down
19 changes: 15 additions & 4 deletions buzz/widgets/preferences_dialog/general_preferences_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def on_test_openai_api_key_success(self):
QMessageBox.information(
self,
_("OpenAI API Key Test"),
_("Your API key is valid. Buzz will use this key to perform Whisper API transcriptions and AI translations with ChatGPT."),
_("Your API key is valid. Buzz will use this key to perform Whisper API transcriptions and AI translations."),
)

def on_test_openai_api_key_failure(self, error: str):
Expand Down Expand Up @@ -201,10 +201,20 @@ def run(self):

if custom_openai_base_url:
try:
response = requests.get(custom_openai_base_url)
if not custom_openai_base_url.endswith("/"):
custom_openai_base_url += "/"

headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}

response = requests.get(custom_openai_base_url + "models", headers=headers, timeout=5)

if response.status_code != 200:
self.signals.failed.emit(
_("OpenAI API returned invalid response, status code: ") + str(response.status_code)
_("OpenAI API returned invalid response. Please check the API url or your key. "
"Transcription and translation may still work if the API does not support key validation.")
)
return
except requests.exceptions.RequestException as exc:
Expand All @@ -214,7 +224,8 @@ def run(self):
try:
client = OpenAI(
api_key=self.api_key,
base_url=custom_openai_base_url if custom_openai_base_url else None
base_url=custom_openai_base_url if custom_openai_base_url else None,
timeout=5,
)
client.models.list()
self.signals.success.emit()
Expand Down

0 comments on commit af48f32

Please sign in to comment.