send custom status update

This commit is contained in:
Believethehype 2024-09-03 10:21:01 +02:00
parent 78ddb3fbc6
commit 323b900603
4 changed files with 47 additions and 5 deletions

View File

@ -52,6 +52,8 @@ class GenericDVM(DVMTaskInterface):
request_form = {"jobID": event.id().to_hex()}
self.options["user"] = user
self.options["request_event_id"] = event.id().to_hex()
self.options["request_event_author"] = event.author().to_hex()
if prompt != "":
self.options["input"] = prompt
request_form['options'] = json.dumps(self.options)

View File

@ -6,13 +6,15 @@ from types import NoneType
import emoji
import requests
from nostr_sdk import Tag, PublicKey, EventId, Keys
from nostr_sdk import Tag, PublicKey, EventId, Keys, nip04_encrypt, EventBuilder, LogLevel
from pyupload.uploader import CatboxUploader
import pandas
from nostr_dvm.utils.print import bcolors
from nostr_dvm.utils.definitions import EventDefinitions
from nostr_dvm.utils.dvmconfig import DVMConfig
from nostr_dvm.utils.nip98_utils import generate_nip98_header
from nostr_dvm.utils.nostr_utils import send_event_outbox
'''
Post process results to either given output format or a Nostr readable plain text.
@ -290,3 +292,35 @@ def build_status_reaction(status, task, amount, content, dvm_config):
reaction = emoji.emojize(":thumbs_down:")
return alt_description, reaction
async def send_job_status_reaction(original_event_id_hex, original_event_author_hex, client, dvm_config,
content=None,
status="processing", user=None):
alt_description, reaction = build_status_reaction(status, "generic", 0, content, dvm_config)
e_tag = Tag.parse(["e", original_event_id_hex])
p_tag = Tag.parse(["p", original_event_author_hex])
alt_tag = Tag.parse(["alt", content])
status_tag = Tag.parse(["status", status])
reply_tags = [e_tag, alt_tag, status_tag]
reply_tags.append(p_tag)
content = reaction
keys = Keys.parse(dvm_config.PRIVATE_KEY)
reaction_event = EventBuilder(EventDefinitions.KIND_FEEDBACK, str(content), reply_tags).to_event(keys)
# send_event(reaction_event, client=self.client, dvm_config=self.dvm_config)
await send_event_outbox(reaction_event, client=client, dvm_config=dvm_config)
if dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
print(bcolors.YELLOW + "[" + dvm_config.NIP89.NAME + "]" + " Sent Kind " + str(
EventDefinitions.KIND_FEEDBACK.as_u64()) + " Reaction: " + status + " " + reaction_event.as_json() + bcolors.ENDC)
elif dvm_config.LOGLEVEL.value >= LogLevel.INFO.value:
print(bcolors.YELLOW + "[" + dvm_config.NIP89.NAME + "]" + " Sent Kind " + str(
EventDefinitions.KIND_FEEDBACK.as_u64()) + " Reaction: " + status + " " + reaction_event.id().to_hex() + bcolors.ENDC)
return reaction_event.as_json()

View File

@ -1,6 +1,6 @@
from setuptools import setup, find_packages
VERSION = '0.8.13'
VERSION = '0.8.14'
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')

View File

@ -12,6 +12,7 @@ from nostr_dvm.utils import definitions
from nostr_dvm.utils.admin_utils import AdminConfig
from nostr_dvm.utils.dvmconfig import build_default_config
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
from nostr_dvm.utils.output_utils import send_job_status_reaction
def playground(announce=False):
@ -43,7 +44,8 @@ def playground(announce=False):
identifier = "duckduckchat_llm" # Chose a unique identifier in order to get a lnaddress
dvm_config = build_default_config(identifier)
dvm_config.KIND = Kind(kind) # Manually set the Kind Number (see data-vending-machines.org)
dvm_config.SEND_FEEDBACK_EVENTS = False
dvm_config.CUSTOM_PROCESSING_MESSAGE = "Creating a personalized feed based on the topics you write about. This might take a moment."
# Add NIP89
nip89info = {
@ -69,6 +71,7 @@ def playground(announce=False):
admin_config=admin_config, options=options)
async def process(request_form):
since = 3 * 60 * 60
options = dvm.set_options(request_form)
sk = SecretKey.from_hex(dvm.dvm_config.PRIVATE_KEY)
keys = Keys.parse(sk.to_hex())
@ -109,6 +112,9 @@ def playground(announce=False):
result = result.replace(", ", ",")
print(result)
content = dvm_config.CUSTOM_PROCESSING_MESSAGE + "\n\nYour topics are:\n"+result.replace(",", ", ")
await send_job_status_reaction(original_event_id_hex=dvm.options["request_event_id"], original_event_author_hex=dvm.options["request_event_author"], client=cli, dvm_config=dvm_config, content=content)
#prompt = "Only reply with the result. For each word in this comma seperated list, add 3 synonyms to the list. Return one single list seperated with commas.: " + result
#async with DuckChat(model=ModelType.GPT4o) as chat:
# query = prompt
@ -121,7 +127,7 @@ def playground(announce=False):
database = await NostrDatabase.sqlite("db/nostr_recent_notes.db")
timestamp_since = Timestamp.now().as_secs() - 4 * 60 * 60
timestamp_since = Timestamp.now().as_secs() - since
since = Timestamp.from_secs(timestamp_since)
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since)