7
7
from typing import List , Dict , Any
8
8
from discord .ext import commands
9
9
from discord .ui import View
10
- from adala .environments .servers .base import BaseAPI , Prediction , GroundTruth , STORAGE_DB
10
+ from adala .environments .servers .base import BaseAPI , Feedback , STORAGE_DB
11
11
12
12
13
13
intents = discord .Intents .default ()
@@ -43,17 +43,17 @@ async def on_message(message):
43
43
initial_message_id = message .reference .message_id
44
44
print (f'Got reply in thread for message id: { initial_message_id } ' , message )
45
45
async with aiosqlite .connect (STORAGE_DB ) as db :
46
- async with db .execute ('SELECT * FROM discord_gt_message WHERE message_id = ?' , (initial_message_id ,)) as cursor :
46
+ async with db .execute ('SELECT * FROM discord_fb_message WHERE message_id = ?' , (initial_message_id ,)) as cursor :
47
47
row = await cursor .fetchone ()
48
48
if row is None :
49
49
print (f'No ground truth message found for message id: { initial_message_id } ' )
50
50
return
51
- prediction_id , skill_name = int (row [1 ]), row [2 ]
51
+ prediction_id , prediction_column = int (row [1 ]), row [2 ]
52
52
53
53
# update ground truth with reply
54
- await db .execute ('UPDATE ground_truth SET gt_data = ? '
55
- 'WHERE prediction_id = ? AND skill_name = ?' ,
56
- (message .content , prediction_id , skill_name ))
54
+ await db .execute ('UPDATE feedback SET fb_message = ? '
55
+ 'WHERE prediction_id = ? AND prediction_column = ?' ,
56
+ (message .content , prediction_id , prediction_column ))
57
57
await db .commit ()
58
58
59
59
# Process other messages normally
@@ -63,46 +63,46 @@ async def on_message(message):
63
63
@bot .event
64
64
async def on_interaction (interaction : discord .Interaction ):
65
65
66
- async def update_ground_truth_match (prediction_id : int , skill_name : str , match : bool ):
66
+ async def update_feedback_match (prediction_id : int , prediction_column : str , match : bool ):
67
67
async with aiosqlite .connect (STORAGE_DB ) as db :
68
- await db .execute ('UPDATE ground_truth SET gt_match = ?, gt_data = NULL '
69
- 'WHERE prediction_id = ? AND skill_name = ?' ,
70
- (match , prediction_id , skill_name ))
68
+ await db .execute ('UPDATE feedback SET fb_match = ?, fb_message = NULL '
69
+ 'WHERE prediction_id = ? AND prediction_column = ?' ,
70
+ (match , prediction_id , prediction_column ))
71
71
await db .commit ()
72
72
print (f'Updated ground truth for prediction id: { prediction_id } with match: { match } ' )
73
73
74
74
if interaction .type == discord .InteractionType .component :
75
75
await interaction .response .defer (ephemeral = True )
76
76
77
77
custom_id = interaction .data ['custom_id' ]
78
- action , prediction_id_str , skill_name = custom_id .split (':' )
78
+ action , prediction_id_str , prediction_column = custom_id .split (':' )
79
79
prediction_id = int (prediction_id_str ) # Convert prediction_id to int
80
80
81
81
if action == 'accept' :
82
82
# Handle the accept action
83
- await update_ground_truth_match (prediction_id , skill_name , True )
83
+ await update_feedback_match (prediction_id , prediction_column , True )
84
84
# React with a checkmark emoji to the message
85
85
await interaction .message .add_reaction ('✅' )
86
86
elif action == 'reject' :
87
87
# Handle the reject action
88
- await update_ground_truth_match (prediction_id , skill_name , False )
88
+ await update_feedback_match (prediction_id , prediction_column , False )
89
89
# React with a cross mark emoji to the message
90
90
await interaction .message .add_reaction ('❌' )
91
91
92
92
93
93
class AcceptRejectView (View ):
94
94
95
- def __init__ (self , prediction_id : int , skill_name : str , * args , ** kwargs ):
95
+ def __init__ (self , prediction_id : int , prediction_column : str , * args , ** kwargs ):
96
96
super ().__init__ (* args , ** kwargs )
97
97
self .add_item (discord .ui .Button (
98
98
label = 'Accept' ,
99
99
style = discord .ButtonStyle .success ,
100
- custom_id = f'accept:{ prediction_id } :{ skill_name } '
100
+ custom_id = f'accept:{ prediction_id } :{ prediction_column } '
101
101
))
102
102
self .add_item (discord .ui .Button (
103
103
label = 'Reject' ,
104
104
style = discord .ButtonStyle .danger ,
105
- custom_id = f'reject:{ prediction_id } :{ skill_name } '
105
+ custom_id = f'reject:{ prediction_id } :{ prediction_column } '
106
106
))
107
107
108
108
async def interaction_check (self , interaction : discord .Interaction ) -> bool :
@@ -115,10 +115,10 @@ class DiscordAPI(BaseAPI):
115
115
async def init_db_gt_message (self ):
116
116
async with aiosqlite .connect (STORAGE_DB ) as db :
117
117
await db .execute ('''
118
- CREATE TABLE IF NOT EXISTS discord_gt_message (
118
+ CREATE TABLE IF NOT EXISTS discord_fb_message (
119
119
id INTEGER PRIMARY KEY AUTOINCREMENT,
120
120
prediction_id INTEGER NOT NULL,
121
- skill_name TEXT NOT NULL,
121
+ prediction_column TEXT NOT NULL,
122
122
message_id INTEGER NOT NULL
123
123
)
124
124
''' )
@@ -140,29 +140,29 @@ async def request_feedback(
140
140
channel = bot .get_channel (CHANNEL_ID )
141
141
if not channel :
142
142
raise Exception (f'Channel with id { CHANNEL_ID } not found' )
143
- ground_truths = []
143
+ fbs = []
144
144
skill_outputs = sum ([skill ['outputs' ] for skill in skills ], [])
145
145
for skill_output in skill_outputs :
146
146
for prediction in predictions :
147
147
text = '========================\n '
148
148
text += '\n ' .join (f'**{ k } **: { v } ' for k , v in prediction .items () if k not in skill_outputs + ['index' ])
149
149
text += f'\n \n __**{ skill_output } **__: { prediction [skill_output ]} '
150
- ground_truth = GroundTruth ( prediction_id = prediction [ 'index' ], skill_name = skill_output )
151
-
150
+ text = text [: 2000 ]
151
+ fb = Feedback ( prediction_id = prediction [ 'index' ], prediction_column = skill_output )
152
152
message = await channel .send (
153
153
text , view = AcceptRejectView (
154
- prediction_id = ground_truth .prediction_id ,
155
- skill_name = ground_truth . skill_name )
154
+ prediction_id = fb .prediction_id ,
155
+ prediction_column = fb . prediction_column )
156
156
)
157
- ground_truths .append (ground_truth )
157
+ fbs .append (fb )
158
158
await db .execute ('''
159
- INSERT INTO discord_gt_message (prediction_id, skill_name , message_id)
159
+ INSERT INTO discord_fb_message (prediction_id, prediction_column , message_id)
160
160
VALUES (?, ?, ?)
161
- ''' , (ground_truth .prediction_id , ground_truth . skill_name , message .id ))
161
+ ''' , (fb .prediction_id , fb . prediction_column , message .id ))
162
162
await db .commit ()
163
163
164
164
# TODO: do we need to store it in advance?
165
- await self .store_ground_truths ( ground_truths , db )
165
+ await self .store_feedback ( fbs , db )
166
166
167
167
168
168
app = DiscordAPI ()
0 commit comments