|
|
@ -13,7 +13,7 @@ import magic |
|
|
|
from PIL import Image |
|
|
|
import re |
|
|
|
|
|
|
|
from .helpers import ChatItem |
|
|
|
from .helpers import ChatItem, Event |
|
|
|
ai = importlib.import_module("matrix_pygmalion_bot.ai.runpod_pygmalion") |
|
|
|
#from .llama_cpp import generate, get_full_prompt, get_full_prompt_chat_style |
|
|
|
#from .runpod_pygmalion import generate_sync, get_full_prompt |
|
|
@ -69,11 +69,14 @@ class Callbacks(object): |
|
|
|
if is_own_message: |
|
|
|
return |
|
|
|
|
|
|
|
if hasattr(event, 'body') and event.body.startswith('!replybot'): |
|
|
|
if not hasattr(event, 'body'): |
|
|
|
return |
|
|
|
|
|
|
|
if event.body.startswith('!replybot'): |
|
|
|
print(event) |
|
|
|
await self.bot.send_message(self.client, room.room_id, "Hello World!") |
|
|
|
return |
|
|
|
elif hasattr(event, 'body') and event.body.startswith('!image'): |
|
|
|
elif event.body.startswith('!image'): |
|
|
|
prompt = event.body.removeprefix('!image').strip() |
|
|
|
negative_prompt = "out of frame, (ugly:1.3), (fused fingers), (too many fingers), (bad anatomy:1.5), (watermark:1.5), (words), letters, untracked eyes, asymmetric eyes, floating head, (logo:1.5), (bad hands:1.3), (mangled hands:1.2), (missing hands), (missing arms), backward hands, floating jewelry, unattached jewelry, floating head, doubled head, unattached head, doubled head, head in body, (misshapen body:1.1), (badly fitted headwear:1.2), floating arms, (too many arms:1.5), limbs fused with body, (facial blemish:1.5), badly fitted clothes, imperfect eyes, untracked eyes, crossed eyes, hair growing from clothes, partial faces, hair not attached to head" |
|
|
|
if len(prompt) == 0: |
|
|
@ -82,8 +85,10 @@ class Callbacks(object): |
|
|
|
for imagefile in output: |
|
|
|
await self.bot.send_image(self.client, room.room_id, imagefile) |
|
|
|
return |
|
|
|
elif hasattr(event, 'body') and event.body.startswith('!begin'): |
|
|
|
elif event.body.startswith('!begin'): |
|
|
|
self.bot.chat_history = {} |
|
|
|
self.bot.timestamp = time.time() |
|
|
|
await self.bot.write_conf2(self.bot.name) |
|
|
|
await self.bot.send_message(self.client, room.room_id, self.bot.greeting) |
|
|
|
return |
|
|
|
elif event.body.startswith('!!!'): |
|
|
@ -109,6 +114,11 @@ class Callbacks(object): |
|
|
|
translated_message = message |
|
|
|
# don't return, we generate a new answer |
|
|
|
|
|
|
|
# Other commands |
|
|
|
if re.search("^(?=.*\bsend\b)(?=.*\bpicture\b).*$", message): |
|
|
|
# send, mail, drop, snap picture, photo, image, portrait |
|
|
|
pass |
|
|
|
|
|
|
|
full_prompt = await ai.get_full_prompt(translated_message, self.bot) |
|
|
|
num_tokens = await ai.num_tokens(full_prompt) |
|
|
|
logger.info(full_prompt) |
|
|
@ -164,6 +174,7 @@ class ChatBot(object): |
|
|
|
self.callbacks = None |
|
|
|
self.config = None |
|
|
|
self.not_synced = True |
|
|
|
self.timestamp = time.time() |
|
|
|
|
|
|
|
self.owner = None |
|
|
|
self.translate = None |
|
|
@ -187,9 +198,17 @@ class ChatBot(object): |
|
|
|
async def event_loop(self): |
|
|
|
while True: |
|
|
|
await asyncio.sleep(60) |
|
|
|
print(time.time()) |
|
|
|
#print(time.time()) |
|
|
|
for event in self.events: |
|
|
|
event.loop() |
|
|
|
event.loop(self) |
|
|
|
|
|
|
|
async def add_event(self, event_string): |
|
|
|
items = event_string.split(',', 3) |
|
|
|
for item in items: |
|
|
|
item = item.strip() |
|
|
|
event = Event(float(items[0]), float(items[1]), float(items[2]), items[3]) |
|
|
|
self.events.append(event) |
|
|
|
pass |
|
|
|
|
|
|
|
async def login(self): |
|
|
|
self.config = AsyncClientConfig(store_sync_tokens=True) |
|
|
@ -218,6 +237,22 @@ class ChatBot(object): |
|
|
|
print("Client is synced") |
|
|
|
self.not_synced = False |
|
|
|
|
|
|
|
async def read_conf2(self, section): |
|
|
|
config2 = configparser.ConfigParser() |
|
|
|
config2.read('bot.conf2') |
|
|
|
if config2.has_section(section) and config2.has_option(section, 'timestamp'): |
|
|
|
self.timestamp = float(config2[section]['timestamp']) |
|
|
|
else: |
|
|
|
self.timestamp = time.time() |
|
|
|
|
|
|
|
async def write_conf2(self, section): |
|
|
|
config2 = configparser.ConfigParser() |
|
|
|
config2.read('bot.conf2') |
|
|
|
config2[section] = {} |
|
|
|
config2[section]['timestamp'] = str(self.timestamp) |
|
|
|
with open('bot.conf2', 'w') as configfile: |
|
|
|
config2.write(configfile) |
|
|
|
|
|
|
|
async def send_message(self, client, room_id, message, reply_to=None, original_message=None): |
|
|
|
content={"msgtype": "m.text", "body": message} |
|
|
|
if reply_to: |
|
|
@ -297,8 +332,14 @@ async def main() -> None: |
|
|
|
translate.init("en", bot.translate) |
|
|
|
if config.has_option(section, 'image_prompt'): |
|
|
|
bot.image_prompt = config[section]['image_prompt'] |
|
|
|
if config.has_option(section, 'events'): |
|
|
|
events = config[section]['events'].strip().split('\n') |
|
|
|
for event in events: |
|
|
|
await bot.add_event(event) |
|
|
|
if config.has_option('DEFAULT', 'runpod_api_key'): |
|
|
|
bot.runpod_api_key = config['DEFAULT']['runpod_api_key'] |
|
|
|
await bot.read_conf2(section) |
|
|
|
await bot.write_conf2(section) |
|
|
|
bots.append(bot) |
|
|
|
await bot.login() |
|
|
|
print("gather") |
|
|
|