diff --git a/nostr_dvm/dvm.py b/nostr_dvm/dvm.py index 2a5afea..01c4d15 100644 --- a/nostr_dvm/dvm.py +++ b/nostr_dvm/dvm.py @@ -1,16 +1,12 @@ import asyncio import json import os -import subprocess -import threading from datetime import timedelta from sys import platform from nostr_sdk import PublicKey, Keys, Client, Tag, Event, EventBuilder, Filter, HandleNotification, Timestamp, \ init_logger, LogLevel, Options, nip04_encrypt, NostrSigner, Kind, RelayLimits -import time - from nostr_dvm.utils.definitions import EventDefinitions, RequiredJobToWatch, JobToWatch from nostr_dvm.utils.dvmconfig import DVMConfig from nostr_dvm.utils.admin_utils import admin_make_database_updates, AdminConfig @@ -115,7 +111,7 @@ class DVM: return # 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) # if task is supported, continue, else do nothing. if task_supported: @@ -306,7 +302,7 @@ class DVM: if tag.as_vec()[0] == 'amount': amount = int(float(tag.as_vec()[1]) / 1000) 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: job_event = check_and_decrypt_tags(job_event, self.dvm_config) if job_event is None: @@ -326,7 +322,7 @@ class DVM: 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) if job_event is not None and task_supported: 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)) 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: return False @@ -395,7 +391,7 @@ class DVM: input = tag.as_vec()[1] input_type = tag.as_vec()[2] 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, dvm_config=dvmconfig) if evt is None: @@ -434,11 +430,11 @@ class DVM: await send_nostr_reply_event(data, original_event.as_json()) 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: if task == dvm.TASK: 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()) except Exception as e: print(e) @@ -515,7 +511,7 @@ class DVM: content=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) 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()) 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: result = "" try: 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: python_location = "/bin/python" @@ -689,7 +685,7 @@ class DVM: # We install locally in these cases for now result = await dvm.process(request_form) 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()) except Exception as e: print(bcolors.RED + "[" + self.dvm_config.NIP89.NAME + "] Error: " + str( diff --git a/nostr_dvm/interfaces/dvmtaskinterface.py b/nostr_dvm/interfaces/dvmtaskinterface.py index 549685b..bc36330 100644 --- a/nostr_dvm/interfaces/dvmtaskinterface.py +++ b/nostr_dvm/interfaces/dvmtaskinterface.py @@ -120,11 +120,11 @@ class DVMTaskInterface: nip89.CONTENT = nip89config.CONTENT 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.""" 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""" pass @@ -132,7 +132,7 @@ class DVMTaskInterface: "Process the data and return the result" 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""" return post_process_result(result, event) diff --git a/nostr_dvm/tasks/advanced_search.py b/nostr_dvm/tasks/advanced_search.py index 7990d6e..685b75d 100644 --- a/nostr_dvm/tasks/advanced_search.py +++ b/nostr_dvm/tasks/advanced_search.py @@ -29,7 +29,7 @@ class AdvancedSearch(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -38,7 +38,7 @@ class AdvancedSearch(DVMTaskInterface): return False 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 print(self.dvm_config.PRIVATE_KEY) @@ -144,7 +144,7 @@ class AdvancedSearch(DVMTaskInterface): await cli.shutdown() 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/advanced_search_wine.py b/nostr_dvm/tasks/advanced_search_wine.py index 1bb9060..a72c820 100644 --- a/nostr_dvm/tasks/advanced_search_wine.py +++ b/nostr_dvm/tasks/advanced_search_wine.py @@ -31,7 +31,7 @@ class AdvancedSearchWine(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -40,7 +40,7 @@ class AdvancedSearchWine(DVMTaskInterface): return False 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 print(self.dvm_config.PRIVATE_KEY) @@ -129,7 +129,7 @@ class AdvancedSearchWine(DVMTaskInterface): 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/audiogeneration_suno_ai.py b/nostr_dvm/tasks/audiogeneration_suno_ai.py index 4f755d8..f5703ed 100644 --- a/nostr_dvm/tasks/audiogeneration_suno_ai.py +++ b/nostr_dvm/tasks/audiogeneration_suno_ai.py @@ -36,7 +36,7 @@ class AudioGenerationSonoAI(DVMTaskInterface): dvm_config.SCRIPT = os.path.abspath(__file__) 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -45,7 +45,7 @@ class AudioGenerationSonoAI(DVMTaskInterface): return False 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(" ", "")} 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']}") break # sleep 5s - asyncio.sleep(5.0) + await asyncio.sleep(5.0) response1 = self.get_clip(data[0]['id']) print(response1['video_url']) diff --git a/nostr_dvm/tasks/content_discovery_currently_latest_longform.py b/nostr_dvm/tasks/content_discovery_currently_latest_longform.py index 18a0d06..2479884 100644 --- a/nostr_dvm/tasks/content_discovery_currently_latest_longform.py +++ b/nostr_dvm/tasks/content_discovery_currently_latest_longform.py @@ -61,7 +61,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface): if not self.personalized: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -70,7 +70,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface): return False 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 request_form = {"jobID": event.id().to_hex()} @@ -148,7 +148,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface): len(result_list)) + " fitting events.") 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/content_discovery_currently_popular.py b/nostr_dvm/tasks/content_discovery_currently_popular.py index b0603c1..b16fc98 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular.py @@ -63,7 +63,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface): if not self.personalized: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -72,7 +72,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface): return False 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 request_form = {"jobID": event.id().to_hex()} @@ -145,7 +145,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface): 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py b/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py index 6e4e7ac..d215063 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py @@ -64,7 +64,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface): if not self.personalized: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -73,7 +73,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface): return False 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 request_form = {"jobID": event.id().to_hex()} @@ -198,7 +198,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface): 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_followers.py b/nostr_dvm/tasks/content_discovery_currently_popular_followers.py index f614890..224cae3 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_followers.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_followers.py @@ -51,7 +51,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface): if self.dvm_config.UPDATE_DATABASE: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -60,7 +60,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface): return False 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 request_form = {"jobID": event.id().to_hex()} @@ -170,7 +170,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface): 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_topic.py b/nostr_dvm/tasks/content_discovery_currently_popular_topic.py index 75b317c..8454205 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_topic.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_topic.py @@ -73,7 +73,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface): if not self.personalized: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -82,7 +82,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface): return False 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 request_form = {"jobID": event.id().to_hex()} @@ -113,7 +113,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface): else: 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/content_discovery_update_db_only.py b/nostr_dvm/tasks/content_discovery_update_db_only.py index 86f5039..3045831 100644 --- a/nostr_dvm/tasks/content_discovery_update_db_only.py +++ b/nostr_dvm/tasks/content_discovery_update_db_only.py @@ -65,7 +65,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): if self.dvm_config.UPDATE_DATABASE: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -74,7 +74,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): return False 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 request_form = {"jobID": event.id().to_hex()} @@ -100,7 +100,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): async def process(self, request_form): 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/convert_media.py b/nostr_dvm/tasks/convert_media.py index ee2a9ed..0156285 100644 --- a/nostr_dvm/tasks/convert_media.py +++ b/nostr_dvm/tasks/convert_media.py @@ -31,7 +31,7 @@ class MediaConverter(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -40,7 +40,7 @@ class MediaConverter(DVMTaskInterface): return False 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()} url = "" media_format = "video/mp4" @@ -61,7 +61,7 @@ class MediaConverter(DVMTaskInterface): if param == "format": # check for param type 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) options = { "filepath": filepath diff --git a/nostr_dvm/tasks/discovery_bot_farms.py b/nostr_dvm/tasks/discovery_bot_farms.py index 716f780..e9ec17e 100644 --- a/nostr_dvm/tasks/discovery_bot_farms.py +++ b/nostr_dvm/tasks/discovery_bot_farms.py @@ -32,7 +32,7 @@ class DiscoveryBotFarms(DVMTaskInterface): dvm_config.SCRIPT = os.path.abspath(__file__) 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -41,7 +41,7 @@ class DiscoveryBotFarms(DVMTaskInterface): return False 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 print(self.dvm_config.PRIVATE_KEY) @@ -117,7 +117,7 @@ class DiscoveryBotFarms(DVMTaskInterface): await cli.shutdown() 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/discovery_censor_wot.py b/nostr_dvm/tasks/discovery_censor_wot.py index e112afa..1c8df34 100644 --- a/nostr_dvm/tasks/discovery_censor_wot.py +++ b/nostr_dvm/tasks/discovery_censor_wot.py @@ -34,11 +34,10 @@ class DiscoverReports(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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): 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 request_form = {"jobID": event.id().to_hex()} @@ -115,7 +114,8 @@ class DiscoverReports(DVMTaskInterface): following = PublicKey.parse(tag.as_vec()[1]) 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) 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)) @@ -130,13 +130,13 @@ class DiscoverReports(DVMTaskInterface): ns.dic[tag.as_vec()[1]] = 0 for report in reports: - #print(report.as_json()) + # print(report.as_json()) for tag in report.tags(): 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: 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 = 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() 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""" for tag in event.tags(): 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.CONTENT = json.dumps(nip89info) - return DiscoverReports(name=name, dvm_config=dvm_config, nip89config=nip89config, admin_config=admin_config) diff --git a/nostr_dvm/tasks/discovery_inactive_follows.py b/nostr_dvm/tasks/discovery_inactive_follows.py index 67472b5..4e8fa59 100644 --- a/nostr_dvm/tasks/discovery_inactive_follows.py +++ b/nostr_dvm/tasks/discovery_inactive_follows.py @@ -34,11 +34,11 @@ class DiscoverInactiveFollows(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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 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 request_form = {"jobID": event.id().to_hex()} @@ -178,7 +178,7 @@ class DiscoverInactiveFollows(DVMTaskInterface): 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/discovery_nonfollowers.py b/nostr_dvm/tasks/discovery_nonfollowers.py index 0b173c1..7844d54 100644 --- a/nostr_dvm/tasks/discovery_nonfollowers.py +++ b/nostr_dvm/tasks/discovery_nonfollowers.py @@ -34,11 +34,11 @@ class DiscoverNonFollowers(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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 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 request_form = {"jobID": event.id().to_hex()} @@ -175,7 +175,7 @@ class DiscoverNonFollowers(DVMTaskInterface): 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/discovery_trending_notes_gleasonator.py b/nostr_dvm/tasks/discovery_trending_notes_gleasonator.py index 8fffe9a..0570b24 100644 --- a/nostr_dvm/tasks/discovery_trending_notes_gleasonator.py +++ b/nostr_dvm/tasks/discovery_trending_notes_gleasonator.py @@ -40,7 +40,7 @@ class TrendingNotesGleasonator(DVMTaskInterface): if self.logger: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -49,7 +49,7 @@ class TrendingNotesGleasonator(DVMTaskInterface): return False 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()} max_results = 200 @@ -104,7 +104,7 @@ class TrendingNotesGleasonator(DVMTaskInterface): print(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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/discovery_trending_notes_nostrband.py b/nostr_dvm/tasks/discovery_trending_notes_nostrband.py index e9d4970..ddd79bc 100644 --- a/nostr_dvm/tasks/discovery_trending_notes_nostrband.py +++ b/nostr_dvm/tasks/discovery_trending_notes_nostrband.py @@ -36,7 +36,7 @@ class TrendingNotesNostrBand(DVMTaskInterface): if self.logger: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -45,7 +45,7 @@ class TrendingNotesNostrBand(DVMTaskInterface): return False 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 request_form = {"jobID": event.id().to_hex()} @@ -92,7 +92,7 @@ class TrendingNotesNostrBand(DVMTaskInterface): print(e) 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/imagegeneration_openai_dalle.py b/nostr_dvm/tasks/imagegeneration_openai_dalle.py index 5323d3b..5516de1 100644 --- a/nostr_dvm/tasks/imagegeneration_openai_dalle.py +++ b/nostr_dvm/tasks/imagegeneration_openai_dalle.py @@ -34,7 +34,7 @@ class ImageGenerationDALLE(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -52,7 +52,7 @@ class ImageGenerationDALLE(DVMTaskInterface): 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(" ", "")} prompt = "" width = "1024" diff --git a/nostr_dvm/tasks/imagegeneration_replicate_sdxl.py b/nostr_dvm/tasks/imagegeneration_replicate_sdxl.py index 6199543..7b60a76 100644 --- a/nostr_dvm/tasks/imagegeneration_replicate_sdxl.py +++ b/nostr_dvm/tasks/imagegeneration_replicate_sdxl.py @@ -34,7 +34,7 @@ class ImageGenerationReplicateSDXL(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -52,7 +52,7 @@ class ImageGenerationReplicateSDXL(DVMTaskInterface): 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(" ", "")} prompt = "" width = "1024" diff --git a/nostr_dvm/tasks/imagegeneration_sd21_mlx.py b/nostr_dvm/tasks/imagegeneration_sd21_mlx.py index 053e241..c7e9e7d 100644 --- a/nostr_dvm/tasks/imagegeneration_sd21_mlx.py +++ b/nostr_dvm/tasks/imagegeneration_sd21_mlx.py @@ -38,7 +38,7 @@ class ImageGenerationMLX(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -56,7 +56,7 @@ class ImageGenerationMLX(DVMTaskInterface): 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(" ", "")} prompt = "" width = "1024" diff --git a/nostr_dvm/tasks/imagegeneration_sdxl.py b/nostr_dvm/tasks/imagegeneration_sdxl.py index 069bae1..c0d20e0 100644 --- a/nostr_dvm/tasks/imagegeneration_sdxl.py +++ b/nostr_dvm/tasks/imagegeneration_sdxl.py @@ -31,7 +31,7 @@ class ImageGenerationSDXL(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -49,7 +49,7 @@ class ImageGenerationSDXL(DVMTaskInterface): 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["trainerFilePath"] = r'modules\stablediffusionxl\stablediffusionxl.trainer' diff --git a/nostr_dvm/tasks/imagegeneration_sdxlimg2img.py b/nostr_dvm/tasks/imagegeneration_sdxlimg2img.py index 0246848..73d8fa6 100644 --- a/nostr_dvm/tasks/imagegeneration_sdxlimg2img.py +++ b/nostr_dvm/tasks/imagegeneration_sdxlimg2img.py @@ -31,7 +31,7 @@ class ImageGenerationSDXLIMG2IMG(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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 hasprompt = False for tag in tags: @@ -56,7 +56,7 @@ class ImageGenerationSDXLIMG2IMG(DVMTaskInterface): 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["trainerFilePath"] = r'modules\stablediffusionxl\stablediffusionxl-img2img.trainer' diff --git a/nostr_dvm/tasks/imageinterrogator.py b/nostr_dvm/tasks/imageinterrogator.py index 9c3d62b..8e42c92 100644 --- a/nostr_dvm/tasks/imageinterrogator.py +++ b/nostr_dvm/tasks/imageinterrogator.py @@ -30,7 +30,7 @@ class ImageInterrogator(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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 for tag in tags: if tag.as_vec()[0] == 'i': @@ -44,7 +44,7 @@ class ImageInterrogator(DVMTaskInterface): 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["trainerFilePath"] = r'modules\image_interrogator\image_interrogator.trainer' url = "" diff --git a/nostr_dvm/tasks/imageupscale.py b/nostr_dvm/tasks/imageupscale.py index 26d89c5..7fef1ef 100644 --- a/nostr_dvm/tasks/imageupscale.py +++ b/nostr_dvm/tasks/imageupscale.py @@ -30,7 +30,7 @@ class ImageUpscale(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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 for tag in tags: if tag.as_vec()[0] == 'i': @@ -44,7 +44,7 @@ class ImageUpscale(DVMTaskInterface): 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["trainerFilePath"] = r'modules\image_upscale\image_upscale_realesrgan.trainer' url = "" diff --git a/nostr_dvm/tasks/people_discovery_wot.py b/nostr_dvm/tasks/people_discovery_wot.py index bde2ea3..cc5be48 100644 --- a/nostr_dvm/tasks/people_discovery_wot.py +++ b/nostr_dvm/tasks/people_discovery_wot.py @@ -66,7 +66,7 @@ class DiscoverPeopleWOT(DVMTaskInterface): if not self.personalized: 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -75,7 +75,7 @@ class DiscoverPeopleWOT(DVMTaskInterface): return False 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 request_form = {"jobID": event.id().to_hex()} @@ -186,7 +186,7 @@ class DiscoverPeopleWOT(DVMTaskInterface): len(result_list)) + " fitting events.") 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/search_users.py b/nostr_dvm/tasks/search_users.py index a306e92..253264e 100644 --- a/nostr_dvm/tasks/search_users.py +++ b/nostr_dvm/tasks/search_users.py @@ -33,7 +33,7 @@ class SearchUser(DVMTaskInterface): dvm_config.SCRIPT = os.path.abspath(__file__) 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -42,7 +42,7 @@ class SearchUser(DVMTaskInterface): return False 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 print(self.dvm_config.PRIVATE_KEY) @@ -117,7 +117,7 @@ class SearchUser(DVMTaskInterface): await cli.shutdown() 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""" for tag in event.tags(): if tag.as_vec()[0] == 'output': diff --git a/nostr_dvm/tasks/summarization_huggingchat.py b/nostr_dvm/tasks/summarization_huggingchat.py index 36101b8..6f74cf0 100644 --- a/nostr_dvm/tasks/summarization_huggingchat.py +++ b/nostr_dvm/tasks/summarization_huggingchat.py @@ -31,7 +31,7 @@ class TextSummarizationHuggingChat(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -41,7 +41,7 @@ class TextSummarizationHuggingChat(DVMTaskInterface): 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(" ", "")} prompt = "" collect_events = [] @@ -56,7 +56,7 @@ class TextSummarizationHuggingChat(DVMTaskInterface): # evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) # prompt += evt.content() + "\n" 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, EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT, EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT, @@ -71,13 +71,13 @@ class TextSummarizationHuggingChat(DVMTaskInterface): prompt = "" for tag in result_list: 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" else: 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: for evt in evts: prompt += evt.content() + "\n" diff --git a/nostr_dvm/tasks/summarization_unleashed_chat.py b/nostr_dvm/tasks/summarization_unleashed_chat.py index ed9d0d3..8e9eaf0 100644 --- a/nostr_dvm/tasks/summarization_unleashed_chat.py +++ b/nostr_dvm/tasks/summarization_unleashed_chat.py @@ -29,7 +29,7 @@ class SummarizationUnleashedChat(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': print(tag.as_vec()) @@ -40,7 +40,7 @@ class SummarizationUnleashedChat(DVMTaskInterface): 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(" ", "")} prompt = "" collect_events = [] @@ -56,7 +56,7 @@ class SummarizationUnleashedChat(DVMTaskInterface): # evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) # prompt += evt.content() + "\n" 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, EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT, EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT, @@ -71,13 +71,13 @@ class SummarizationUnleashedChat(DVMTaskInterface): prompt = "" for tag in result_list: 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" else: 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: for evt in evts: prompt += evt.content() + "\n" diff --git a/nostr_dvm/tasks/textextraction_google.py b/nostr_dvm/tasks/textextraction_google.py index b2ebf15..a6750e7 100644 --- a/nostr_dvm/tasks/textextraction_google.py +++ b/nostr_dvm/tasks/textextraction_google.py @@ -34,7 +34,7 @@ class SpeechToTextGoogle(DVMTaskInterface): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -50,7 +50,7 @@ class SpeechToTextGoogle(DVMTaskInterface): 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(" ", "")} url = "" @@ -94,7 +94,7 @@ class SpeechToTextGoogle(DVMTaskInterface): except: 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) options = { "filepath": filepath, diff --git a/nostr_dvm/tasks/textextraction_pdf.py b/nostr_dvm/tasks/textextraction_pdf.py index e1933f9..4f23f1f 100644 --- a/nostr_dvm/tasks/textextraction_pdf.py +++ b/nostr_dvm/tasks/textextraction_pdf.py @@ -32,7 +32,7 @@ class TextExtractionPDF(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -41,7 +41,7 @@ class TextExtractionPDF(DVMTaskInterface): return False 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()} # default values @@ -58,7 +58,7 @@ class TextExtractionPDF(DVMTaskInterface): url = input_content # if event contains url to pdf, we checked for a pdf link before 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("(?Phttps?://[^\s]+)", evt.content()).group("url") options = { diff --git a/nostr_dvm/tasks/textextraction_whisperx.py b/nostr_dvm/tasks/textextraction_whisperx.py index 7b1e90f..490d6a0 100644 --- a/nostr_dvm/tasks/textextraction_whisperx.py +++ b/nostr_dvm/tasks/textextraction_whisperx.py @@ -33,7 +33,7 @@ class SpeechToTextWhisperX(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -49,7 +49,7 @@ class SpeechToTextWhisperX(DVMTaskInterface): 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(" ", ""), "trainerFilePath": r'modules\whisperx\whisperx_transcript.trainer'} @@ -104,7 +104,7 @@ class SpeechToTextWhisperX(DVMTaskInterface): except: 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) path_on_server = send_file_to_server(os.path.realpath(filepath), self.options['server']) diff --git a/nostr_dvm/tasks/textgeneration_huggingchat.py b/nostr_dvm/tasks/textgeneration_huggingchat.py index ec95c83..20a052d 100644 --- a/nostr_dvm/tasks/textgeneration_huggingchat.py +++ b/nostr_dvm/tasks/textgeneration_huggingchat.py @@ -29,7 +29,7 @@ class TextGenerationHuggingChat(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -39,7 +39,7 @@ class TextGenerationHuggingChat(DVMTaskInterface): 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(" ", "")} prompt = "" diff --git a/nostr_dvm/tasks/textgeneration_llmlite.py b/nostr_dvm/tasks/textgeneration_llmlite.py index 494012d..cb19a18 100644 --- a/nostr_dvm/tasks/textgeneration_llmlite.py +++ b/nostr_dvm/tasks/textgeneration_llmlite.py @@ -29,7 +29,7 @@ class TextGenerationLLMLite(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -39,7 +39,7 @@ class TextGenerationLLMLite(DVMTaskInterface): 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(" ", "")} prompt = "" if self.options.get("default_model") and self.options.get("default_model") != "": diff --git a/nostr_dvm/tasks/textgeneration_unleashed_chat.py b/nostr_dvm/tasks/textgeneration_unleashed_chat.py index 9d407ac..04c60a4 100644 --- a/nostr_dvm/tasks/textgeneration_unleashed_chat.py +++ b/nostr_dvm/tasks/textgeneration_unleashed_chat.py @@ -29,7 +29,7 @@ class TextGenerationUnleashedChat(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -39,7 +39,7 @@ class TextGenerationUnleashedChat(DVMTaskInterface): 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(" ", "")} prompt = "" nostr_mode= True diff --git a/nostr_dvm/tasks/texttospeech.py b/nostr_dvm/tasks/texttospeech.py index dfaa112..1af6432 100644 --- a/nostr_dvm/tasks/texttospeech.py +++ b/nostr_dvm/tasks/texttospeech.py @@ -37,7 +37,7 @@ class TextToSpeech(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -47,7 +47,7 @@ class TextToSpeech(DVMTaskInterface): if input_type == "text" and len(input_value) > 250: return False 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: return False elif tag.as_vec()[0] == 'param': @@ -58,7 +58,7 @@ class TextToSpeech(DVMTaskInterface): 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(" ", "")} prompt = "test" 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': input_type = tag.as_vec()[2] 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() elif input_type == "text": prompt = tag.as_vec()[1] 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, EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT, EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT], diff --git a/nostr_dvm/tasks/translation_google.py b/nostr_dvm/tasks/translation_google.py index f4e6209..b293da9 100644 --- a/nostr_dvm/tasks/translation_google.py +++ b/nostr_dvm/tasks/translation_google.py @@ -31,7 +31,7 @@ class TranslationGoogle(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -42,7 +42,7 @@ class TranslationGoogle(DVMTaskInterface): return False 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()} text = "" translation_lang = "en" @@ -51,12 +51,12 @@ class TranslationGoogle(DVMTaskInterface): if tag.as_vec()[0] == 'i': input_type = tag.as_vec()[2] 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() elif input_type == "text": text = tag.as_vec()[1] 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, EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT, EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT], diff --git a/nostr_dvm/tasks/translation_libretranslate.py b/nostr_dvm/tasks/translation_libretranslate.py index 8daddba..a97308d 100644 --- a/nostr_dvm/tasks/translation_libretranslate.py +++ b/nostr_dvm/tasks/translation_libretranslate.py @@ -31,7 +31,7 @@ class TranslationLibre(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -42,7 +42,7 @@ class TranslationLibre(DVMTaskInterface): return False 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()} text = "" translation_lang = "en" @@ -51,12 +51,12 @@ class TranslationLibre(DVMTaskInterface): if tag.as_vec()[0] == 'i': input_type = tag.as_vec()[2] 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() elif input_type == "text": text = tag.as_vec()[1] 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, EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT, EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT], diff --git a/nostr_dvm/tasks/videogeneration_replicate_svd.py b/nostr_dvm/tasks/videogeneration_replicate_svd.py index 5e3f514..3e196ca 100644 --- a/nostr_dvm/tasks/videogeneration_replicate_svd.py +++ b/nostr_dvm/tasks/videogeneration_replicate_svd.py @@ -35,7 +35,7 @@ class VideoGenerationReplicateSVD(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -44,7 +44,7 @@ class VideoGenerationReplicateSVD(DVMTaskInterface): return False 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(" ", "")} url = "" frames = 14 # 25 diff --git a/nostr_dvm/tasks/videogeneration_svd.py b/nostr_dvm/tasks/videogeneration_svd.py index b668251..8767f95 100644 --- a/nostr_dvm/tasks/videogeneration_svd.py +++ b/nostr_dvm/tasks/videogeneration_svd.py @@ -30,7 +30,7 @@ class VideoGenerationSVD(DVMTaskInterface): admin_config: AdminConfig = None, options=None): 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: if tag.as_vec()[0] == 'i': input_value = tag.as_vec()[1] @@ -39,7 +39,7 @@ class VideoGenerationSVD(DVMTaskInterface): return False 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["trainerFilePath"] = r'modules\stablevideodiffusion\stablevideodiffusion.trainer' diff --git a/nostr_dvm/utils/backend_utils.py b/nostr_dvm/utils/backend_utils.py index ac28697..0a80347 100644 --- a/nostr_dvm/utils/backend_utils.py +++ b/nostr_dvm/utils/backend_utils.py @@ -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 -def get_task(event, client, dvm_config): +async def get_task(event, client, dvm_config): try: if event.kind() == EventDefinitions.KIND_NIP90_GENERIC: # use this for events that have no id yet, inclufr j tag for tag in event.tags(): @@ -41,7 +41,7 @@ def get_task(event, client, dvm_config): else: return "unknown job" 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.kind() == 1063: for tg in evt.tags(): @@ -68,7 +68,7 @@ def get_task(event, client, dvm_config): has_image_tag = True print("found image tag") 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_TRANSLATE_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)) -def check_task_is_supported(event: Event, client, config=None): +async def check_task_is_supported(event: Event, client, config=None): try: dvm_config = config # 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, "" # 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): return False, task # See if current dvm can handle input for given task for dvm in dvm_config.SUPPORTED_DVMS: 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 True, task diff --git a/nostr_dvm/utils/mediasource_utils.py b/nostr_dvm/utils/mediasource_utils.py index 635e901..74223fc 100644 --- a/nostr_dvm/utils/mediasource_utils.py +++ b/nostr_dvm/utils/mediasource_utils.py @@ -57,10 +57,10 @@ async def input_data_file_duration(event, dvm_config, client, start=0, end=0): 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: 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: input_value, input_type = check_nip94_event_for_media(evt, input_value, input_type) diff --git a/nostr_dvm/utils/nostr_utils.py b/nostr_dvm/utils/nostr_utils.py index f93ca64..44efc61 100644 --- a/nostr_dvm/utils/nostr_utils.py +++ b/nostr_dvm/utils/nostr_utils.py @@ -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) #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: @@ -46,7 +47,7 @@ async def get_events_async(client, filter, timeout): 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 = [] events = [] 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: pk = PublicKey.from_hex(split[1]) 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)) else: 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) 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)) if len(events) > 0: @@ -80,17 +81,17 @@ def get_events_by_ids(event_ids, client: Client, config=None) -> List | 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) - 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 = asyncio.run(get_events_async(client, id_filter, config.RELAY_TIMEOUT)) + events = await client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT)) if len(events) > 0: return events else: 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: kinds = [] 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) else: job_id_filter = Filter().event(event_id).limit(1) - - events = asyncio.run(get_events_async(client, job_id_filter, dvm_config.RELAY_TIMEOUT)) + events = await client.get_events_of([job_id_filter], timedelta(seconds=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)) if len(events) > 0: diff --git a/setup.py b/setup.py index 91b31ee..4d2bd3d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ 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' LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information') diff --git a/tests/gui/nicegui/nostrAI_search_client.py b/tests/gui/nicegui/nostrAI_search_client.py index 8996552..3588d1d 100644 --- a/tests/gui/nicegui/nostrAI_search_client.py +++ b/tests/gui/nicegui/nostrAI_search_client.py @@ -86,7 +86,7 @@ async def init(): if len(events) == 0: response = False - asyncio.sleep(1.0) + await asyncio.sleep(1.0) continue else: if events[0].content() == "[]": @@ -99,7 +99,7 @@ async def init(): event_ids.append(eventidob) 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: return []