Kevin Hu
commited on
Commit
·
47f7da5
1
Parent(s):
9309ea5
add inferface for message thumbup (#2091)
Browse files### What problem does this PR solve?
#2088
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- api/apps/conversation_app.py +24 -1
api/apps/conversation_app.py
CHANGED
|
@@ -178,7 +178,7 @@ def completion():
|
|
| 178 |
@manager.route('/delete_msg', methods=['POST'])
|
| 179 |
@login_required
|
| 180 |
@validate_request("conversation_id", "message_id")
|
| 181 |
-
def
|
| 182 |
req = request.json
|
| 183 |
e, conv = ConversationService.get_by_id(req["conversation_id"])
|
| 184 |
if not e:
|
|
@@ -196,3 +196,26 @@ def completion():
|
|
| 196 |
|
| 197 |
ConversationService.update_by_id(conv["id"], conv)
|
| 198 |
return get_json_result(data=conv)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
@manager.route('/delete_msg', methods=['POST'])
|
| 179 |
@login_required
|
| 180 |
@validate_request("conversation_id", "message_id")
|
| 181 |
+
def delete_msg():
|
| 182 |
req = request.json
|
| 183 |
e, conv = ConversationService.get_by_id(req["conversation_id"])
|
| 184 |
if not e:
|
|
|
|
| 196 |
|
| 197 |
ConversationService.update_by_id(conv["id"], conv)
|
| 198 |
return get_json_result(data=conv)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
@manager.route('/thumbup', methods=['POST'])
|
| 202 |
+
@login_required
|
| 203 |
+
@validate_request("conversation_id", "message_id")
|
| 204 |
+
def thumbup():
|
| 205 |
+
req = request.json
|
| 206 |
+
e, conv = ConversationService.get_by_id(req["conversation_id"])
|
| 207 |
+
if not e:
|
| 208 |
+
return get_data_error_result(retmsg="Conversation not found!")
|
| 209 |
+
up_down = req.get("set")
|
| 210 |
+
feedback = req.get("feedback", "")
|
| 211 |
+
conv = conv.to_dict()
|
| 212 |
+
for i, msg in enumerate(conv["message"]):
|
| 213 |
+
if req["message_id"] == msg.get("id", "") and msg.get("role", "") == "assistant":
|
| 214 |
+
if up_down: msg["thumbup"] = True
|
| 215 |
+
else:
|
| 216 |
+
msg["thumbup"] = False
|
| 217 |
+
msg["feedback"] = feedback
|
| 218 |
+
break
|
| 219 |
+
|
| 220 |
+
ConversationService.update_by_id(conv["id"], conv)
|
| 221 |
+
return get_json_result(data=conv)
|