Skip to content

Commit

Permalink
bot updates to new logos
Browse files Browse the repository at this point in the history
  • Loading branch information
genekogan committed Dec 28, 2023
1 parent a06fbb3 commit 598a969
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 64 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies = [
"python-dotenv>=1.0.0",
"pymongo>=4.6.0",
"py-cord>=2.4.1",
"eden-logos @ git+https://github.com/edenartlab/logos",
]
readme = "README.md"
requires-python = ">= 3.11"
Expand Down
88 changes: 44 additions & 44 deletions src/cogs/LogosCharacterCog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import random
import discord
from datetime import datetime, timedelta
from attr import dataclass
from discord.ext import commands

Expand All @@ -10,8 +11,14 @@
replace_bot_mention,
replace_mentions_with_usernames,
)
from common.eden import generation_loop, get_assistant
from common.logos import request_logos_assistant
from common.eden import (
generation_loop,
get_assistant,
)
from common.logos import (
logos_think,
logos_speak,
)
from common.models import (
GenerationLoopInput,
SignInCredentials,
Expand All @@ -27,7 +34,6 @@
EDEN_API_SECRET = os.getenv("EDEN_API_SECRET")
EDEN_CHARACTER_ID = os.getenv("EDEN_CHARACTER_ID")

print("EDEN CHAR", EDEN_CHARACTER_ID)

@dataclass
class LoraInput:
Expand Down Expand Up @@ -58,43 +64,45 @@ async def on_message(self, message: discord.Message) -> None:
):
return

trigger_reply = is_mentioned(message, self.bot.user)
session_id = f'{message.channel.id}/{message.author.id}'
prompt = self.message_preprocessor(message)
attachment_urls = [attachment.url for attachment in message.attachments]

cutoff = message.created_at - timedelta(minutes=90)
conversation_history = await message.channel.history(after=cutoff).flatten()
conversation = ""
for message in conversation_history[-10:]:
timestamp = message.created_at.strftime("%I:%M %p")
author = message.author.name
content = replace_mentions_with_usernames(
message.content,
message.mentions,
)
conversation += f"\n{author}{timestamp}\n{content}\n"
#if message.attachments:

request = {
"character_id": self.characterId,
"session_id": session_id,
"prompt": conversation,
# "prompt": prompt,
"attachments": attachment_urls,
}

trigger_reply = is_mentioned(message, self.bot.user)
#if not trigger_reply:
# trigger_reply = logos_think(LOGOS_URL, request)

if trigger_reply:
ctx = await self.bot.get_context(message)
async with ctx.channel.typing():
prompt = self.message_preprocessor(message)
attachment_urls = [attachment.url for attachment in message.attachments]

assistant, concept = get_assistant(
api_url=EDEN_API_URL,
character_id=self.characterId,
credentials=self.eden_credentials,
)
request["prompt"] = prompt
response = logos_speak(LOGOS_URL, request)

print("ASISSTANT")
print(assistant)
print("CONCEPT")
print(concept)

interaction = {
"character_id": self.characterId,
"session_id": str(message.author.id) + str(message.channel.id),
"prompt": prompt,
"attachments": attachment_urls,
}

print("THE INTERACTION")
print(interaction)


print(LOGOS_URL)

response = request_logos_assistant(LOGOS_URL, assistant, interaction)
print("RESPONSE")
print(response)
reply = response.get("message")[:2000]
reply_message = await message.reply(reply)
reply = response.get("message")
reply_chunks = [reply[i:i+2000] for i in range(0, len(reply), 2000)]
for chunk in reply_chunks:
reply_message = await message.reply(chunk)

# check if there is a config
config = response.get("config")
Expand All @@ -116,15 +124,13 @@ async def on_message(self, message: discord.Message) -> None:

config = StableDiffusionConfig(generator_name=mode, **config)

config = self.add_lora(config, concept)

source = get_source(ctx)

is_video_request = mode in ["interpolate", "real2real"]

start_bot_message = f"**{text_input}** - <@!{ctx.author.id}>\n"
original_text = (
f"{reply[0:1950-len(start_bot_message)]}\n\n{start_bot_message}"
f"{reply_message.content[0:1950-len(start_bot_message)]}\n\n{start_bot_message}"
)

generation_loop_input = GenerationLoopInput(
Expand All @@ -150,11 +156,5 @@ def message_preprocessor(self, message: discord.Message) -> str:
message_content = message_content.strip()
return message_content

def add_lora(self, config: StableDiffusionConfig, concept: str):
if concept:
config.lora = concept
config.lora_strength = 0.6
return config

def check_lora_trigger_provided(message: str, lora_trigger: str):
return lora_trigger in message
29 changes: 10 additions & 19 deletions src/common/logos.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import requests


def request_logos_assistant(api_url: str, assistant: dict, interaction: dict):

print("----")
print(assistant)
print(interaction)
print(api_url)
print("----")
print("--> 1")
print("GET KEYS")
print(assistant.keys())
print(interaction.keys())
print("--> 2")
def logos_think(api_url: str, request: dict):
response = requests.post(
f"{api_url}/interact",
json={
"assistant": assistant,
"interaction": interaction,
},
f"{api_url}/chat/think",
json=request,
)
print("--> 3")
print(response.json())
return response.json()


def logos_speak(api_url: str, request: dict):
response = requests.post(
f"{api_url}/chat/speak",
json=request,
)
return response.json()

0 comments on commit 598a969

Please sign in to comment.