fixes for translations

This commit is contained in:
Believethehype 2023-11-28 07:32:57 +01:00
parent 508278d10b
commit 18ae0f5b8f
3 changed files with 14 additions and 26 deletions

6
bot.py
View File

@ -118,15 +118,15 @@ class Bot:
try: try:
split = i.split(" ") split = i.split(" ")
param = str(split[0]) param = str(split[0])
print(param) print(str(param))
value = str(split[1]) value = str(split[1])
print(value) print(str(value))
tag = Tag.parse(["param", param, value]) tag = Tag.parse(["param", param, value])
tags.append(tag.as_vec()) tags.append(tag.as_vec())
print("Added params: " + tag.as_vec()) print("Added params: " + tag.as_vec())
except Exception as e: except Exception as e:
print(e) print(e)
print("Couldn't add " + i) print("Couldn't add " + str(i))
encrypted_params_string = json.dumps(tags) encrypted_params_string = json.dumps(tags)

2
dvm.py
View File

@ -450,6 +450,7 @@ class DVM:
or job_event.kind() == EventDefinitions.KIND_DM): or job_event.kind() == EventDefinitions.KIND_DM):
task = get_task(job_event, client=self.client, dvmconfig=self.dvm_config) task = get_task(job_event, client=self.client, dvmconfig=self.dvm_config)
for dvm in self.dvm_config.SUPPORTED_DVMS: for dvm in self.dvm_config.SUPPORTED_DVMS:
try: try:
if task == dvm.TASK: if task == dvm.TASK:
@ -458,6 +459,7 @@ class DVM:
result = dvm.process(request_form) result = dvm.process(request_form)
check_and_return_event(result, str(job_event.as_json())) check_and_return_event(result, str(job_event.as_json()))
except Exception as e: except Exception as e:
print(e) print(e)
send_job_status_reaction(job_event, "error", content=str(e), dvm_config=self.dvm_config) send_job_status_reaction(job_event, "error", content=str(e), dvm_config=self.dvm_config)

View File

@ -36,50 +36,36 @@ class Translation(DVMTaskInterface):
def create_request_form_from_nostr_event(self, event, client=None, dvm_config=None): def create_request_form_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
input_type = "event"
text = "" text = ""
translation_lang = "en" translation_lang = "en"
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_type = tag.as_vec()[2] input_type = tag.as_vec()[2]
if input_type == "event":
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':
evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config)
text = evt.content() text = evt.content()
break elif input_type == "text":
elif input_type == "text":
for tag in event.tags:
if tag.as_vec()[0] == 'i':
text = tag.as_vec()[1] text = tag.as_vec()[1]
break elif input_type == "job":
elif input_type == "job":
for tag in event.tags:
if tag.as_vec()[0] == 'i':
evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client, evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client,
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT, kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT, EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT], EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT],
dvm_config=dvm_config) dvm_config=dvm_config)
text = evt.content() 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 = { options = {
"text": text, "text": text,
"language": translation_lang "language": translation_lang
} }
request_form['options'] = json.dumps(options) request_form['options'] = json.dumps(options)
return request_form return request_form
def process(self, request_form): def process(self, request_form):