[Add] translation_gemini: Integrate Gemini translation model and authentication; [Update] controller: Implement methods for managing Gemini models and auth keys; [Update] mainloop: Add routes for Gemini model and auth key management; [Update] translation: Enhance Translator class for Gemini API support; [Update] translation_languages: Add Gemini language mappings
This commit is contained in:
@@ -10,6 +10,7 @@ try:
|
||||
from .translation_languages import translation_lang
|
||||
from .translation_utils import ctranslate2_weights
|
||||
from .translation_plamo import PlamoClient
|
||||
from .translation_gemini import GeminiClient
|
||||
except Exception:
|
||||
import sys
|
||||
print(os_path.dirname(os_path.dirname(os_path.dirname(os_path.abspath(__file__)))))
|
||||
@@ -17,6 +18,7 @@ except Exception:
|
||||
from translation_languages import translation_lang
|
||||
from translation_utils import ctranslate2_weights
|
||||
from translation_plamo import PlamoClient
|
||||
from translation_gemini import GeminiClient
|
||||
|
||||
import ctranslate2
|
||||
import transformers
|
||||
@@ -30,6 +32,7 @@ class Translator():
|
||||
def __init__(self):
|
||||
self.deepl_client = None
|
||||
self.plamo_client = None
|
||||
self.gemini_client = None
|
||||
self.ctranslate2_translator = None
|
||||
self.ctranslate2_tokenizer = None
|
||||
self.is_loaded_ctranslate2_model = False
|
||||
@@ -57,6 +60,17 @@ class Translator():
|
||||
result = False
|
||||
return result
|
||||
|
||||
def authenticationGeminiAuthKey(self, auth_key: str, model: str) -> bool:
|
||||
result = True
|
||||
try:
|
||||
self.gemini_client = GeminiClient(auth_key, model=model)
|
||||
self.gemini_client.checkAuthKey()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
self.gemini_client = None
|
||||
result = False
|
||||
return result
|
||||
|
||||
def changeCTranslate2Model(self, path, model_type, device="cpu", device_index=0):
|
||||
self.is_loaded_ctranslate2_model = False
|
||||
directory_name = ctranslate2_weights[model_type]["directory_name"]
|
||||
@@ -158,6 +172,15 @@ class Translator():
|
||||
input_lang=source_language,
|
||||
output_lang=target_language,
|
||||
)
|
||||
case "Gemini_API":
|
||||
if self.gemini_client is None:
|
||||
result = False
|
||||
else:
|
||||
result = self.gemini_client.translate(
|
||||
message,
|
||||
input_lang=source_language,
|
||||
output_lang=target_language,
|
||||
)
|
||||
case "Google":
|
||||
if self.is_enable_translators is True:
|
||||
result = other_web_Translator(
|
||||
|
||||
Reference in New Issue
Block a user