From f6fc65eeae98a1f4765b3af3040c85badac435f6 Mon Sep 17 00:00:00 2001 From: Raivis Dejus Date: Mon, 26 Aug 2024 19:51:31 +0300 Subject: [PATCH] Adding option to specify different API for translation (#893) --- Makefile | 12 ++++++++---- buzz/translator.py | 13 ++++++++++--- docs/docs/preferences.md | 6 +++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 7ebc758b4..a9ee3d238 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/buzz/translator.py b/buzz/translator.py index 5be35579f..9fa020f7c 100644 --- a/buzz/translator.py +++ b/buzz/translator.py @@ -1,3 +1,4 @@ +import os import logging import queue @@ -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 diff --git a/docs/docs/preferences.md b/docs/docs/preferences.md index f4ca56286..d5405456d 100644 --- a/docs/docs/preferences.md +++ b/docs/docs/preferences.md @@ -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. \ No newline at end of file +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`.