mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
RM Iffy util
This commit is contained in:
@@ -68,7 +68,7 @@ from backend.util.service import (
|
||||
)
|
||||
from backend.util.settings import Settings, BehaveAs
|
||||
from backend.util.type import convert
|
||||
from backend.util.iffy import send_to_iffy
|
||||
from backend.server.v2.iffy.service import IffyService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
settings = Settings()
|
||||
@@ -1197,12 +1197,12 @@ class ExecutionManager(AppService):
|
||||
"input_data": input_data
|
||||
}
|
||||
|
||||
# Send to Iffy for moderation.
|
||||
is_safe, reason = await send_to_iffy(user_id, block_content)
|
||||
# Send to Iffy for moderation using the service directly
|
||||
result = await IffyService._moderate_content(user_id, block_content)
|
||||
|
||||
# CRITICAL: Ensure we never proceed if iffy and openrouter moderation fails
|
||||
if not is_safe:
|
||||
logger.error(f"Content moderation failed for {block.name}: {reason}")
|
||||
# CRITICAL: Ensure we never proceed if moderation fails
|
||||
if not result.is_safe:
|
||||
logger.error(f"Content moderation failed for {block.name}: {result.reason}")
|
||||
raise ValueError(f"Content moderation failed for {block.name}")
|
||||
|
||||
except ValueError as ve:
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import logging
|
||||
from typing import Any, Dict, Tuple
|
||||
import json
|
||||
from backend.server.v2.iffy.service import IffyService
|
||||
from backend.util.settings import Settings
|
||||
from backend.util.openrouter import open_router_moderate_content
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
settings = Settings()
|
||||
|
||||
async def send_to_iffy(user_id: str, block_content: Dict[str, Any]) -> Tuple[bool, str]:
|
||||
"""
|
||||
Send block content to Iffy for content moderation.
|
||||
Only used in cloud mode - local mode skips moderation entirely.
|
||||
|
||||
Args:
|
||||
user_id: The ID of the user executing the block
|
||||
block_content: The content of the block to be moderated
|
||||
|
||||
Returns:
|
||||
Tuple[bool, str]: (is_safe, reason)
|
||||
- is_safe: True if content was sent to Iffy successfully or passed OpenRouter moderation,
|
||||
False if both services failed or content was flagged
|
||||
- reason: Description of the result or error
|
||||
"""
|
||||
# Use the IffyService to handle moderation
|
||||
try:
|
||||
result = await IffyService._moderate_content(user_id, block_content)
|
||||
return result.is_safe, result.reason
|
||||
except Exception as e:
|
||||
logger.error(f"Error in IffyService: {str(e)}", exc_info=True)
|
||||
# Fall back to OpenRouter as a last resort
|
||||
try:
|
||||
is_safe, reason = await open_router_moderate_content(json.dumps(block_content.get('input_data', {}), indent=2))
|
||||
return is_safe, f"IffyService error, OpenRouter fallback: {reason}"
|
||||
except Exception as e2:
|
||||
logger.error(f"Both moderation services failed: {str(e2)}", exc_info=True)
|
||||
return False, f"All moderation services failed: {str(e)}, {str(e2)}"
|
||||
Reference in New Issue
Block a user