mirror of https://github.com/skygpu/skynet.git
get initial discord bot working with hardcoded config and image return
parent
fadb4eab6d
commit
1d7633d340
|
@ -439,7 +439,7 @@ def telegram(
|
||||||
@run.command()
|
@run.command()
|
||||||
@click.option('--loglevel', '-l', default='INFO', help='logging level')
|
@click.option('--loglevel', '-l', default='INFO', help='logging level')
|
||||||
@click.option(
|
@click.option(
|
||||||
'--account', '-a', default='discord')
|
'--account', '-a', default=None)
|
||||||
@click.option(
|
@click.option(
|
||||||
'--permission', '-p', default='active')
|
'--permission', '-p', default='active')
|
||||||
@click.option(
|
@click.option(
|
||||||
|
@ -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
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,8 @@ from leap.sugar import Name, asset_from_str, collect_stdout
|
||||||
from leap.hyperion import HyperionAPI
|
from leap.hyperion import HyperionAPI
|
||||||
# from telebot.types import InputMediaPhoto
|
# from telebot.types import InputMediaPhoto
|
||||||
|
|
||||||
# import discord
|
import discord
|
||||||
|
import io
|
||||||
|
|
||||||
from skynet.db import open_new_database, open_database_connection
|
from skynet.db import open_new_database, open_database_connection
|
||||||
from skynet.ipfs import get_ipfs_file
|
from skynet.ipfs import get_ipfs_file
|
||||||
|
@ -34,24 +35,24 @@ class SkynetDiscordFrontend:
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
token: str,
|
# token: str,
|
||||||
account: str,
|
account: str,
|
||||||
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
|
||||||
):
|
):
|
||||||
self.token = token
|
# self.token = token
|
||||||
self.account = account
|
self.account = account
|
||||||
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
|
||||||
|
@ -115,6 +116,7 @@ class SkynetDiscordFrontend:
|
||||||
status_msg,
|
status_msg,
|
||||||
method: str,
|
method: str,
|
||||||
params: dict,
|
params: dict,
|
||||||
|
ctx: discord.TextChannel,
|
||||||
file_id: str | None = None,
|
file_id: str | None = None,
|
||||||
binary_data: str = ''
|
binary_data: str = ''
|
||||||
):
|
):
|
||||||
|
@ -134,13 +136,17 @@ class SkynetDiscordFrontend:
|
||||||
})
|
})
|
||||||
request_time = datetime.now().isoformat()
|
request_time = datetime.now().isoformat()
|
||||||
|
|
||||||
# import pdb; pdb.set_trace()
|
# maybe get rid of this
|
||||||
# await self.update_status_message(
|
# await self.update_status_message(
|
||||||
# status_msg,
|
# status_msg,
|
||||||
# f'processing a \'{method}\' request by {tg_user_pretty(user)}\n'
|
# f'processing a \'{method}\' request by {tg_user_pretty(user)}\n'
|
||||||
# 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(
|
||||||
|
f'processing a \'{method}\' request by {user}\n \
|
||||||
|
[{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(
|
||||||
|
@ -178,6 +184,12 @@ class SkynetDiscordFrontend:
|
||||||
# parse_mode='HTML'
|
# parse_mode='HTML'
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
await message.edit(
|
||||||
|
f'**broadcasted!**\n \
|
||||||
|
**{enqueue_tx_link}**\n \
|
||||||
|
[{timestamp_pretty()}] *workers are processing request...*'
|
||||||
|
)
|
||||||
|
|
||||||
out = collect_stdout(res)
|
out = collect_stdout(res)
|
||||||
|
|
||||||
request_id, nonce = out.split(':')
|
request_id, nonce = out.split(':')
|
||||||
|
@ -238,13 +250,18 @@ 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(
|
||||||
|
f'**request processed!**\n \
|
||||||
|
**{tx_link}**\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'
|
||||||
resp = await get_ipfs_file(ipfs_link)
|
resp = await get_ipfs_file(ipfs_link)
|
||||||
|
|
||||||
caption = generate_reply_caption(
|
# caption = generate_reply_caption(
|
||||||
user, params, tx_hash, worker, reward)
|
# user, params, tx_hash, worker, reward)
|
||||||
|
|
||||||
if not resp or resp.status_code != 200:
|
if not resp or resp.status_code != 200:
|
||||||
logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link}!')
|
logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link}!')
|
||||||
|
@ -257,9 +274,11 @@ class SkynetDiscordFrontend:
|
||||||
#
|
#
|
||||||
else:
|
else:
|
||||||
logging.info(f'success! sending generated image')
|
logging.info(f'success! sending generated image')
|
||||||
|
image = io.BytesIO(resp.raw)
|
||||||
# await self.bot.delete_message(
|
# await self.bot.delete_message(
|
||||||
# chat_id=status_msg.chat.id, message_id=status_msg.id)
|
# chat_id=status_msg.chat.id, message_id=status_msg.id)
|
||||||
# if file_id: # img2img
|
if file_id: # img2img
|
||||||
|
pass
|
||||||
# await self.bot.send_media_group(
|
# await self.bot.send_media_group(
|
||||||
# status_msg.chat.id,
|
# status_msg.chat.id,
|
||||||
# media=[
|
# media=[
|
||||||
|
@ -272,11 +291,14 @@ class SkynetDiscordFrontend:
|
||||||
# ],
|
# ],
|
||||||
# )
|
# )
|
||||||
#
|
#
|
||||||
# else: # txt2img
|
else: # txt2img
|
||||||
# await self.bot.send_photo(
|
# await self.bot.send_photo(
|
||||||
# status_msg.chat.id,
|
# status_msg.chat.id,
|
||||||
# caption=caption,
|
# caption=caption,
|
||||||
# photo=resp.raw,
|
# photo=resp.raw,
|
||||||
# reply_markup=build_redo_menu(),
|
# reply_markup=build_redo_menu(),
|
||||||
# parse_mode='HTML'
|
# parse_mode='HTML'
|
||||||
# )
|
# )
|
||||||
|
await ctx.send(
|
||||||
|
file=discord.File(image, 'image.png')
|
||||||
|
)
|
||||||
|
|
|
@ -29,7 +29,7 @@ class DiscordBot(commands.Bot):
|
||||||
message_content=True,
|
message_content=True,
|
||||||
voice_states=True
|
voice_states=True
|
||||||
)
|
)
|
||||||
super().__init__(command_prefix='\\', intents=intents, *args, **kwargs)
|
super().__init__(command_prefix='/', intents=intents, *args, **kwargs)
|
||||||
|
|
||||||
# async def setup_hook(self):
|
# async def setup_hook(self):
|
||||||
# db.poll_db.start()
|
# db.poll_db.start()
|
||||||
|
|
|
@ -35,16 +35,21 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'):
|
||||||
|
|
||||||
@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, *, arg):
|
||||||
user = 'tests'
|
user = 'testworker3'
|
||||||
status_msg = 'status'
|
status_msg = 'status'
|
||||||
params = {
|
params = {
|
||||||
'prompt': arg,
|
'prompt': arg,
|
||||||
'seed': None,
|
'seed': None,
|
||||||
'step': 35,
|
'step': 35,
|
||||||
'guidance': 1,
|
'guidance': 7.5,
|
||||||
|
'strength': 0.5,
|
||||||
|
'width': 512,
|
||||||
|
'height': 512,
|
||||||
|
'upscaler': None,
|
||||||
|
'model': 'prompthero/openjourney',
|
||||||
}
|
}
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
ec = await work_request(user, status_msg, 'txt2img', params)
|
ec = await work_request(user, status_msg, 'txt2img', params, ctx)
|
||||||
print(ec)
|
print(ec)
|
||||||
|
|
||||||
# if ec == 0:
|
# if ec == 0:
|
||||||
|
|
Loading…
Reference in New Issue