Skip to content

Commit

Permalink
Fix for API key validation (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus authored Jun 18, 2024
1 parent fe1a1e5 commit 82da36f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-2
key: venv-${{ runner.os }}-${{ runner.architecture }}-${{ hashFiles('**/poetry.lock') }}

- name: Load cached Whisper models
id: cached-whisper-models
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-2
key: venv-${{ runner.os }}-${{ runner.architecture }}-${{ hashFiles('**/poetry.lock') }}

- uses: FedericoCarboni/[email protected]
id: setup-ffmpeg
Expand Down
42 changes: 23 additions & 19 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-06-15 17:36+0300\n"
"PO-Revision-Date: 2024-06-15 17:37+0300\n"
"POT-Creation-Date: 2024-06-18 21:50+0300\n"
"PO-Revision-Date: 2024-06-18 21:39+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: lv_LV\n"
Expand Down Expand Up @@ -42,53 +42,57 @@ msgstr "Jūsu ievadītā URL adrese nav derīga."
msgid "Reset to Defaults"
msgstr "Atjaunot noklusētos"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:44
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:45
msgid "Test"
msgstr "Pārbaudīt"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:50
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:51
msgid "OpenAI API key"
msgstr "OpenAI API atslēga"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:63
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:64
msgid "OpenAI base url"
msgstr "OpenAI adrese"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:72
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:73
msgid "Default export file name"
msgstr "Eksporta fails"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:78
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:79
msgid "Enable live recording transcription export"
msgstr "Eksportēt dzīvā ieraksta transkriptus"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:84
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:85
#: buzz/widgets/preferences_dialog/folder_watch_preferences_widget.py:47
#: buzz/widgets/preferences_dialog/folder_watch_preferences_widget.py:50
msgid "Browse"
msgstr "Izvēlēties"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:103
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:104
msgid "Export folder"
msgstr "Eksportēt mapē"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:128
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:134
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:129
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:135
msgid "OpenAI API Key Test"
msgstr "OpenAI API atslēgas pārbaude"

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:129
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:130
msgid ""
"Your API key is valid. Buzz will use this key to perform Whisper API "
"transcriptions and AI translations with ChatGPT."
msgstr ""
"Jūsu API atslēga ir derīga. Buzz izmantos to runas atpazīšanai ar Whisper "
"API un tulkošanai ar ChatGPT."

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

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:189
msgid "OpenAI API returned invalid response, status code: "
msgstr "OpenAI API atbildēja ar nederīgu atbildi, statusa kods: "

#: buzz/widgets/preferences_dialog/folder_watch_preferences_widget.py:42
msgid "Enable folder watch"
msgstr "Ieslēgt mapes vērošanu"
Expand Down Expand Up @@ -324,27 +328,27 @@ msgstr "Pievienots"
msgid "Date Completed"
msgstr "Pabeigts"

#: buzz/widgets/recording_transcriber_widget.py:66
#: buzz/widgets/recording_transcriber_widget.py:71
msgid "Live Recording"
msgstr "Dzīvā ierakstīšana"

#: buzz/widgets/recording_transcriber_widget.py:125
#: buzz/widgets/recording_transcriber_widget.py:130
msgid "Click Record to begin..."
msgstr "Klikšķiniet Ierakstīt, lai sāktu..."

#: buzz/widgets/recording_transcriber_widget.py:128
#: buzz/widgets/recording_transcriber_widget.py:133
msgid "Waiting for AI translation..."
msgstr "Gaida MI tulkojumu..."

#: buzz/widgets/recording_transcriber_widget.py:140
#: buzz/widgets/recording_transcriber_widget.py:145
msgid "Microphone:"
msgstr "Mikrofons:"

#: buzz/widgets/recording_transcriber_widget.py:391
#: buzz/widgets/recording_transcriber_widget.py:397
msgid "An error occurred while starting a new recording:"
msgstr "Sākot jaunu ierakstu notikusi kļūda:"

#: buzz/widgets/recording_transcriber_widget.py:395
#: buzz/widgets/recording_transcriber_widget.py:401
msgid ""
"Please check your audio devices or check the application logs for more "
"information."
Expand Down
23 changes: 22 additions & 1 deletion buzz/widgets/preferences_dialog/general_preferences_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import requests
from typing import Optional
from platformdirs import user_documents_dir

Expand Down Expand Up @@ -175,8 +176,28 @@ def __init__(self, api_key: str):
self.signals = self.Signals()

def run(self):
settings = Settings()
custom_openai_base_url = settings.value(
key=Settings.Key.CUSTOM_OPENAI_BASE_URL, default_value=""
)

if custom_openai_base_url:
try:
response = requests.get(custom_openai_base_url)
if response.status_code != 200:
self.signals.failed.emit(
_("OpenAI API returned invalid response, status code: ") + str(response.status_code)
)
return
except requests.exceptions.RequestException as exc:
self.signals.failed.emit(str(exc))
return

try:
client = OpenAI(api_key=self.api_key)
client = OpenAI(
api_key=self.api_key,
base_url=custom_openai_base_url if custom_openai_base_url else None
)
client.models.list()
self.signals.success.emit()
except AuthenticationError as exc:
Expand Down

0 comments on commit 82da36f

Please sign in to comment.