From 18ae0f5b8fe69e7554d96449da46eea574cbc770 Mon Sep 17 00:00:00 2001 From: Believethehype Date: Tue, 28 Nov 2023 07:32:57 +0100 Subject: [PATCH] fixes for translations --- bot.py | 6 +++--- dvm.py | 2 ++ tasks/translation.py | 32 +++++++++----------------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/bot.py b/bot.py index 5960692..ce20195 100644 --- a/bot.py +++ b/bot.py @@ -118,15 +118,15 @@ class Bot: try: split = i.split(" ") param = str(split[0]) - print(param) + print(str(param)) value = str(split[1]) - print(value) + print(str(value)) tag = Tag.parse(["param", param, value]) tags.append(tag.as_vec()) print("Added params: " + tag.as_vec()) except Exception as e: print(e) - print("Couldn't add " + i) + print("Couldn't add " + str(i)) encrypted_params_string = json.dumps(tags) diff --git a/dvm.py b/dvm.py index 8146746..90c88e3 100644 --- a/dvm.py +++ b/dvm.py @@ -450,6 +450,7 @@ class DVM: or job_event.kind() == EventDefinitions.KIND_DM): task = get_task(job_event, client=self.client, dvmconfig=self.dvm_config) + for dvm in self.dvm_config.SUPPORTED_DVMS: try: if task == dvm.TASK: @@ -458,6 +459,7 @@ class DVM: result = dvm.process(request_form) check_and_return_event(result, str(job_event.as_json())) + except Exception as e: print(e) send_job_status_reaction(job_event, "error", content=str(e), dvm_config=self.dvm_config) diff --git a/tasks/translation.py b/tasks/translation.py index dda618a..d900e39 100644 --- a/tasks/translation.py +++ b/tasks/translation.py @@ -36,50 +36,36 @@ class Translation(DVMTaskInterface): def create_request_form_from_nostr_event(self, event, client=None, dvm_config=None): request_form = {"jobID": event.id().to_hex()} - - input_type = "event" text = "" translation_lang = "en" for tag in event.tags(): if tag.as_vec()[0] == 'i': input_type = tag.as_vec()[2] - - elif tag.as_vec()[0] == 'param': - param = tag.as_vec()[1] - if param == "language": # check for param type - translation_lang = str(tag.as_vec()[2]).split('-')[0] - - if input_type == "event": - for tag in event.tags: - if tag.as_vec()[0] == 'i': + if input_type == "event": evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) text = evt.content() - break - - elif input_type == "text": - for tag in event.tags: - if tag.as_vec()[0] == 'i': + elif input_type == "text": text = tag.as_vec()[1] - break - - elif input_type == "job": - for tag in event.tags: - if tag.as_vec()[0] == 'i': + elif input_type == "job": evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client, kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT, EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT, EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT], dvm_config=dvm_config) text = evt.content() - break + + + elif tag.as_vec()[0] == 'param': + param = tag.as_vec()[1] + if param == "language": # check for param type + translation_lang = str(tag.as_vec()[2]).split('-')[0] options = { "text": text, "language": translation_lang } request_form['options'] = json.dumps(options) - return request_form def process(self, request_form):