CryptoScoutv1 commited on
Commit
f969e96
·
verified ·
1 Parent(s): 30990d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -65,20 +65,31 @@ async def chat(ctx, prompt: str):
65
  if ctx.author.id == bot.user.id:
66
  return
67
  try:
68
- # Acknowledge the command immediately - This is the discord message after the command / is called ##
69
- await ctx.send(f"Processing request: {prompt}")
70
 
 
 
 
 
 
 
 
71
  loop = asyncio.get_running_loop()
72
  client = await loop.run_in_executor(None, get_client, None)
73
- job = client.submit(prompt, api_name="/predict") ## /predict can be used for gradio interface ##
74
  await wait(job)
75
 
76
  try:
77
  job.result()
78
  response = job.outputs()[-1]
79
- await ctx.send(f"```{truncate_response(response)}```") # Send the LLM response
 
 
80
  except QueueError:
81
- await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
 
 
 
82
  except Exception as e:
83
  print(f"{e}")
84
 
 
65
  if ctx.author.id == bot.user.id:
66
  return
67
  try:
68
+ message = await ctx.send("Creating thread...")
 
69
 
70
+ # User triggered bot via !echo
71
+ if ctx.message.content:
72
+ prompt = ctx.message.content.replace(
73
+ f"{bot.command_prefix}echo", ""
74
+ ).strip()
75
+
76
+ thread = await message.create_thread(name=prompt)
77
  loop = asyncio.get_running_loop()
78
  client = await loop.run_in_executor(None, get_client, None)
79
+ job = client.submit(prompt, api_name="/predict")
80
  await wait(job)
81
 
82
  try:
83
  job.result()
84
  response = job.outputs()[-1]
85
+ await thread.send(truncate_response(response))
86
+ thread_to_client[thread.id] = client
87
+ thread_to_user[thread.id] = ctx.author.id
88
  except QueueError:
89
+ await thread.send(
90
+ "The gradio space powering this bot is really busy! Please try again later!"
91
+ )
92
+
93
  except Exception as e:
94
  print(f"{e}")
95