move is_input_supported and post_process to async, fix some get_event_id async

This commit is contained in:
Believethehype 2024-06-17 09:12:48 +02:00
parent 1b65ccedd2
commit b5a848d7fc
45 changed files with 150 additions and 154 deletions

View File

@ -1,16 +1,12 @@
import asyncio import asyncio
import json import json
import os import os
import subprocess
import threading
from datetime import timedelta from datetime import timedelta
from sys import platform from sys import platform
from nostr_sdk import PublicKey, Keys, Client, Tag, Event, EventBuilder, Filter, HandleNotification, Timestamp, \ from nostr_sdk import PublicKey, Keys, Client, Tag, Event, EventBuilder, Filter, HandleNotification, Timestamp, \
init_logger, LogLevel, Options, nip04_encrypt, NostrSigner, Kind, RelayLimits init_logger, LogLevel, Options, nip04_encrypt, NostrSigner, Kind, RelayLimits
import time
from nostr_dvm.utils.definitions import EventDefinitions, RequiredJobToWatch, JobToWatch from nostr_dvm.utils.definitions import EventDefinitions, RequiredJobToWatch, JobToWatch
from nostr_dvm.utils.dvmconfig import DVMConfig from nostr_dvm.utils.dvmconfig import DVMConfig
from nostr_dvm.utils.admin_utils import admin_make_database_updates, AdminConfig from nostr_dvm.utils.admin_utils import admin_make_database_updates, AdminConfig
@ -115,7 +111,7 @@ class DVM:
return return
# check if task is supported by the current DVM # check if task is supported by the current DVM
task_supported, task = check_task_is_supported(nip90_event, client=self.client, task_supported, task = await check_task_is_supported(nip90_event, client=self.client,
config=self.dvm_config) config=self.dvm_config)
# if task is supported, continue, else do nothing. # if task is supported, continue, else do nothing.
if task_supported: if task_supported:
@ -306,7 +302,7 @@ class DVM:
if tag.as_vec()[0] == 'amount': if tag.as_vec()[0] == 'amount':
amount = int(float(tag.as_vec()[1]) / 1000) amount = int(float(tag.as_vec()[1]) / 1000)
elif tag.as_vec()[0] == 'e': elif tag.as_vec()[0] == 'e':
job_event = get_event_by_id(tag.as_vec()[1], client=self.client, config=self.dvm_config) job_event = await get_event_by_id(tag.as_vec()[1], client=self.client, config=self.dvm_config)
if job_event is not None: if job_event is not None:
job_event = check_and_decrypt_tags(job_event, self.dvm_config) job_event = check_and_decrypt_tags(job_event, self.dvm_config)
if job_event is None: if job_event is None:
@ -326,7 +322,7 @@ class DVM:
else: else:
task_supported, task = check_task_is_supported(job_event, client=self.client, task_supported, task = await check_task_is_supported(job_event, client=self.client,
config=self.dvm_config) config=self.dvm_config)
if job_event is not None and task_supported: if job_event is not None and task_supported:
print("Zap received for NIP90 task: " + str(invoice_amount) + " Sats from " + str( print("Zap received for NIP90 task: " + str(invoice_amount) + " Sats from " + str(
@ -382,7 +378,7 @@ class DVM:
print("[" + self.dvm_config.NIP89.NAME + "] Error during content decryption: " + str(e)) print("[" + self.dvm_config.NIP89.NAME + "] Error during content decryption: " + str(e))
async def check_event_has_not_unfinished_job_input(nevent, append, client, dvmconfig): async def check_event_has_not_unfinished_job_input(nevent, append, client, dvmconfig):
task_supported, task = check_task_is_supported(nevent, client, config=dvmconfig) task_supported, task = await check_task_is_supported(nevent, client, config=dvmconfig)
if not task_supported: if not task_supported:
return False return False
@ -395,7 +391,7 @@ class DVM:
input = tag.as_vec()[1] input = tag.as_vec()[1]
input_type = tag.as_vec()[2] input_type = tag.as_vec()[2]
if input_type == "job": if input_type == "job":
evt = get_referenced_event_by_id(event_id=input, client=client, evt = await get_referenced_event_by_id(event_id=input, client=client,
kinds=EventDefinitions.ANY_RESULT, kinds=EventDefinitions.ANY_RESULT,
dvm_config=dvmconfig) dvm_config=dvmconfig)
if evt is None: if evt is None:
@ -434,11 +430,11 @@ class DVM:
await send_nostr_reply_event(data, original_event.as_json()) await send_nostr_reply_event(data, original_event.as_json())
break break
task = get_task(original_event, self.client, self.dvm_config) task = await get_task(original_event, self.client, self.dvm_config)
for dvm in self.dvm_config.SUPPORTED_DVMS: for dvm in self.dvm_config.SUPPORTED_DVMS:
if task == dvm.TASK: if task == dvm.TASK:
try: try:
post_processed = dvm.post_process(data, original_event) post_processed = await dvm.post_process(data, original_event)
await send_nostr_reply_event(post_processed, original_event.as_json()) await send_nostr_reply_event(post_processed, original_event.as_json())
except Exception as e: except Exception as e:
print(e) print(e)
@ -515,7 +511,7 @@ class DVM:
content=None, content=None,
dvm_config=None, user=None): dvm_config=None, user=None):
task = get_task(original_event, client=client, dvm_config=dvm_config) task = await get_task(original_event, client=client, dvm_config=dvm_config)
alt_description, reaction = build_status_reaction(status, task, amount, content, dvm_config) alt_description, reaction = build_status_reaction(status, task, amount, content, dvm_config)
e_tag = Tag.parse(["e", original_event.id().to_hex()]) e_tag = Tag.parse(["e", original_event.id().to_hex()])
@ -654,14 +650,14 @@ class DVM:
EventDefinitions.KIND_NIP90_EXTRACT_TEXT.as_u64() <= job_event.kind().as_u64() <= EventDefinitions.KIND_NIP90_GENERIC.as_u64()) EventDefinitions.KIND_NIP90_EXTRACT_TEXT.as_u64() <= job_event.kind().as_u64() <= EventDefinitions.KIND_NIP90_GENERIC.as_u64())
or job_event.kind().as_u64() == EventDefinitions.KIND_DM.as_u64()): or job_event.kind().as_u64() == EventDefinitions.KIND_DM.as_u64()):
task = get_task(job_event, client=self.client, dvm_config=self.dvm_config) task = await get_task(job_event, client=self.client, dvm_config=self.dvm_config)
for dvm in self.dvm_config.SUPPORTED_DVMS: for dvm in self.dvm_config.SUPPORTED_DVMS:
result = "" result = ""
try: try:
if task == dvm.TASK: if task == dvm.TASK:
request_form = dvm.create_request_from_nostr_event(job_event, self.client, self.dvm_config) request_form = await dvm.create_request_from_nostr_event(job_event, self.client, self.dvm_config)
if dvm_config.USE_OWN_VENV: if dvm_config.USE_OWN_VENV:
python_location = "/bin/python" python_location = "/bin/python"
@ -689,7 +685,7 @@ class DVM:
# We install locally in these cases for now # We install locally in these cases for now
result = await dvm.process(request_form) result = await dvm.process(request_form)
try: try:
post_processed = dvm.post_process(result, job_event) post_processed = await dvm.post_process(result, job_event)
await send_nostr_reply_event(post_processed, job_event.as_json()) await send_nostr_reply_event(post_processed, job_event.as_json())
except Exception as e: except Exception as e:
print(bcolors.RED + "[" + self.dvm_config.NIP89.NAME + "] Error: " + str( print(bcolors.RED + "[" + self.dvm_config.NIP89.NAME + "] Error: " + str(

View File

@ -120,11 +120,11 @@ class DVMTaskInterface:
nip89.CONTENT = nip89config.CONTENT nip89.CONTENT = nip89config.CONTENT
return nip89 return nip89
def is_input_supported(self, tags, client=None, dvm_config=None) -> bool: async def is_input_supported(self, tags, client=None, dvm_config=None) -> bool:
"""Check if input is supported for current Task.""" """Check if input is supported for current Task."""
pass pass
def create_request_from_nostr_event(self, event, client=None, dvm_config=None) -> dict: async def create_request_from_nostr_event(self, event, client=None, dvm_config=None) -> dict:
"""Parse input into a request form that will be given to the process method""" """Parse input into a request form that will be given to the process method"""
pass pass
@ -132,7 +132,7 @@ class DVMTaskInterface:
"Process the data and return the result" "Process the data and return the result"
pass pass
def post_process(self, result, event): async def post_process(self, result, event):
"""Post-process the data and return the result Use default function, if not overwritten""" """Post-process the data and return the result Use default function, if not overwritten"""
return post_process_result(result, event) return post_process_result(result, event)

View File

@ -29,7 +29,7 @@ class AdvancedSearch(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -38,7 +38,7 @@ class AdvancedSearch(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
print(self.dvm_config.PRIVATE_KEY) print(self.dvm_config.PRIVATE_KEY)
@ -144,7 +144,7 @@ class AdvancedSearch(DVMTaskInterface):
await cli.shutdown() await cli.shutdown()
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -31,7 +31,7 @@ class AdvancedSearchWine(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -40,7 +40,7 @@ class AdvancedSearchWine(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
print(self.dvm_config.PRIVATE_KEY) print(self.dvm_config.PRIVATE_KEY)
@ -129,7 +129,7 @@ class AdvancedSearchWine(DVMTaskInterface):
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -36,7 +36,7 @@ class AudioGenerationSonoAI(DVMTaskInterface):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
self.base_url = 'http://localhost:3000' self.base_url = 'http://localhost:3000'
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -45,7 +45,7 @@ class AudioGenerationSonoAI(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "A popular heavy metal song about a purple Ostrich, Nostr, sung by a deep-voiced male singer, slowly and melodiously. The lyrics depict hope for a better future." prompt = "A popular heavy metal song about a purple Ostrich, Nostr, sung by a deep-voiced male singer, slowly and melodiously. The lyrics depict hope for a better future."
@ -131,7 +131,7 @@ class AudioGenerationSonoAI(DVMTaskInterface):
print(f"{data[1]['id']} ==> {data[1]['video_url']}") print(f"{data[1]['id']} ==> {data[1]['video_url']}")
break break
# sleep 5s # sleep 5s
asyncio.sleep(5.0) await asyncio.sleep(5.0)
response1 = self.get_clip(data[0]['id']) response1 = self.get_clip(data[0]['id'])
print(response1['video_url']) print(response1['video_url'])

View File

@ -61,7 +61,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
if not self.personalized: if not self.personalized:
self.result = await self.calculate_result(self.request_form) self.result = await self.calculate_result(self.request_form)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -70,7 +70,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -148,7 +148,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
len(result_list)) + " fitting events.") len(result_list)) + " fitting events.")
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -63,7 +63,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
if not self.personalized: if not self.personalized:
self.result = await self.calculate_result(self.request_form) self.result = await self.calculate_result(self.request_form)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -72,7 +72,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -145,7 +145,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -64,7 +64,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
if not self.personalized: if not self.personalized:
self.result = await self.calculate_result(self.request_form) self.result = await self.calculate_result(self.request_form)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -73,7 +73,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -198,7 +198,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -51,7 +51,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
if self.dvm_config.UPDATE_DATABASE: if self.dvm_config.UPDATE_DATABASE:
await self.sync_db() await self.sync_db()
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -60,7 +60,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event: Event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event: Event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -170,7 +170,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -73,7 +73,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
if not self.personalized: if not self.personalized:
self.result = await self.calculate_result(self.request_form) self.result = await self.calculate_result(self.request_form)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -82,7 +82,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -113,7 +113,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
else: else:
return self.result return self.result
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -65,7 +65,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
if self.dvm_config.UPDATE_DATABASE: if self.dvm_config.UPDATE_DATABASE:
await self.sync_db() await self.sync_db()
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -74,7 +74,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -100,7 +100,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
async def process(self, request_form): async def process(self, request_form):
return "I don't return results, I just update the DB." return "I don't return results, I just update the DB."
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -31,7 +31,7 @@ class MediaConverter(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -40,7 +40,7 @@ class MediaConverter(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
url = "" url = ""
media_format = "video/mp4" media_format = "video/mp4"
@ -61,7 +61,7 @@ class MediaConverter(DVMTaskInterface):
if param == "format": # check for param type if param == "format": # check for param type
media_format = tag.as_vec()[2] media_format = tag.as_vec()[2]
filepath = organize_input_media_data(url, input_type, start_time, end_time, dvm_config, client, True, filepath = await organize_input_media_data(url, input_type, start_time, end_time, dvm_config, client, True,
media_format) media_format)
options = { options = {
"filepath": filepath "filepath": filepath

View File

@ -32,7 +32,7 @@ class DiscoveryBotFarms(DVMTaskInterface):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
await self.sync_db() await self.sync_db()
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -41,7 +41,7 @@ class DiscoveryBotFarms(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
print(self.dvm_config.PRIVATE_KEY) print(self.dvm_config.PRIVATE_KEY)
@ -117,7 +117,7 @@ class DiscoveryBotFarms(DVMTaskInterface):
await cli.shutdown() await cli.shutdown()
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -34,11 +34,10 @@ class DiscoverReports(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
async def is_input_supported(self, tags, client=None, dvm_config=None):
def is_input_supported(self, tags, client=None, dvm_config=None):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -115,7 +114,8 @@ class DiscoverReports(DVMTaskInterface):
following = PublicKey.parse(tag.as_vec()[1]) following = PublicKey.parse(tag.as_vec()[1])
pubkeys.append(following) pubkeys.append(following)
ago = Timestamp.now().as_secs() - 60*60*24*int(options["since_days"]) #TODO make this an option, 180 days for now ago = Timestamp.now().as_secs() - 60 * 60 * 24 * int(
options["since_days"]) # TODO make this an option, 180 days for now
since = Timestamp.from_secs(ago) since = Timestamp.from_secs(ago)
kind1984_filter = Filter().authors(pubkeys).kind(Kind(1984)).since(since) kind1984_filter = Filter().authors(pubkeys).kind(Kind(1984)).since(since)
reports = await cli.get_events_of([kind1984_filter], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)) reports = await cli.get_events_of([kind1984_filter], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
@ -130,13 +130,13 @@ class DiscoverReports(DVMTaskInterface):
ns.dic[tag.as_vec()[1]] = 0 ns.dic[tag.as_vec()[1]] = 0
for report in reports: for report in reports:
#print(report.as_json()) # print(report.as_json())
for tag in report.tags(): for tag in report.tags():
if tag.as_vec()[0] == "p": if tag.as_vec()[0] == "p":
if len(tag.as_vec()) > 2 and tag.as_vec()[2] in reasons or len(tag.as_vec()) <= 2: if len(tag.as_vec()) > 2 and tag.as_vec()[2] in reasons or len(tag.as_vec()) <= 2:
ns.dic[tag.as_vec()[1]] += 1 ns.dic[tag.as_vec()[1]] += 1
#print(ns.dic.items()) # print(ns.dic.items())
# result = {k for (k, v) in ns.dic.items() if v > 0} # result = {k for (k, v) in ns.dic.items() if v > 0}
# result = sorted(ns.dic.items(), key=lambda x: x[1], reverse=True) # result = sorted(ns.dic.items(), key=lambda x: x[1], reverse=True)
finallist_sorted = sorted(ns.dic.items(), key=lambda x: x[1], reverse=True) finallist_sorted = sorted(ns.dic.items(), key=lambda x: x[1], reverse=True)
@ -151,7 +151,7 @@ class DiscoverReports(DVMTaskInterface):
await cli.shutdown() await cli.shutdown()
return json.dumps(bad_actors) return json.dumps(bad_actors)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':
@ -190,7 +190,6 @@ def build_example(name, identifier, admin_config):
nip89config.DTAG = check_and_set_d_tag(identifier, name, dvm_config.PRIVATE_KEY, nip89info["image"]) nip89config.DTAG = check_and_set_d_tag(identifier, name, dvm_config.PRIVATE_KEY, nip89info["image"])
nip89config.CONTENT = json.dumps(nip89info) nip89config.CONTENT = json.dumps(nip89info)
return DiscoverReports(name=name, dvm_config=dvm_config, nip89config=nip89config, return DiscoverReports(name=name, dvm_config=dvm_config, nip89config=nip89config,
admin_config=admin_config) admin_config=admin_config)

View File

@ -34,11 +34,11 @@ class DiscoverInactiveFollows(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
# no input required # no input required
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -178,7 +178,7 @@ class DiscoverInactiveFollows(DVMTaskInterface):
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -34,11 +34,11 @@ class DiscoverNonFollowers(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
# no input required # no input required
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -175,7 +175,7 @@ class DiscoverNonFollowers(DVMTaskInterface):
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -40,7 +40,7 @@ class TrendingNotesGleasonator(DVMTaskInterface):
if self.logger: if self.logger:
init_logger(LogLevel.DEBUG) init_logger(LogLevel.DEBUG)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -49,7 +49,7 @@ class TrendingNotesGleasonator(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
max_results = 200 max_results = 200
@ -104,7 +104,7 @@ class TrendingNotesGleasonator(DVMTaskInterface):
print(json.dumps(result_list)) print(json.dumps(result_list))
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -36,7 +36,7 @@ class TrendingNotesNostrBand(DVMTaskInterface):
if self.logger: if self.logger:
init_logger(LogLevel.DEBUG) init_logger(LogLevel.DEBUG)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -45,7 +45,7 @@ class TrendingNotesNostrBand(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -92,7 +92,7 @@ class TrendingNotesNostrBand(DVMTaskInterface):
print(e) print(e)
return json.dumps([]) return json.dumps([])
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -34,7 +34,7 @@ class ImageGenerationDALLE(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -52,7 +52,7 @@ class ImageGenerationDALLE(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "" prompt = ""
width = "1024" width = "1024"

View File

@ -34,7 +34,7 @@ class ImageGenerationReplicateSDXL(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -52,7 +52,7 @@ class ImageGenerationReplicateSDXL(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "" prompt = ""
width = "1024" width = "1024"

View File

@ -38,7 +38,7 @@ class ImageGenerationMLX(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -56,7 +56,7 @@ class ImageGenerationMLX(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "" prompt = ""
width = "1024" width = "1024"

View File

@ -31,7 +31,7 @@ class ImageGenerationSDXL(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -49,7 +49,7 @@ class ImageGenerationSDXL(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
request_form["trainerFilePath"] = r'modules\stablediffusionxl\stablediffusionxl.trainer' request_form["trainerFilePath"] = r'modules\stablediffusionxl\stablediffusionxl.trainer'

View File

@ -31,7 +31,7 @@ class ImageGenerationSDXLIMG2IMG(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
hasurl = False hasurl = False
hasprompt = False hasprompt = False
for tag in tags: for tag in tags:
@ -56,7 +56,7 @@ class ImageGenerationSDXLIMG2IMG(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
request_form["trainerFilePath"] = r'modules\stablediffusionxl\stablediffusionxl-img2img.trainer' request_form["trainerFilePath"] = r'modules\stablediffusionxl\stablediffusionxl-img2img.trainer'

View File

@ -30,7 +30,7 @@ class ImageInterrogator(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
hasurl = False hasurl = False
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
@ -44,7 +44,7 @@ class ImageInterrogator(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
request_form["trainerFilePath"] = r'modules\image_interrogator\image_interrogator.trainer' request_form["trainerFilePath"] = r'modules\image_interrogator\image_interrogator.trainer'
url = "" url = ""

View File

@ -30,7 +30,7 @@ class ImageUpscale(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
hasurl = False hasurl = False
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
@ -44,7 +44,7 @@ class ImageUpscale(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
request_form["trainerFilePath"] = r'modules\image_upscale\image_upscale_realesrgan.trainer' request_form["trainerFilePath"] = r'modules\image_upscale\image_upscale_realesrgan.trainer'
url = "" url = ""

View File

@ -66,7 +66,7 @@ class DiscoverPeopleWOT(DVMTaskInterface):
if not self.personalized: if not self.personalized:
self.result = await self.calculate_result(self.request_form) self.result = await self.calculate_result(self.request_form)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -75,7 +75,7 @@ class DiscoverPeopleWOT(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
@ -186,7 +186,7 @@ class DiscoverPeopleWOT(DVMTaskInterface):
len(result_list)) + " fitting events.") len(result_list)) + " fitting events.")
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -33,7 +33,7 @@ class SearchUser(DVMTaskInterface):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
await self.sync_db() await self.sync_db()
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -42,7 +42,7 @@ class SearchUser(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
self.dvm_config = dvm_config self.dvm_config = dvm_config
print(self.dvm_config.PRIVATE_KEY) print(self.dvm_config.PRIVATE_KEY)
@ -117,7 +117,7 @@ class SearchUser(DVMTaskInterface):
await cli.shutdown() await cli.shutdown()
return json.dumps(result_list) return json.dumps(result_list)
def post_process(self, result, event): async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested""" """Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags(): for tag in event.tags():
if tag.as_vec()[0] == 'output': if tag.as_vec()[0] == 'output':

View File

@ -31,7 +31,7 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -41,7 +41,7 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "" prompt = ""
collect_events = [] collect_events = []
@ -56,7 +56,7 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
# 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)
# prompt += evt.content() + "\n" # prompt += evt.content() + "\n"
elif input_type == "job": elif input_type == "job":
evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client, evt = await 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,
@ -71,13 +71,13 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
prompt = "" prompt = ""
for tag in result_list: for tag in result_list:
e_tag = Tag.parse(tag) e_tag = Tag.parse(tag)
evt = get_event_by_id(e_tag.as_vec()[1], client=client, config=dvm_config) evt = await get_event_by_id(e_tag.as_vec()[1], client=client, config=dvm_config)
prompt += evt.content() + "\n" prompt += evt.content() + "\n"
else: else:
prompt = evt.content() prompt = evt.content()
evts = get_events_by_ids(collect_events, client=client, config=dvm_config) evts = await get_events_by_ids(collect_events, client=client, config=dvm_config)
if evts is not None: if evts is not None:
for evt in evts: for evt in evts:
prompt += evt.content() + "\n" prompt += evt.content() + "\n"

View File

@ -29,7 +29,7 @@ class SummarizationUnleashedChat(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
print(tag.as_vec()) print(tag.as_vec())
@ -40,7 +40,7 @@ class SummarizationUnleashedChat(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "" prompt = ""
collect_events = [] collect_events = []
@ -56,7 +56,7 @@ class SummarizationUnleashedChat(DVMTaskInterface):
# 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)
# prompt += evt.content() + "\n" # prompt += evt.content() + "\n"
elif input_type == "job": elif input_type == "job":
evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client, evt = await 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,
@ -71,13 +71,13 @@ class SummarizationUnleashedChat(DVMTaskInterface):
prompt = "" prompt = ""
for tag in result_list: for tag in result_list:
e_tag = Tag.parse(tag) e_tag = Tag.parse(tag)
evt = get_event_by_id(e_tag.as_vec()[1], client=client, config=dvm_config) evt = await get_event_by_id(e_tag.as_vec()[1], client=client, config=dvm_config)
prompt += evt.content() + "\n" prompt += evt.content() + "\n"
else: else:
prompt = evt.content() prompt = evt.content()
evts = get_events_by_ids(collect_events, client=client, config=dvm_config) evts = await get_events_by_ids(collect_events, client=client, config=dvm_config)
if evts is not None: if evts is not None:
for evt in evts: for evt in evts:
prompt += evt.content() + "\n" prompt += evt.content() + "\n"

View File

@ -34,7 +34,7 @@ class SpeechToTextGoogle(DVMTaskInterface):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -50,7 +50,7 @@ class SpeechToTextGoogle(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
url = "" url = ""
@ -94,7 +94,7 @@ class SpeechToTextGoogle(DVMTaskInterface):
except: except:
end_time = float(tag.as_vec()[3]) end_time = float(tag.as_vec()[3])
filepath = organize_input_media_data(url, input_type, start_time, end_time, dvm_config, client, True, filepath = await organize_input_media_data(url, input_type, start_time, end_time, dvm_config, client, True,
media_format) media_format)
options = { options = {
"filepath": filepath, "filepath": filepath,

View File

@ -32,7 +32,7 @@ class TextExtractionPDF(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -41,7 +41,7 @@ class TextExtractionPDF(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
# default values # default values
@ -58,7 +58,7 @@ class TextExtractionPDF(DVMTaskInterface):
url = input_content url = input_content
# if event contains url to pdf, we checked for a pdf link before # if event contains url to pdf, we checked for a pdf link before
elif input_type == "event": elif input_type == "event":
evt = get_event_by_id(input_content, client=client, config=dvm_config) evt = await get_event_by_id(input_content, client=client, config=dvm_config)
url = re.search("(?P<url>https?://[^\s]+)", evt.content()).group("url") url = re.search("(?P<url>https?://[^\s]+)", evt.content()).group("url")
options = { options = {

View File

@ -33,7 +33,7 @@ class SpeechToTextWhisperX(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -49,7 +49,7 @@ class SpeechToTextWhisperX(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", ""), request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", ""),
"trainerFilePath": r'modules\whisperx\whisperx_transcript.trainer'} "trainerFilePath": r'modules\whisperx\whisperx_transcript.trainer'}
@ -104,7 +104,7 @@ class SpeechToTextWhisperX(DVMTaskInterface):
except: except:
end_time = float(tag.as_vec()[3]) end_time = float(tag.as_vec()[3])
filepath = organize_input_media_data(url, input_type, start_time, end_time, dvm_config, client, True, filepath = await organize_input_media_data(url, input_type, start_time, end_time, dvm_config, client, True,
media_format) media_format)
path_on_server = send_file_to_server(os.path.realpath(filepath), self.options['server']) path_on_server = send_file_to_server(os.path.realpath(filepath), self.options['server'])

View File

@ -29,7 +29,7 @@ class TextGenerationHuggingChat(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -39,7 +39,7 @@ class TextGenerationHuggingChat(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "" prompt = ""

View File

@ -29,7 +29,7 @@ class TextGenerationLLMLite(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -39,7 +39,7 @@ class TextGenerationLLMLite(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "" prompt = ""
if self.options.get("default_model") and self.options.get("default_model") != "": if self.options.get("default_model") and self.options.get("default_model") != "":

View File

@ -29,7 +29,7 @@ class TextGenerationUnleashedChat(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -39,7 +39,7 @@ class TextGenerationUnleashedChat(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "" prompt = ""
nostr_mode= True nostr_mode= True

View File

@ -37,7 +37,7 @@ class TextToSpeech(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -47,7 +47,7 @@ class TextToSpeech(DVMTaskInterface):
if input_type == "text" and len(input_value) > 250: if input_type == "text" and len(input_value) > 250:
return False return False
if input_type == "event": if input_type == "event":
evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) evt = await get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config)
if len(evt.content()) > 250: if len(evt.content()) > 250:
return False return False
elif tag.as_vec()[0] == 'param': elif tag.as_vec()[0] == 'param':
@ -58,7 +58,7 @@ class TextToSpeech(DVMTaskInterface):
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
prompt = "test" prompt = "test"
if self.options.get("input_file") and self.options.get("input_file") != "": if self.options.get("input_file") and self.options.get("input_file") != "":
@ -74,12 +74,12 @@ class TextToSpeech(DVMTaskInterface):
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": if input_type == "event":
evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) evt = await get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config)
prompt = evt.content() prompt = evt.content()
elif input_type == "text": elif input_type == "text":
prompt = tag.as_vec()[1] prompt = tag.as_vec()[1]
elif input_type == "job": elif input_type == "job":
evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client, evt = await 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],

View File

@ -31,7 +31,7 @@ class TranslationGoogle(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -42,7 +42,7 @@ class TranslationGoogle(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
text = "" text = ""
translation_lang = "en" translation_lang = "en"
@ -51,12 +51,12 @@ class TranslationGoogle(DVMTaskInterface):
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": if input_type == "event":
evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) evt = await get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config)
text = evt.content() text = evt.content()
elif input_type == "text": elif input_type == "text":
text = tag.as_vec()[1] text = tag.as_vec()[1]
elif input_type == "job": elif input_type == "job":
evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client, evt = await 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],

View File

@ -31,7 +31,7 @@ class TranslationLibre(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -42,7 +42,7 @@ class TranslationLibre(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex()} request_form = {"jobID": event.id().to_hex()}
text = "" text = ""
translation_lang = "en" translation_lang = "en"
@ -51,12 +51,12 @@ class TranslationLibre(DVMTaskInterface):
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": if input_type == "event":
evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) evt = await get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config)
text = evt.content() text = evt.content()
elif input_type == "text": elif input_type == "text":
text = tag.as_vec()[1] text = tag.as_vec()[1]
elif input_type == "job": elif input_type == "job":
evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client, evt = await 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],

View File

@ -35,7 +35,7 @@ class VideoGenerationReplicateSVD(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -44,7 +44,7 @@ class VideoGenerationReplicateSVD(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
url = "" url = ""
frames = 14 # 25 frames = 14 # 25

View File

@ -30,7 +30,7 @@ class VideoGenerationSVD(DVMTaskInterface):
admin_config: AdminConfig = None, options=None): admin_config: AdminConfig = None, options=None):
dvm_config.SCRIPT = os.path.abspath(__file__) dvm_config.SCRIPT = os.path.abspath(__file__)
def is_input_supported(self, tags, client=None, dvm_config=None): async def is_input_supported(self, tags, client=None, dvm_config=None):
for tag in tags: for tag in tags:
if tag.as_vec()[0] == 'i': if tag.as_vec()[0] == 'i':
input_value = tag.as_vec()[1] input_value = tag.as_vec()[1]
@ -39,7 +39,7 @@ class VideoGenerationSVD(DVMTaskInterface):
return False return False
return True return True
def create_request_from_nostr_event(self, event, client=None, dvm_config=None): async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")} request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
request_form["trainerFilePath"] = r'modules\stablevideodiffusion\stablevideodiffusion.trainer' request_form["trainerFilePath"] = r'modules\stablevideodiffusion\stablevideodiffusion.trainer'

View File

@ -10,7 +10,7 @@ from nostr_dvm.utils.mediasource_utils import check_source_type, media_source
from nostr_dvm.utils.nostr_utils import get_event_by_id, get_referenced_event_by_id from nostr_dvm.utils.nostr_utils import get_event_by_id, get_referenced_event_by_id
def get_task(event, client, dvm_config): async def get_task(event, client, dvm_config):
try: try:
if event.kind() == EventDefinitions.KIND_NIP90_GENERIC: # use this for events that have no id yet, inclufr j tag if event.kind() == EventDefinitions.KIND_NIP90_GENERIC: # use this for events that have no id yet, inclufr j tag
for tag in event.tags(): for tag in event.tags():
@ -41,7 +41,7 @@ def get_task(event, client, dvm_config):
else: else:
return "unknown job" return "unknown job"
elif tag.as_vec()[2] == "event": elif tag.as_vec()[2] == "event":
evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) evt = await get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config)
if evt is not None: if evt is not None:
if evt.kind() == 1063: if evt.kind() == 1063:
for tg in evt.tags(): for tg in evt.tags():
@ -68,7 +68,7 @@ def get_task(event, client, dvm_config):
has_image_tag = True has_image_tag = True
print("found image tag") print("found image tag")
elif tag.as_vec()[2] == "job": elif tag.as_vec()[2] == "job":
evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], kinds= evt = await get_referenced_event_by_id(event_id=tag.as_vec()[1], kinds=
[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT, [EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT, EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT], EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT],
@ -126,7 +126,7 @@ def is_input_supported_generic(tags, client, dvm_config) -> bool:
print("Generic input check: " + str(e)) print("Generic input check: " + str(e))
def check_task_is_supported(event: Event, client, config=None): async def check_task_is_supported(event: Event, client, config=None):
try: try:
dvm_config = config dvm_config = config
# Check for generic issues, event maformed, referenced event not found etc.. # Check for generic issues, event maformed, referenced event not found etc..
@ -134,13 +134,13 @@ def check_task_is_supported(event: Event, client, config=None):
return False, "" return False, ""
# See if current dvm supports the task # See if current dvm supports the task
task = get_task(event, client=client, dvm_config=dvm_config) task = await get_task(event, client=client, dvm_config=dvm_config)
if task not in (x.TASK for x in dvm_config.SUPPORTED_DVMS): if task not in (x.TASK for x in dvm_config.SUPPORTED_DVMS):
return False, task return False, task
# See if current dvm can handle input for given task # See if current dvm can handle input for given task
for dvm in dvm_config.SUPPORTED_DVMS: for dvm in dvm_config.SUPPORTED_DVMS:
if dvm.TASK == task: if dvm.TASK == task:
if not dvm.is_input_supported(event.tags(), client, config): if not await dvm.is_input_supported(event.tags(), client, config):
return False, task return False, task
return True, task return True, task

View File

@ -57,10 +57,10 @@ async def input_data_file_duration(event, dvm_config, client, start=0, end=0):
return 1 return 1
def organize_input_media_data(input_value, input_type, start, end, dvm_config, client, process=True, async def organize_input_media_data(input_value, input_type, start, end, dvm_config, client, process=True,
media_format="audio/mp3") -> str: media_format="audio/mp3") -> str:
if input_type == "event": # NIP94 event if input_type == "event": # NIP94 event
evt = get_event_by_id(input_value, client=client, config=dvm_config) evt = await get_event_by_id(input_value, client=client, config=dvm_config)
if evt is not None: if evt is not None:
input_value, input_type = check_nip94_event_for_media(evt, input_value, input_type) input_value, input_type = check_nip94_event_for_media(evt, input_value, input_type)

View File

@ -33,7 +33,8 @@ async def get_event_by_id(event_id: str, client: Client, config=None) -> Event |
id_filter = Filter().id(event_id).limit(1) id_filter = Filter().id(event_id).limit(1)
#events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT)) #events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
events = await get_events_async(client, id_filter, config.RELAY_TIMEOUT) events = await client.get_events_of([id_filter], timedelta(seconds=5))
if len(events) > 0: if len(events) > 0:
@ -46,7 +47,7 @@ async def get_events_async(client, filter, timeout):
return events return events
def get_events_by_ids(event_ids, client: Client, config=None) -> List | None: async def get_events_by_ids(event_ids, client: Client, config=None) -> List | None:
search_ids = [] search_ids = []
events = [] events = []
for event_id in event_ids: for event_id in event_ids:
@ -54,7 +55,7 @@ def get_events_by_ids(event_ids, client: Client, config=None) -> List | None:
if len(split) == 3: if len(split) == 3:
pk = PublicKey.from_hex(split[1]) pk = PublicKey.from_hex(split[1])
id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]]) id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]])
events = asyncio.run(get_events_async(client, id_filter, config.RELAY_TIMEOUT)) events = await client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
#events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT)) #events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
else: else:
if str(event_id).startswith('note'): if str(event_id).startswith('note'):
@ -71,7 +72,7 @@ def get_events_by_ids(event_ids, client: Client, config=None) -> List | None:
search_ids.append(event_id) search_ids.append(event_id)
id_filter = Filter().ids(search_ids) id_filter = Filter().ids(search_ids)
events = asyncio.run(get_events_async(client, id_filter, config.RELAY_TIMEOUT)) events = await client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
#events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT)) #events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
if len(events) > 0: if len(events) > 0:
@ -80,17 +81,17 @@ def get_events_by_ids(event_ids, client: Client, config=None) -> List | None:
return None return None
def get_events_by_id(event_ids: list, client: Client, config=None) -> list[Event] | None: async def get_events_by_id(event_ids: list, client: Client, config=None) -> list[Event] | None:
id_filter = Filter().ids(event_ids) id_filter = Filter().ids(event_ids)
events = asyncio.run(get_events_async(client, id_filter, config.RELAY_TIMEOUT)) #events = asyncio.run(get_events_async(client, id_filter, config.RELAY_TIMEOUT))
#events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT)) events = await client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
if len(events) > 0: if len(events) > 0:
return events return events
else: else:
return None return None
def get_referenced_event_by_id(event_id, client, dvm_config, kinds) -> Event | None: async def get_referenced_event_by_id(event_id, client, dvm_config, kinds) -> Event | None:
if kinds is None: if kinds is None:
kinds = [] kinds = []
if str(event_id).startswith('note'): if str(event_id).startswith('note'):
@ -108,8 +109,8 @@ def get_referenced_event_by_id(event_id, client, dvm_config, kinds) -> Event | N
job_id_filter = Filter().kinds(kinds).event(event_id).limit(1) job_id_filter = Filter().kinds(kinds).event(event_id).limit(1)
else: else:
job_id_filter = Filter().event(event_id).limit(1) job_id_filter = Filter().event(event_id).limit(1)
events = await client.get_events_of([job_id_filter], timedelta(seconds=dvm_config.RELAY_TIMEOUT))
events = asyncio.run(get_events_async(client, job_id_filter, dvm_config.RELAY_TIMEOUT)) #events = await get_events_async(client, job_id_filter, dvm_config.RELAY_TIMEOUT)
#events = client.get_events_of([job_id_filter], timedelta(seconds=dvm_config.RELAY_TIMEOUT)) #events = client.get_events_of([job_id_filter], timedelta(seconds=dvm_config.RELAY_TIMEOUT))
if len(events) > 0: if len(events) > 0:

View File

@ -1,6 +1,6 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
VERSION = '0.6.14' VERSION = '0.6.15'
DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines' DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines'
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information') LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')

View File

@ -86,7 +86,7 @@ async def init():
if len(events) == 0: if len(events) == 0:
response = False response = False
asyncio.sleep(1.0) await asyncio.sleep(1.0)
continue continue
else: else:
if events[0].content() == "[]": if events[0].content() == "[]":
@ -99,7 +99,7 @@ async def init():
event_ids.append(eventidob) event_ids.append(eventidob)
config = DVMConfig() config = DVMConfig()
events = get_events_by_id(event_ids, client, config) events = await get_events_by_id(event_ids, client, config)
if events is None: if events is None:
return [] return []