Skip to content

Commit

Permalink
Adding option to specify different API for translation (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus authored Aug 26, 2024
1 parent a25c384 commit f6fc65e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ endif

clean:
ifeq ($(OS), Windows_NT)
del /f buzz\$(LIBWHISPER) 2> nul
del /f buzz\whisper_cpp.py 2> nul
rmdir /s /q whisper.cpp\build 2> nul
rmdir /s /q dist 2> nul
-del /f buzz\$(LIBWHISPER) 2> nul
-del /f buzz\whisper_cpp.py 2> nul
-rmdir /s /q whisper.cpp\build 2> nul
-rmdir /s /q dist 2> nul
-rm -f buzz/$(LIBWHISPER)
-rm -f buzz/whisper_cpp.py
-rm -rf whisper.cpp/build || true
-rm -rf dist/* || true
else
rm -f buzz/$(LIBWHISPER)
rm -f buzz/whisper_cpp.py
Expand Down
13 changes: 10 additions & 3 deletions buzz/translator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import logging
import queue

Expand Down Expand Up @@ -35,10 +36,16 @@ def __init__(
self.queue = queue.Queue()

settings = Settings()
custom_openai_base_url = settings.value(
key=Settings.Key.CUSTOM_OPENAI_BASE_URL, default_value=""
custom_openai_base_url = os.getenv(
"BUZZ_TRANSLATION_API_BASE_URl",
settings.value(
key=Settings.Key.CUSTOM_OPENAI_BASE_URL, default_value=""
)
)
openai_api_key = os.getenv(
"BUZZ_TRANSLATION_API_KEY",
get_password(Key.OPENAI_API_KEY)
)
openai_api_key = get_password(Key.OPENAI_API_KEY)
self.openai_client = OpenAI(
api_key=openai_api_key,
base_url=custom_openai_base_url if custom_openai_base_url else None
Expand Down
6 changes: 5 additions & 1 deletion docs/docs/preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ set SOME_OTHER_VARIABLE=some_other_value

On a laptop with 16 threads setting `BUZZ_WHISPERCPP_N_THREADS=8` leads to some 15% speedup in transcription time.
Increasing number of threads even more will lead in slower transcription time as results from parallel threads has to be
combined to produce the final answer.
combined to produce the final answer.

**BUZZ_TRANSLATION_API_BASE_URl** - Base URL of OpenAI compatible API to use for translation. Available from `v1.0.2`.

**BUZZ_TRANSLATION_API_KEY** - Api key of OpenAI compatible API to use for translation. Available from `v1.0.2`.

0 comments on commit f6fc65e

Please sign in to comment.