Skip to content

Commit 398630f

Browse files
committed
Refactor logging for early exit in chunk rejection
Simplifies the logging statement when a chunk is rejected by calculating the number of remaining chunks in a variable and using it in the log message. This improves readability and maintainability.
1 parent c5ad918 commit 398630f

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

app/services/ai/ai_moderator.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ def moderate_content(self, content, content_type='text', custom_prompt=None):
339339

340340
# Early exit: if any chunk is rejected, cancel remaining and return immediately
341341
if result.get('decision') == 'rejected':
342+
remaining = len(future_to_chunk) - len(chunk_results)
342343
current_app.logger.info(
343-
f"Early exit: Chunk rejected, cancelling {
344-
len(future_to_chunk) - len(chunk_results)} remaining chunks")
344+
f"Early exit: Chunk rejected, cancelling {remaining} remaining chunks")
345345

346346
# Cancel all pending futures
347347
for f in future_to_chunk:
@@ -388,10 +388,9 @@ def moderate_content(self, content, content_type='text', custom_prompt=None):
388388

389389
# Early exit: if any chunk is rejected, cancel remaining and return immediately
390390
if result.get('decision') == 'rejected':
391+
remaining = len(future_to_chunk) - len(chunk_results)
391392
current_app.logger.info(
392-
f"Early exit: Chunk rejected, cancelling {
393-
len(future_to_chunk) -
394-
len(chunk_results)} remaining chunks")
393+
f"Early exit: Chunk rejected, cancelling {remaining} remaining chunks")
395394

396395
# Cancel all pending futures
397396
for f in future_to_chunk:

0 commit comments

Comments
 (0)