updating JS sdk to 0.12.0, fixes summarization

This commit is contained in:
Believethehype
2024-03-28 11:48:52 +01:00
parent ea5b0cddce
commit 97857cd928
10 changed files with 27 additions and 28 deletions

View File

@@ -66,7 +66,7 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
print("Event not found") print("Event not found")
raise Exception raise Exception
if evt.kind() == EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY: if evt.kind().as_u64() == EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY:
result_list = json.loads(evt.content()) result_list = json.loads(evt.content())
prompt = "" prompt = ""
for tag in result_list: for tag in result_list:

View File

@@ -68,7 +68,7 @@ class SummarizationUnleashedChat(DVMTaskInterface):
print("Event not found") print("Event not found")
raise Exception raise Exception
if evt.kind() == EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY: if evt.kind().as_u64() == EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY:
result_list = json.loads(evt.content()) result_list = json.loads(evt.content())
prompt = "" prompt = ""
for tag in result_list: for tag in result_list:

View File

@@ -1,5 +1,6 @@
import json import json
import os import os
import threading
from pathlib import Path from pathlib import Path
import dotenv import dotenv
@@ -15,7 +16,6 @@ from nostr_dvm.utils.nostr_utils import check_and_set_private_key
from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys
def playground(): def playground():
bot_config = DVMConfig() bot_config = DVMConfig()
identifier = "bot_test" identifier = "bot_test"
@@ -26,7 +26,6 @@ def playground():
bot_config.LNBITS_ADMIN_KEY = admin_key # The dvm might pay failed jobs back bot_config.LNBITS_ADMIN_KEY = admin_key # The dvm might pay failed jobs back
bot_config.LNBITS_URL = os.getenv("LNBITS_HOST") bot_config.LNBITS_URL = os.getenv("LNBITS_HOST")
admin_config = AdminConfig() admin_config = AdminConfig()
pdfextractor = textextraction_pdf.build_example("PDF Extractor", "pdf_extractor", admin_config) pdfextractor = textextraction_pdf.build_example("PDF Extractor", "pdf_extractor", admin_config)
@@ -34,12 +33,11 @@ def playground():
pdfextractor.run() pdfextractor.run()
bot_config.SUPPORTED_DVMS.append(pdfextractor) # We add translator to the bot bot_config.SUPPORTED_DVMS.append(pdfextractor) # We add translator to the bot
x = threading.Thread(target=Bot, args=([bot_config]))
x.start()
Bot(bot_config, admin_config)
# Keep the main function alive for libraries that require it, like openai # Keep the main function alive for libraries that require it, like openai
keep_alive() # keep_alive()
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -13,9 +13,7 @@ def playground():
connectionstr = os.getenv("TEST_NWC") connectionstr = os.getenv("TEST_NWC")
keys = Keys.parse(os.getenv("TEST_USER")) keys = Keys.parse(os.getenv("TEST_USER"))
bolt11 = zaprequest("bot@nostrdvm.com", 5, "test", None, PublicKey.parse("npub1cc79kn3phxc7c6mn45zynf4gtz0khkz59j4anew7dtj8fv50aqrqlth2hf"), keys, dvmconfig.DVMConfig.RELAY_LIST, zaptype="private") bolt11 = zaprequest("bot@nostrdvm.com", 5, "test", None, PublicKey.parse("npub1cc79kn3phxc7c6mn45zynf4gtz0khkz59j4anew7dtj8fv50aqrqlth2hf"), keys, dvmconfig.DVMConfig.RELAY_LIST, zaptype="private")
print(bolt11) print(bolt11)
result = nwc_zap(connectionstr, bolt11, keys, externalrelay=None) result = nwc_zap(connectionstr, bolt11, keys, externalrelay=None)
print(result) print(result)

View File

@@ -12,7 +12,7 @@
}, },
"dependencies": { "dependencies": {
"@getalby/sdk": "^3.4.0", "@getalby/sdk": "^3.4.0",
"@rust-nostr/nostr-sdk": "^0.11.1", "@rust-nostr/nostr-sdk": "^0.12.0",
"@vuepic/vue-datepicker": "^7.4.1", "@vuepic/vue-datepicker": "^7.4.1",
"@vueuse/core": "^10.7.2", "@vueuse/core": "^10.7.2",
"bech32": "^2.0.0", "bech32": "^2.0.0",

View File

@@ -118,13 +118,13 @@ async function listen() {
const handle = { const handle = {
// Handle event // Handle event
handleEvent: async (relayUrl, event) => { handleEvent: async (relayUrl, subscriptionId, event) => {
/* if (store.state.imagehasEventListener === false){ /* if (store.state.imagehasEventListener === false){
return true return true
}*/ }*/
//const dvmname = getNamefromId(event.author.toHex()) //const dvmname = getNamefromId(event.author.toHex())
console.log("Received new event from", relayUrl); console.log("Received new event from", relayUrl);
console.log(event.asJson()) // console.log(event.asJ())
let resonsetorequest = false let resonsetorequest = false
sleep(0).then(async () => { sleep(0).then(async () => {
for (let tag in event.tags) { for (let tag in event.tags) {

View File

@@ -119,6 +119,7 @@ async function react(eventid, authorid){
if (objects !== undefined){ if (objects !== undefined){
if(!objects.reacted ){ if(!objects.reacted ){
if (localStorage.getItem('nostr-key-method') === 'android-signer') { if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = { let draft = {
content: "🧡", content: "🧡",
@@ -127,14 +128,14 @@ async function react(eventid, authorid){
tags: [], tags: [],
createdAt: Date.now() createdAt: Date.now()
}; };
let res = await amberSignerService.signEvent(draft) let res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res))) await client.sendEvent(Event.fromJson(JSON.stringify(res)))
let requestid = res.id; let requestid = res.id;
} }
else { else {
let event = EventBuilder.reaction(event_id, public_key, "🧡") let event = new EventBuilder(7, "🧡", [])
let res = await client.sendEventBuilder(event); //let event = EventBuilder.reaction(event_id, "🧡")
let requestid = await client.sendEventBuilder(event);
} }
objects.reacted = true objects.reacted = true

View File

@@ -14,12 +14,11 @@ import {
Nip19Event, Nip19Event,
Alphabet, Alphabet,
Keys, Keys,
nip04_decrypt,
SecretKey, SecretKey,
Duration, Duration,
SingleLetterTag, SingleLetterTag,
NostrSigner, NostrSigner,
nip44_encrypt, nip44Encrypt,
NIP44Version NIP44Version
} from "@rust-nostr/nostr-sdk"; } from "@rust-nostr/nostr-sdk";
import store from '../store'; import store from '../store';
@@ -206,7 +205,7 @@ async function listen() {
const handle = { const handle = {
// Handle event // Handle event
handleEvent: async (relayUrl, event) => { handleEvent: async (relayUrl, subscriptionId, event) => {
let resonsetorequest = false let resonsetorequest = false
sleep(1200).then(async () => { sleep(1200).then(async () => {
for (let tag in event.tags) { for (let tag in event.tags) {
@@ -779,7 +778,7 @@ async function subscribe_to_dvm() {
} }
await nclient.connect() await nclient.connect()
let encnwc = nip44_encrypt(SecretKey.parse(store.state.nooglekey), PublicKey.parse(store.state.subscription_verifier_pubkey), let encnwc = nip44Encrypt(SecretKey.parse(store.state.nooglekey), PublicKey.parse(store.state.subscription_verifier_pubkey),
current_subscription_nwc.value, NIP44Version.V2) current_subscription_nwc.value, NIP44Version.V2)
let content = { let content = {

View File

@@ -178,7 +178,7 @@ async function listen() {
const handle = { const handle = {
// Handle event // Handle event
handleEvent: async (relayUrl, event) => { handleEvent: async (relayUrl, subscriptionId, event) => {
/* if (store.state.hasEventListener === false){ /* if (store.state.hasEventListener === false){
return true return true
}*/ }*/

View File

@@ -29,10 +29,13 @@ import VueDatePicker from "@vuepic/vue-datepicker";
import {timestamp} from "@vueuse/core"; import {timestamp} from "@vueuse/core";
import NoteTable from "@/components/NoteTable.vue"; import NoteTable from "@/components/NoteTable.vue";
import {zap} from "@/components/helper/Zap.vue"; import {zap} from "@/components/helper/Zap.vue";
import index from "vuex";
let dvms =[] let dvms =[]
async function summarizefeed(eventids) { async function summarizefeed(eventids) {
let sortedIds = eventids.sort(function(a,b) {return (a.index > b.index) ? 1 : ((b.index > a.index) ? -1 : 0);} );
try { try {
if(store.state.pubkey === undefined || localStorage.getItem('nostr-key-method') === "anon"){ if(store.state.pubkey === undefined || localStorage.getItem('nostr-key-method') === "anon"){
miniToastr.showMessage("In order to receive personalized recommendations, sign-in first.", "Not signed in.", VueNotifications.types.warn) miniToastr.showMessage("In order to receive personalized recommendations, sign-in first.", "Not signed in.", VueNotifications.types.warn)
@@ -47,9 +50,9 @@ async function summarizefeed(eventids) {
let kind = 5001 let kind = 5001
let tags = [] let tags = []
for (const tag of eventids){ for (const tag of sortedIds){
try{ try{
tags.push(["i", tag.id.toHex(), "event"]) tags.push(["i", tag.id, "event"])
} }
catch{} catch{}
} }
@@ -110,7 +113,7 @@ async function listen() {
const handle = { const handle = {
// Handle event // Handle event
handleEvent: async (relayUrl, event) => { handleEvent: async (relayUrl, subscriptionId, event) => {
/* if (store.state.summarizationhasEventListener === false){ /* if (store.state.summarizationhasEventListener === false){
return true return true
}*/ }*/