mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-10-03 20:52:54 +02:00
more adjustments
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import asyncio
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
|
||||
import dotenv
|
||||
from nostr_sdk import Keys, Client, NostrSigner, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt
|
||||
from nostr_sdk import Keys, Client, NostrSigner, Tag, EventBuilder, Filter, HandleNotification, Timestamp, \
|
||||
nip04_decrypt, Event
|
||||
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig
|
||||
from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
|
||||
def nostr_client_test_llm(prompt):
|
||||
async def nostr_client_test_llm(prompt):
|
||||
keys = Keys.parse(check_and_set_private_key("test_client"))
|
||||
|
||||
iTag = Tag.parse(["i", prompt, "text"])
|
||||
@@ -28,13 +30,13 @@ def nostr_client_test_llm(prompt):
|
||||
client = Client(signer)
|
||||
|
||||
for relay in relay_list:
|
||||
client.add_relay(relay)
|
||||
client.connect()
|
||||
await client.add_relay(relay)
|
||||
await client.connect()
|
||||
config = DVMConfig
|
||||
send_event(event, client=client, dvm_config=config)
|
||||
await send_event(event, client=client, dvm_config=config)
|
||||
return event.as_json()
|
||||
|
||||
def nostr_client():
|
||||
async def nostr_client():
|
||||
keys = Keys.parse(check_and_set_private_key("test_client"))
|
||||
sk = keys.secret_key()
|
||||
pk = keys.public_key()
|
||||
@@ -42,28 +44,28 @@ def nostr_client():
|
||||
client = Client(keys)
|
||||
dvmconfig = DVMConfig()
|
||||
for relay in dvmconfig.RELAY_LIST:
|
||||
client.add_relay(relay)
|
||||
client.connect()
|
||||
await client.add_relay(relay)
|
||||
await client.connect()
|
||||
|
||||
dm_zap_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_DM,
|
||||
EventDefinitions.KIND_ZAP]).since(
|
||||
Timestamp.now()) # events to us specific
|
||||
dvm_filter = (Filter().kinds([EventDefinitions.KIND_NIP90_RESULT_GENERATE_TEXT,
|
||||
EventDefinitions.KIND_FEEDBACK]).since(Timestamp.now())) # public events
|
||||
client.subscribe([dm_zap_filter, dvm_filter])
|
||||
await client.subscribe([dm_zap_filter, dvm_filter])
|
||||
|
||||
|
||||
nostr_client_test_llm("Tell me a joke about a purple Ostrich!")
|
||||
await nostr_client_test_llm("Tell me a joke about a purple Ostrich!")
|
||||
print("Sending Job Request")
|
||||
|
||||
|
||||
#nostr_client_test_image_private("a beautiful ostrich watching the sunset")
|
||||
class NotificationHandler(HandleNotification):
|
||||
def handle(self, relay_url, event):
|
||||
def handle(self, relay_url, subscription_id, event: Event):
|
||||
print(f"Received new event from {relay_url}: {event.as_json()}")
|
||||
if event.kind() == 7000:
|
||||
print("[Nostr Client]: " + event.as_json())
|
||||
elif 6000 < event.kind() < 6999:
|
||||
elif 6000 < event.kind().as_u64() < 6999:
|
||||
print("[Nostr Client]: " + event.as_json())
|
||||
print("[Nostr Client]: " + event.content())
|
||||
|
||||
@@ -75,12 +77,12 @@ def nostr_client():
|
||||
print("[Nostr Client]: " + f"Received new zap:")
|
||||
print(event.as_json())
|
||||
|
||||
def handle_msg(self, relay_url, msg):
|
||||
async def handle_msg(self, relay_url, msg):
|
||||
return
|
||||
|
||||
client.handle_notifications(NotificationHandler())
|
||||
asyncio.create_task(client.handle_notifications(NotificationHandler()))
|
||||
while True:
|
||||
time.sleep(5.0)
|
||||
await asyncio.sleep(5.0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -92,5 +94,5 @@ if __name__ == '__main__':
|
||||
else:
|
||||
raise FileNotFoundError(f'.env file not found at {env_path} ')
|
||||
|
||||
nostr_dvm_thread = Thread(target=nostr_client())
|
||||
nostr_dvm_thread.start()
|
||||
asyncio.run(nostr_client())
|
||||
|
||||
|
Reference in New Issue
Block a user