Skip to content

Commit

Permalink
add view on eden button to discord client
Browse files Browse the repository at this point in the history
  • Loading branch information
jmilldotdev committed Jan 7, 2025
1 parent f201b9d commit 2ceda04
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
8 changes: 6 additions & 2 deletions eve/clients/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
import time

import modal

from eve.models import ClientType

db = os.getenv("DB", "STAGE")

HOUR_IMAGE_LIMIT = 50
HOUR_VIDEO_LIMIT = 10
Expand Down Expand Up @@ -105,3 +104,8 @@ def register_tool_call(user, tool_name):
def get_ably_channel_name(agent_username: str, client_platform: ClientType):
env = os.getenv("UPDATE_CHANNEL_ENV", "DEV")
return f"{agent_username.lower()}_{client_platform.value}_{env}"


def get_eden_creation_url(creation_id: str):
root_url = "beta.eden.art" if db == "PROD" else "staging2.app.eden.art"
return f"https://{root_url}/creations/{creation_id}"
29 changes: 25 additions & 4 deletions eve/clients/discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,27 @@ async def async_callback(message):
elif update_type == UpdateType.TOOL_COMPLETE:
result = data.get("result", {})
result["result"] = prepare_result(result["result"])
url = result["result"][0]["output"][0]["url"]
await self.send_message(channel, url, reference=reference)
output = result["result"][0]["output"][0]
url = output["url"]

# Get creation ID from the output
creation_id = str(output.get("creation"))

if creation_id:
eden_url = common.get_eden_creation_url(creation_id)
view = discord.ui.View()
view.add_item(
discord.ui.Button(
label="View on Eden",
url=eden_url,
style=discord.ButtonStyle.link,
)
)
await self.send_message(
channel, url, reference=reference, view=view
)
else:
await self.send_message(channel, url, reference=reference)

elif update_type == UpdateType.END_PROMPT:
await self.stop_typing(channel)
Expand Down Expand Up @@ -243,10 +262,12 @@ async def on_message(self, message: discord.Message) -> None:
async def on_member_join(self, member):
print(f"{member} has joined the guild id: {member.guild.id}")

async def send_message(self, channel, content, reference=None, limit=2000):
async def send_message(
self, channel, content, reference=None, limit=2000, view=None
):
for i in range(0, len(content), limit):
chunk = content[i : i + limit]
await channel.send(chunk, reference=reference)
await channel.send(chunk, reference=reference, view=view)

async def start_typing(self, channel):
"""
Expand Down

0 comments on commit 2ceda04

Please sign in to comment.