-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (61 loc) · 2.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
from pathlib import Path
import dotenv
from duck_chat import ModelType
from nostr_sdk import Kind
from nostr_dvm.tasks.generic_dvm import GenericDVM
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
def playground(announce=False):
admin_config = AdminConfig()
admin_config.REBROADCAST_NIP89 = announce
admin_config.REBROADCAST_NIP65_RELAY_LIST = announce
admin_config.UPDATE_PROFILE = announce
name = "AmyAmyGo"
identifier = "AmyAmyGo" # Chose a unique identifier in order to get a lnaddress
kind = Kind(5050)
dvm_config = build_default_config(identifier)
dvm_config.KIND = kind # Manually set the Kind Number (see data-vending-machines.org)
dvm_config.SEND_FEEDBACK_EVENTS = False
# Add NIP89
nip89info = {
"name": name,
"image": "https://i.nostr.build/05oBiasWPfSJtz8B.png",
"about": "I do AI. Pew. Pew.",
"encryptionSupported": True,
"cashuAccepted": True,
"nip90Params": {
}
}
nip89config = NIP89Config()
nip89config.DTAG = check_and_set_d_tag(identifier, name, dvm_config.PRIVATE_KEY, nip89info["image"])
nip89config.KIND = kind
nip89config.CONTENT = json.dumps(nip89info)
options = {
"input": "Good Morning!",
}
dvm = GenericDVM(name=name, dvm_config=dvm_config, nip89config=nip89config,
admin_config=admin_config, options=options)
async def process(request_form):
from duck_chat import DuckChat
options = dvm.set_options(request_form)
async with DuckChat(model=ModelType.Llama) as chat:
query = options["input"]
result = await chat.ask_question(query)
print(result)
return result
dvm.process = process # overwrite the process function with the above one
dvm.run(True)
if __name__ == '__main__':
env_path = Path('.env')
if not env_path.is_file():
with open('.env', 'w') as f:
print("Writing new .env file")
f.write('')
if env_path.is_file():
print(f'loading environment from {env_path.resolve()}')
dotenv.load_dotenv(env_path, verbose=True, override=True)
else:
raise FileNotFoundError(f'.env file not found at {env_path} ')
playground(announce=True)