From 79af336a7cb49769498d9b9a736d005dfadfbccf Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Sun, 15 Sep 2024 11:48:02 +0200 Subject: [PATCH] fixes for noogle and new sdk --- nostr_dvm/dvm.py | 2 +- nostr_dvm/utils/nostr_utils.py | 3 +- tests/discovery.py | 46 ++++-- tests/test_dvm_client.py | 6 +- ui/noogle/src/components/FilterGeneration.vue | 7 +- ui/noogle/src/components/ImageGeneration.vue | 138 +++++++++--------- ui/noogle/src/components/Login.vue | 25 +++- ui/noogle/src/components/Nip89view.vue | 2 +- .../components/RecommendationGeneration.vue | 9 +- ui/noogle/src/components/Search.vue | 7 +- .../components/SummarizationGeneration.vue | 7 +- 11 files changed, 157 insertions(+), 95 deletions(-) diff --git a/nostr_dvm/dvm.py b/nostr_dvm/dvm.py index 8255ce2..3b4f3b0 100644 --- a/nostr_dvm/dvm.py +++ b/nostr_dvm/dvm.py @@ -139,7 +139,7 @@ class DVM: return if self.dvm_config.LOGLEVEL.value >= LogLevel.INFO.value: print( - bcolors.MAGENTA + "[" + self.dvm_config.NIP89.NAME + "] Received new Request: " + task + " from " + user.name + " (" + user.npub + ")" + bcolors.ENDC) + bcolors.MAGENTA + "[" + self.dvm_config.NIP89.NAME + "] Received new Request: " + task + " from " + user.name + " (" + PublicKey.parse(user.npub).to_bech32() + ")" + bcolors.ENDC) duration = await input_data_file_duration(nip90_event, dvm_config=self.dvm_config, client=self.client) amount = get_amount_per_task(task, self.dvm_config, duration) if amount is None: diff --git a/nostr_dvm/utils/nostr_utils.py b/nostr_dvm/utils/nostr_utils.py index 646ae79..389d942 100644 --- a/nostr_dvm/utils/nostr_utils.py +++ b/nostr_dvm/utils/nostr_utils.py @@ -239,8 +239,7 @@ async def send_event_outbox(event: Event, client, dvm_config) -> EventId: relays = await get_main_relays(event, client, dvm_config) for relay in relays: - opts = RelayOptions().ping(False) - await outboxclient.add_relay_with_opts(relay, opts) + await outboxclient.add_relay(relay) try: await outboxclient.connect() event_id = await outboxclient.send_event(event) diff --git a/tests/discovery.py b/tests/discovery.py index 6710256..4f736cb 100644 --- a/tests/discovery.py +++ b/tests/discovery.py @@ -41,10 +41,10 @@ use_logger = True log_level = LogLevel.INFO -RECONCILE_DB_RELAY_LIST = [ "wss://relay.damus.io", "wss://relay.primal.net"] +RECONCILE_DB_RELAY_LIST = [ "wss://relay.damus.io", "wss://relay.primal.net", "wss://nostr.oxtr.dev"] RELAY_LIST = ["wss://relay.primal.net", - "wss://nostr.mom", + "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.net" ] @@ -415,12 +415,12 @@ def build_example_popular_non_followers(name, identifier, admin_config, options, dvm_config.UPDATE_DATABASE = update_db dvm_config.DATABASE = database # Activate these to use a subscription based model instead - dvm_config.FIX_COST = cost + dvm_config.FIX_COST = 10 dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg dvm_config.AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_OUTBOX_RELAY_LIST dvm_config.RECONCILE_DB_RELAY_LIST = RECONCILE_DB_RELAY_LIST dvm_config.RELAY_LIST = RELAY_LIST - dvm_config.SUBSCRIPTION_REQUIRED = True + dvm_config.SUBSCRIPTION_REQUIRED = False admin_config.LUD16 = dvm_config.LN_ADDRESS admin_config.REBROADCAST_NIP88 = False #admin_config.REBROADCAST_NIP89 = True @@ -435,8 +435,8 @@ def build_example_popular_non_followers(name, identifier, admin_config, options, "lud16": dvm_config.LN_ADDRESS, "encryptionSupported": True, "cashuAccepted": True, - "subscription": True, - "personalized": False, + "subscription": False, + "personalized": True, "nip90Params": { "max_results": { "required": False, @@ -468,7 +468,7 @@ def build_example_popular_non_followers(name, identifier, admin_config, options, admin_config.PRIVKEY = dvm_config.PRIVATE_KEY return DicoverContentCurrentlyPopularNonFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config, - nip88config=nip88config, + #nip88config=nip88config, admin_config=admin_config, options=options) @@ -620,7 +620,7 @@ def playground(): admin_config_db_scheduler= AdminConfig() options_animal = { "db_name": main_db, - "db_since": 12 * 60 * 60, # 48h since gmt, + "db_since": 48 * 60 * 60, # 48h since gmt, "personalized": False, "logger": False} image = "" @@ -811,6 +811,34 @@ def playground(): update_db=True) discovery_mostr.run() + # Popular Garden&Plants + admin_config_asknostr = AdminConfig() + admin_config_asknostr.REBROADCAST_NIP89 =rebroadcast_NIP89 + admin_config_asknostr.REBROADCAST_NIP65_RELAY_LIST = rebroadcast_NIP65_Relay_List + admin_config_asknostr.UPDATE_PROFILE = update_profile + options_plants = { + "search_list": ["#asknostr"], + "avoid_list": [], + "db_name": "db/nostr_recent_notes.db", + "db_since": 24 * 60 * 60, # 12h since gmt + "personalized": False, + "logger": False} + + image = "https://i.nostr.build/vIixmuRacIhULsrP.png" + description = "I show popular questions #asknostr" + custom_processing_msg = ["Finding the best notes for you.. #asknostr"] + update_db = False + cost = 0 + discovery_asknostr = build_example_topic("Popular on #asknostr", "discovery_content_asknostr", + admin_config_asknostr, options_plants, + image=image, + description=description, + update_rate=global_update_rate, + cost=cost, + processing_msg=custom_processing_msg, + update_db=update_db, + database=DATABASE) + discovery_asknostr.run() # Popular Animals (Fluffy frens) admin_config_animals = AdminConfig() @@ -1029,7 +1057,7 @@ def playground(): options_global_popular = { "db_name": "db/nostr_recent_notes.db", - "db_since": 60 * 60 * 4, # 1h since gmt, + "db_since": 60 * 60 * 1, # 1h since gmt, } cost = 0 #image = "https://image.nostr.build/b29b6ec4bf9b6184f69d33cb44862db0d90a2dd9a506532e7ba5698af7d36210.jpg" diff --git a/tests/test_dvm_client.py b/tests/test_dvm_client.py index e628d6c..12cace4 100644 --- a/tests/test_dvm_client.py +++ b/tests/test_dvm_client.py @@ -224,7 +224,7 @@ async def nostr_client_custom_discovery(user, ptag): pTag = Tag.parse(["p", ptag]) - tags = [relaysTag, alttag, paramTag, pTag, paramTagSearch, paramTagMust, paramTagAvoid] + tags = [relaysTag, alttag, paramTag, pTag]# paramTagSearch, paramTagMust, paramTagAvoid] event = EventBuilder(EventDefinitions.KIND_NIP90_CONTENT_DISCOVERY, str("Give me content"), tags).to_event(keys) @@ -234,7 +234,7 @@ async def nostr_client_custom_discovery(user, ptag): for relay in relay_list: await client.add_relay(relay) ropts = RelayOptions().ping(False) - await client.add_relay_with_opts("wss://nostr.band", ropts) + await client.connect() config = DVMConfig await send_event(event, client=client, dvm_config=config) @@ -444,7 +444,7 @@ async def nostr_client(): # await nostr_client_test_translation("44a0a8b395ade39d46b9d20038b3f0c8a11168e67c442e3ece95e4a1703e2beb", "event", "zh", 20, 20) #await nostr_client_test_image("a beautiful purple ostrich watching the sunset, eating a cashew nut") - await nostr_client_custom_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "7a63849b684d90c0de983492578b12e147e56f5d79ed6585cc64e5aa8a122744") + await nostr_client_custom_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "7240284b84951cfedbc20fce26f0e3f0a36da3e9c1be85d7a06965f0d4fe25fb") #"a018ba05af400b52772e33162d8326fca4a167fe7b6d3cd2382e14cac2af6841" # await nostr_client_duckduck_test(PublicKey.parse("7a63849b684d90c0de983492578b12e147e56f5d79ed6585cc64e5aa8a122744").to_hex() , "How do i create a dockerfile for python 3.12") #await nostr_client_flux_schnell("d57f1efb7582f58cade6f482d53eefa998d8082711b996aae3dc5f5527cbdd6e" , "topics") diff --git a/ui/noogle/src/components/FilterGeneration.vue b/ui/noogle/src/components/FilterGeneration.vue index a4796ee..4bee0a7 100644 --- a/ui/noogle/src/components/FilterGeneration.vue +++ b/ui/noogle/src/components/FilterGeneration.vue @@ -75,8 +75,11 @@ async function generate_feed(id) { let tags = [] //tags.push(["param", "max_results", "200"]) tags.push(["param", "user", store.state.pubkey.toHex()]) - let r = store.state.relays.join(",") - tags.push(["relays", r]) + let r = ["relays"] + for (let relay of store.state.relays){ + r.push(relay) + } + tags.push(r) let res; let requestid; diff --git a/ui/noogle/src/components/ImageGeneration.vue b/ui/noogle/src/components/ImageGeneration.vue index 868f163..b640ce2 100644 --- a/ui/noogle/src/components/ImageGeneration.vue +++ b/ui/noogle/src/components/ImageGeneration.vue @@ -61,8 +61,12 @@ async function generate_image(message) { let tags = [ ["i", message, "text"] ] - let r = store.state.relays.join(",") - tags.push(["relays", r]) + + let r = ["relays"] + for (let relay of store.state.relays){ + r.push(relay) + } + tags.push(r) hasmultipleinputs = false if (urlinput.value !== "" && urlinput.value.startsWith('http')){ @@ -222,7 +226,7 @@ async function listen() { for (const el of store.state.nip89dvms) { - if (JSON.parse(el.event).pubkey === event.author.toHex().toString()) { + if (JSON.parse(el.event).pubkey === event.author.toHex().toString() && el.kind === "5100" ) { jsonentry.name = el.name jsonentry.about = el.about jsonentry.image = el.image @@ -439,54 +443,54 @@ const submitHandler = async () => { -
+
+ - -
+ + + + + + -
- + + + + + +
-

{{dvm.reactions.positive.length}} - +

-
-
- - - -
-
-
-

Liked results by

-
-
-
-
- DVM Picture - -
-
-
+ + + + + + + + + + + + + + + + + +
@@ -500,53 +504,53 @@ const submitHandler = async () => {
- {{dvm.reactions.negative.length}} -
+ + -
-
- - - -
-
-
-

Disliked results by

-
-
-
+ + + + + + + + + + + + -
+ - DVM Picture - -
+ + + -
-
+ + -
+ -
-
-
- -
+ + + + + + -

-
+ -
-
-
+ + +