Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from discord.ext import commands
|
|
11 |
from discord.utils import oauth_url
|
12 |
import gradio_client as grc
|
13 |
from gradio_client.utils import QueueError
|
|
|
14 |
|
15 |
event = Event()
|
16 |
|
@@ -57,36 +58,38 @@ async def on_ready():
|
|
57 |
print(f"Add this bot to your server by clicking this link: {url}")
|
58 |
|
59 |
|
60 |
-
@bot.command(name="cryptoportfolio", help="Select a predefined sentence by typing it")
|
61 |
-
async def crypto_portfolio(ctx, *, input_text: str):
|
62 |
-
valid_choices = [
|
63 |
-
"Find the top performing cryptocurrencies of the day.",
|
64 |
-
"Find the top performing cryptocurrencies of the week.",
|
65 |
-
"Find the top performing cryptocurrencies of the month."
|
66 |
-
]
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
try:
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
await wait(job)
|
78 |
-
|
79 |
-
try:
|
80 |
-
job.result()
|
81 |
-
response = job.outputs()[-1]
|
82 |
-
await ctx.send(f"```{truncate_response(response)}```") # Send the LLM response
|
83 |
-
except QueueError:
|
84 |
-
await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
|
85 |
-
except Exception as e:
|
86 |
-
print(f"{e}")
|
87 |
-
else:
|
88 |
-
# Handle invalid input
|
89 |
-
await ctx.send("Invalid input. Please select one of the predefined sentences.")
|
90 |
|
91 |
|
92 |
@bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")
|
|
|
11 |
from discord.utils import oauth_url
|
12 |
import gradio_client as grc
|
13 |
from gradio_client.utils import QueueError
|
14 |
+
from discord_slash.model import SlashCommandOptionType as Option
|
15 |
|
16 |
event = Event()
|
17 |
|
|
|
58 |
print(f"Add this bot to your server by clicking this link: {url}")
|
59 |
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
@bot.event
|
63 |
+
async def on_ready():
|
64 |
+
# Bot ready event code
|
65 |
+
|
66 |
+
@bot.hybrid_command(name="cryptoportfolio", description="Select a predefined sentence")
|
67 |
+
async def crypto_portfolio(ctx,
|
68 |
+
selection: Option(str,
|
69 |
+
"Select an option",
|
70 |
+
choices=[
|
71 |
+
"Find the top performing cryptocurrencies of the day.",
|
72 |
+
"Find the top performing cryptocurrencies of the week.",
|
73 |
+
"Find the top performing cryptocurrencies of the month."
|
74 |
+
])):
|
75 |
+
try:
|
76 |
+
# Acknowledge the command
|
77 |
+
await ctx.send(f"Processing request: {selection}")
|
78 |
+
|
79 |
+
# Simulated external processing
|
80 |
+
loop = asyncio.get_running_loop()
|
81 |
+
client = await loop.run_in_executor(None, get_client, None)
|
82 |
+
job = client.submit(selection, api_name="/predict")
|
83 |
+
await wait(job)
|
84 |
+
|
85 |
try:
|
86 |
+
job.result()
|
87 |
+
response = job.outputs()[-1]
|
88 |
+
await ctx.send(f"```{truncate_response(response)}```") # Send the LLM response
|
89 |
+
except QueueError:
|
90 |
+
await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
|
91 |
+
except Exception as e:
|
92 |
+
print(f"{e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
|
95 |
@bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")
|