Merge pull request #7 from believethehype/privatezaps

fixes for translations
This commit is contained in:
believethehype 2023-11-28 07:33:18 +01:00 committed by GitHub
commit 254cfb90c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 26 deletions

6
bot.py
View File

@ -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)

2
dvm.py
View File

@ -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)

View File

@ -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):