mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-28 16:20:34 +08:00
Added buttons and commands to bot
This commit is contained in:
+67
-1
@@ -52,6 +52,39 @@ intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
client = OpenChatGPTClient(intents=intents)
|
||||
|
||||
class LikeButton(discord.ui.Button):
|
||||
def __init__(self, label, channel, username, prompt):
|
||||
super().__init__(label=label, style=discord.ButtonStyle.green, emoji="👍")
|
||||
self.channel = channel
|
||||
self.username = username
|
||||
self.prompt = prompt
|
||||
async def callback(self, interaction):
|
||||
# interaction holds the interaction object
|
||||
#await interaction.response.defer()
|
||||
await interaction.response.send_message("Thanks for your feedback. You liked this 👍 ")
|
||||
|
||||
class NeutralButton(discord.ui.Button):
|
||||
def __init__(self, label, channel, username, prompt):
|
||||
super().__init__(label=label, style=discord.ButtonStyle.green, emoji="😐")
|
||||
self.channel = channel
|
||||
self.username = username
|
||||
self.prompt = prompt
|
||||
async def callback(self, interaction):
|
||||
# interaction holds the interaction object
|
||||
#await interaction.response.defer()
|
||||
await interaction.response.send_message("Thanks for your feedback. You thought this was neutral 😐 ")
|
||||
|
||||
class DislikeButton(discord.ui.Button):
|
||||
def __init__(self, label, channel, username, prompt):
|
||||
super().__init__(label=label, style=discord.ButtonStyle.green, emoji="👎")
|
||||
self.channel = channel
|
||||
self.username = username
|
||||
self.prompt = prompt
|
||||
async def callback(self, interaction):
|
||||
# interaction holds the interaction object
|
||||
#await interaction.response.defer()
|
||||
# send the feedback to the backend #
|
||||
await interaction.response.send_message("Thanks for your feedback. You disliked this 👎 ")
|
||||
|
||||
@client.tree.command()
|
||||
async def register(interaction: discord.Interaction):
|
||||
@@ -80,6 +113,37 @@ async def list_participants(interaction: discord.Interaction):
|
||||
await interaction.response.send_message("Failed to fetch participants")
|
||||
|
||||
|
||||
async def send_propmt_with_response_and_buttons(channel, username, prompt, response):
|
||||
await channel.send(f'What do you think about the following interaction: \nprompt: {prompt} \nresponse: {response}')
|
||||
#await channel.send(f'Please click on the button that best describes your reaction to the response:')
|
||||
|
||||
# add buttons
|
||||
view = discord.ui.View()
|
||||
like=LikeButton(label="Like", channel=channel, username=username, prompt=prompt)
|
||||
neutral=NeutralButton(label="Neutral", channel=channel, username=username, prompt=prompt)
|
||||
dislike=DislikeButton(label="Dislike", channel=channel, username=username, prompt=prompt)
|
||||
|
||||
view.add_item(item=like)
|
||||
view.add_item(item=neutral)
|
||||
view.add_item(item=dislike)
|
||||
await channel.send(view=view)
|
||||
|
||||
|
||||
@client.tree.command()
|
||||
async def review_prompts(interaction: discord.Interaction, number_of_prompts: int):
|
||||
# get the prompt from the db
|
||||
url = f"{prompts_url}?begin_id=0&limit={number_of_prompts}"
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
prompts = response.json()
|
||||
print("the responses are", prompts)
|
||||
for prompt in prompts:
|
||||
await send_propmt_with_response_and_buttons(interaction.channel, interaction.user.name, prompt['prompt'], prompt["response"])
|
||||
else:
|
||||
await interaction.response.send_message("Failed to get prompts for review")
|
||||
|
||||
|
||||
|
||||
@client.tree.command()
|
||||
async def add_prompt(interaction: discord.Interaction, prompt: str, response: str, language: str = "en"):
|
||||
"""Uploads a single prompt to the server."""
|
||||
@@ -92,7 +156,9 @@ async def add_prompt(interaction: discord.Interaction, prompt: str, response: st
|
||||
}
|
||||
response = requests.post(prompts_url, headers=headers, json=prompt)
|
||||
if response.status_code == 200:
|
||||
await interaction.response.send_message("Added your prompt")
|
||||
await send_propmt_with_response_and_buttons(interaction.channel, interaction.user.name, prompt['prompt'], prompt["response"])
|
||||
# send the prompt back with buttons for the user to click on
|
||||
#await interaction.response.send_message("Added your prompt")
|
||||
else:
|
||||
await interaction.response.send_message("Failed to add the prompt")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user