Skip to content

Commit

Permalink
remote translator client is responiblity of the remote class
Browse files Browse the repository at this point in the history
* remove remote attributes from base `Translator`
* always set self.client when `_load_translator()` is called

Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
  • Loading branch information
jmartin-tech committed Feb 27, 2025
1 parent 92e7d54 commit 3afc715
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 0 additions & 2 deletions garak/translators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ class Translator(Configurable):
def __init__(self, config_root: dict = {}) -> None:
self._load_config(config_root=config_root)

self.translator = None
self.nmt_client = None
self.source_lang, self.target_lang = self.language.split("-")

self._validate_env_var()
Expand Down
24 changes: 11 additions & 13 deletions garak/translators/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,16 @@ def _load_translator(self):

import riva.client

if self.client is None:
auth = riva.client.Auth(
None,
self.use_ssl,
self.uri,
[
("function-id", self.function_id),
("authorization", "Bearer " + self.api_key),
],
)
self.client = riva.client.NeuralMachineTranslationClient(auth)
auth = riva.client.Auth(
None,
self.use_ssl,
self.uri,
[
("function-id", self.function_id),
("authorization", "Bearer " + self.api_key),
],
)
self.client = riva.client.NeuralMachineTranslationClient(auth)

# TODO: consider adding a backoff here and determining if a connection needs to be re-established
def _translate(self, text: str) -> str:
Expand Down Expand Up @@ -118,8 +117,7 @@ def _load_translator(self):
f"Language pair {self.source_lang}-{self.target_lang} is not supported for this translator service."
)

if self.client is None:
self.client = Translator(self.api_key)
self.client = Translator(self.api_key)

def _translate(self, text: str) -> str:
try:
Expand Down

0 comments on commit 3afc715

Please sign in to comment.