@@ -150,8 +150,8 @@ def flag_question(
150
150
question : Question ,
151
151
by_user : User ,
152
152
notes : str ,
153
- status : int = FlaggedObject .FLAG_PENDING ,
154
- reason : str = FlaggedObject .REASON_CONTENT_MODERATION ,
153
+ status : int = FlaggedObject .FLAG_ACCEPTED ,
154
+ reason : str = FlaggedObject .REASON_SPAM ,
155
155
) -> None :
156
156
content_type = ContentType .objects .get_for_model (question )
157
157
flagged_object , created = FlaggedObject .objects .get_or_create (
@@ -214,17 +214,6 @@ def update_question_fields_from_classification(question, result, sumo_bot):
214
214
question .tags .clear ()
215
215
question .auto_tag ()
216
216
217
- if topic := update_fields .get ("topic" ):
218
- flag_question (
219
- question ,
220
- by_user = sumo_bot ,
221
- notes = (
222
- f"LLM classified as { topic .title } , for the following reason:\n "
223
- f"{ topic_result .get ('reason' , '' )} "
224
- ),
225
- status = FlaggedObject .FLAG_ACCEPTED ,
226
- )
227
-
228
217
229
218
def process_classification_result (
230
219
question : Question ,
@@ -236,19 +225,44 @@ def process_classification_result(
236
225
"""
237
226
sumo_bot = Profile .get_sumo_bot ()
238
227
action = result .get ("action" )
228
+ flag_kwargs = {
229
+ "by_user" : sumo_bot ,
230
+ "notes" : "" ,
231
+ "question" : question ,
232
+ }
239
233
240
234
match action :
241
235
case ModerationAction .SPAM :
236
+ flag_kwargs .update (
237
+ {
238
+ "notes" : (
239
+ f"LLM classified as spam, for the following reason:\n "
240
+ f"{ result .get ('spam_result' , {}).get ('reason' , '' )} "
241
+ ),
242
+ }
243
+ )
242
244
question .mark_as_spam (sumo_bot )
243
245
case ModerationAction .FLAG_REVIEW :
244
- flag_question (
245
- question ,
246
- by_user = sumo_bot ,
247
- notes = (
248
- "LLM flagged for manual review, for the following reason:\n "
249
- f"{ result .get ('spam_result' , {}).get ('reason' , '' )} "
250
- ),
251
- reason = FlaggedObject . REASON_SPAM ,
246
+ flag_kwargs . update (
247
+ {
248
+ "status" : FlaggedObject . FLAG_PENDING ,
249
+ " notes" : (
250
+ f "LLM flagged for manual review, for the following reason:\n "
251
+ f"{ result .get ('spam_result' , {}).get ('reason' , '' )} "
252
+ ),
253
+ }
252
254
)
253
255
case _:
256
+ flag_kwargs .update (
257
+ {
258
+ "reason" : FlaggedObject .REASON_CONTENT_MODERATION ,
259
+ "notes" : (
260
+ f"LLM classified as { result .get ('topic_result' , {}).get ('topic' , '' )} , "
261
+ f"for the following reason:\n "
262
+ f"{ result .get ('topic_result' , {}).get ('reason' , '' )} "
263
+ ),
264
+ }
265
+ )
254
266
update_question_fields_from_classification (question , result , sumo_bot )
267
+
268
+ flag_question (** flag_kwargs )
0 commit comments