get db, config, help, cool, and txt2img working

pull/11/head
Konstantine Tsafatinos 2023-07-19 00:58:55 -04:00
parent 1d7633d340
commit 609c741ae9
3 changed files with 112 additions and 47 deletions

View File

@ -485,7 +485,7 @@ def discord(
permission, permission,
node_url, node_url,
hyperion_url, hyperion_url,
# db_host, db_user, db_pass, db_host, db_user, db_pass,
remote_ipfs_node=ipfs_url, remote_ipfs_node=ipfs_url,
key=key key=key
) )

View File

@ -40,9 +40,9 @@ class SkynetDiscordFrontend:
permission: str, permission: str,
node_url: str, node_url: str,
hyperion_url: str, hyperion_url: str,
# db_host: str, db_host: str,
# db_user: str, db_user: str,
# db_pass: str, db_pass: str,
remote_ipfs_node: str, remote_ipfs_node: str,
key: str key: str
): ):
@ -51,9 +51,9 @@ class SkynetDiscordFrontend:
self.permission = permission self.permission = permission
self.node_url = node_url self.node_url = node_url
self.hyperion_url = hyperion_url self.hyperion_url = hyperion_url
# self.db_host = db_host self.db_host = db_host
# self.db_user = db_user self.db_user = db_user
# self.db_pass = db_pass self.db_pass = db_pass
self.remote_ipfs_node = remote_ipfs_node self.remote_ipfs_node = remote_ipfs_node
self.key = key self.key = key
@ -72,9 +72,9 @@ class SkynetDiscordFrontend:
logging.info( logging.info(
f'connected to remote ipfs node: {self.remote_ipfs_node}') f'connected to remote ipfs node: {self.remote_ipfs_node}')
# self.db_call = await self._async_exit_stack.enter_async_context( self.db_call = await self._async_exit_stack.enter_async_context(
# open_database_connection( open_database_connection(
# self.db_user, self.db_pass, self.db_host)) self.db_user, self.db_pass, self.db_host))
create_handler_context(self) create_handler_context(self)
@ -143,10 +143,10 @@ class SkynetDiscordFrontend:
# f'[{timestamp_pretty()}] <i>broadcasting transaction to chain...</i>', # f'[{timestamp_pretty()}] <i>broadcasting transaction to chain...</i>',
# parse_mode='HTML' # parse_mode='HTML'
# ) # )
message = await ctx.send( # message = await ctx.send(
f'processing a \'{method}\' request by {user}\n \ # f'processing a \'{method}\' request by {user}\n \
[{timestamp_pretty()}] *broadcasting transaction to chain...*' # [{timestamp_pretty()}] *broadcasting transaction to chain...*'
) # )
reward = '20.0000 GPU' reward = '20.0000 GPU'
res = await self.cleos.a_push_action( res = await self.cleos.a_push_action(
@ -183,12 +183,11 @@ class SkynetDiscordFrontend:
# f'[{timestamp_pretty()}] <i>workers are processing request...</i>', # f'[{timestamp_pretty()}] <i>workers are processing request...</i>',
# parse_mode='HTML' # parse_mode='HTML'
# ) # )
# await message.edit(content=
await message.edit( # f'**broadcasted!**\n \
f'**broadcasted!**\n \ # **{enqueue_tx_link}**\n \
**{enqueue_tx_link}**\n \ # [{timestamp_pretty()}] *workers are processing request...*'
[{timestamp_pretty()}] *workers are processing request...*' # )
)
out = collect_stdout(res) out = collect_stdout(res)
@ -250,11 +249,11 @@ class SkynetDiscordFrontend:
# f'[{timestamp_pretty()}] <i>trying to download image...</i>\n', # f'[{timestamp_pretty()}] <i>trying to download image...</i>\n',
# parse_mode='HTML' # parse_mode='HTML'
# ) # )
await message.edit( # await message.edit(content=
f'**request processed!**\n \ # f'**request processed!**\n \
**{tx_link}**\n \ # **{tx_link}**\n \
[{timestamp_pretty()}] *trying to download image...*\n' # [{timestamp_pretty()}] *trying to download image...*\n'
) # )
# attempt to get the image and send it # attempt to get the image and send it
ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}/image.png' ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}/image.png'

View File

@ -17,46 +17,112 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'):
bot = frontend.bot bot = frontend.bot
cleos = frontend.cleos cleos = frontend.cleos
# db_call = frontend.db_call db_call = frontend.db_call
work_request = frontend.work_request work_request = frontend.work_request
ipfs_node = frontend.ipfs_node ipfs_node = frontend.ipfs_node
@bot.command(name='config', help='Responds with the configuration') @bot.command(name='config', help='Responds with the configuration')
async def config(ctx): async def set_config(ctx):
response = "This is the bot configuration" # Put your bot configuration here
await ctx.send(response) user = ctx.author
try:
attr, val, reply_txt = validate_user_config_request(
ctx.message.content)
logging.info(f'user config update: {attr} to {val}')
await db_call('update_user_config', user.id, attr, val)
logging.info('done')
except BaseException as e:
reply_txt = str(e)
finally:
await ctx.reply(content=reply_txt)
@bot.command(name='helper', help='Responds with a help') @bot.command(name='helper', help='Responds with a help')
async def helper(ctx): async def helper(ctx):
response = "This is help information" # Put your help response here splt_msg = ctx.message.content.split(' ')
await ctx.send(response)
if len(splt_msg) == 1:
await ctx.reply(content=HELP_TEXT)
else:
param = splt_msg[1]
if param in HELP_TOPICS:
await ctx.reply(content=HELP_TOPICS[param])
else:
await ctx.reply(content=HELP_UNKWNOWN_PARAM)
@bot.command(name='cool', help='Display a list of cool prompt words')
async def send_cool_words(ctx):
await ctx.reply(content='\n'.join(COOL_WORDS))
@bot.command(name='txt2img', help='Responds with an image') @bot.command(name='txt2img', help='Responds with an image')
async def send_txt2img(ctx, *, arg): async def send_txt2img(ctx):
user = 'testworker3'
status_msg = 'status' # grab user from ctx
user = ctx.author
user_row = await db_call('get_or_create_user', user.id)
# init new msg
init_msg = 'started processing txt2img request...'
status_msg = await ctx.reply(init_msg)
await db_call(
'new_user_request', user.id, ctx.message.id, status_msg.id, status=init_msg)
prompt = ' '.join(ctx.message.content.split(' ')[1:])
if len(prompt) == 0:
await status_msg.edit(content=
'Empty text prompt ignored.'
)
await db_call('update_user_request', status_msg.id, 'Empty text prompt ignored.')
return
logging.info(f'mid: {ctx.message.id}')
user_config = {**user_row}
del user_config['id']
params = { params = {
'prompt': arg, 'prompt': prompt,
'seed': None, **user_config
'step': 35,
'guidance': 7.5,
'strength': 0.5,
'width': 512,
'height': 512,
'upscaler': None,
'model': 'prompthero/openjourney',
} }
ec = await work_request(user, status_msg, 'txt2img', params, ctx) await db_call(
print(ec) 'update_user_stats', user.id, 'txt2img', last_prompt=prompt)
ec = await work_request(user.name, status_msg, 'txt2img', params, ctx)
if ec == 0:
await db_call('increment_generated', user.id)
# TODO: DELETE BELOW
# user = 'testworker3'
# status_msg = 'status'
# params = {
# 'prompt': arg,
# 'seed': None,
# 'step': 35,
# 'guidance': 7.5,
# 'strength': 0.5,
# 'width': 512,
# 'height': 512,
# 'upscaler': None,
# 'model': 'prompthero/openjourney',
# }
#
# ec = await work_request(user, status_msg, 'txt2img', params, ctx)
# print(ec)
# if ec == 0: # if ec == 0:
# await db_call('increment_generated', user.id) # await db_call('increment_generated', user.id)
response = f"This is your prompt: {arg}" # response = f"This is your prompt: {arg}"
await ctx.send(response) # await ctx.send(response)
# generic / simple handlers # generic / simple handlers