Skip to content

Commit

Permalink
added dependencies (and dependencies per task)
Browse files Browse the repository at this point in the history
  • Loading branch information
believethehype committed Dec 13, 2023
1 parent 14d1366 commit af4bc8a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .idea/dvm.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion nostr_dvm/interfaces/dvmtaskinterface.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
import subprocess
import sys
from threading import Thread

from nostr_sdk import Keys

from nostr_dvm.dvm import DVM
from nostr_dvm.utils.admin_utils import AdminConfig
from nostr_dvm.utils.dvmconfig import DVMConfig
from nostr_dvm.utils.nip89_utils import NIP89Config
from nostr_dvm.dvm import DVM
from nostr_dvm.utils.output_utils import post_process_result


Expand All @@ -23,11 +25,13 @@ class DVMTaskInterface:
ACCEPTS_CASHU = True # DVMs build with this framework support encryption, but others might not.
dvm_config: DVMConfig
admin_config: AdminConfig
dependencies = []

def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, admin_config: AdminConfig = None,
options=None, task=None):
self.init(name, dvm_config, admin_config, nip89config, task)
self.options = options
self.install_dependencies(self.dependencies)

def init(self, name, dvm_config, admin_config=None, nip89config=None, task=None):
self.NAME = name
Expand Down Expand Up @@ -80,6 +84,13 @@ 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)

def install_dependencies(self, packages):
import pip
for package in packages:
try:
__import__(package.split("=")[0])
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", package])

@staticmethod
def set_options(request_form):
Expand Down
1 change: 1 addition & 0 deletions nostr_dvm/tasks/imagegeneration_openai_dalle.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ImageGenerationDALLE(DVMTaskInterface):
KIND: int = EventDefinitions.KIND_NIP90_GENERATE_IMAGE
TASK: str = "text-to-image"
FIX_COST: float = 120
dependencies = ["openai==1.3.5"]

def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config,
admin_config: AdminConfig = None, options=None):
Expand Down
1 change: 1 addition & 0 deletions nostr_dvm/tasks/imagegeneration_replicate_sdxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ImageGenerationReplicateSDXL(DVMTaskInterface):
KIND: int = EventDefinitions.KIND_NIP90_GENERATE_IMAGE
TASK: str = "text-to-image"
FIX_COST: float = 120
dependencies = ["replicate==0.21.1"]

def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config,
admin_config: AdminConfig = None, options=None):
Expand Down
3 changes: 3 additions & 0 deletions nostr_dvm/tasks/textextraction_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ class TextExtractionPDF(DVMTaskInterface):
KIND: int = EventDefinitions.KIND_NIP90_EXTRACT_TEXT
TASK: str = "pdf-to-text"
FIX_COST: float = 0
dependencies = ["pypdf==3.17.1"]

def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config,
admin_config: AdminConfig = None, options=None):
super().__init__(name, dvm_config, nip89config, admin_config, options)



def is_input_supported(self, tags):
for tag in tags:
if tag.as_vec()[0] == 'i':
Expand Down
5 changes: 4 additions & 1 deletion nostr_dvm/tasks/textgeneration_llmlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path

import dotenv
from litellm import completion


from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface
from nostr_dvm.utils.admin_utils import AdminConfig
Expand All @@ -27,6 +27,7 @@ class TextGenerationOLLAMA(DVMTaskInterface):
KIND: int = EventDefinitions.KIND_NIP90_GENERATE_TEXT
TASK: str = "text-to-text"
FIX_COST: float = 0
dependencies = ["litellm==1.12.3"]

def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config,
admin_config: AdminConfig = None, options=None):
Expand Down Expand Up @@ -71,6 +72,8 @@ def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
return request_form

def process(self, request_form):
from litellm import completion

options = DVMTaskInterface.set_options(request_form)

try:
Expand Down
1 change: 1 addition & 0 deletions nostr_dvm/tasks/translation_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TranslationGoogle(DVMTaskInterface):
KIND: int = EventDefinitions.KIND_NIP90_TRANSLATE_TEXT
TASK: str = "translation"
FIX_COST: float = 0
dependencies = ["translatepy==2.3"]

def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config,
admin_config: AdminConfig = None, options=None):
Expand Down
22 changes: 17 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@

# Setting up
setup(
# the name must match the folder name 'verysimplemodule'
name="nostr-dvm",
version=VERSION,
author="Believethehype",
author_email="-",
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
packages=find_packages(),
install_requires=[], # add any additional packages that
# needs to be installed along with your package. Eg: 'caer'

packages=find_packages(include=['nostr_dvm']),
install_requires=["nostr-sdk==0.0.5",
"bech32==1.2.0",
"pycryptodome==3.19.0",
"python-dotenv==1.0.0",
"emoji==2.8.0",
"eva-decord==0.6.1",
"ffmpegio==0.8.5",
"lnurl==0.4.1",
"pandas==2.1.3",
"Pillow==10.1.0",
"PyUpload==0.1.4",
"requests==2.31.0",
"instaloader==4.10.1",
"pytube==15.0.0",
"moviepy==2.0.0.dev2"
],
keywords=['nostr', 'nip90', 'dvm', 'data vending machine'],
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down

0 comments on commit af4bc8a

Please sign in to comment.