File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,9 +43,6 @@ def calculate_max_content_tokens(self, custom_prompt=None):
4343 Calculate the maximum tokens available for content based on prompt size.
4444 Dynamically adjusts for custom prompts to prevent exceeding context window.
4545 """
46- # Base system prompt size estimation
47- base_system_tokens = 100 # System message overhead
48-
4946 # Calculate custom prompt tokens if provided
5047 prompt_tokens = 0
5148 if custom_prompt :
@@ -63,9 +60,12 @@ def calculate_max_content_tokens(self, custom_prompt=None):
6360Does content violate this rule? JSON only:"""
6461 # Count tokens for the prompt parts (excluding content placeholder)
6562 prompt_tokens = self .count_tokens (system_message ) + self .count_tokens (user_template )
63+ else :
64+ # For default moderation, estimate prompt overhead
65+ prompt_tokens = 150 # Typical system + user message without content
6666
67- # Total overhead = base + prompt + output + safety margin
68- total_overhead = base_system_tokens + prompt_tokens + self .max_output_tokens
67+ # Total overhead = prompt + output tokens + small buffer for message formatting
68+ total_overhead = prompt_tokens + self .max_output_tokens + 50 # 50 for message structure overhead
6969 safety_margin = 0.90 # Use 90% of available capacity
7070
7171 available_for_content = int (
Original file line number Diff line number Diff line change @@ -21,8 +21,9 @@ class Config:
2121 OPENAI_CONTEXT_WINDOW = int (os .environ .get (
2222 'OPENAI_CONTEXT_WINDOW' , '272000' ))
2323 # Upper bound for output tokens; actual requests may use much less
24+ # AI moderator only returns small JSON responses (~100-200 tokens), so 500 is plenty
2425 OPENAI_MAX_OUTPUT_TOKENS = int (os .environ .get (
25- 'OPENAI_MAX_OUTPUT_TOKENS' , '128000 ' ))
26+ 'OPENAI_MAX_OUTPUT_TOKENS' , '500 ' ))
2627 ADMIN_EMAIL = os .environ .get ('ADMIN_EMAIL' )
2728 ADMIN_PASSWORD = os .environ .get ('ADMIN_PASSWORD' )
2829
You can’t perform that action at this time.
0 commit comments