Merge branch 'feature/multimodal-image-input' into developing
This commit is contained in:
commit
339144ad80
@ -81,11 +81,57 @@ class AgentConfig:
|
||||
'shell_env': self.shell_env,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _redact_image_data(messages):
|
||||
"""Return a copy of messages with image base64/data URL payloads truncated.
|
||||
|
||||
Image content blocks can carry huge base64 strings; replace them with a short
|
||||
placeholder so logs stay readable.
|
||||
"""
|
||||
if not isinstance(messages, list):
|
||||
return messages
|
||||
|
||||
def redact_value(value):
|
||||
if isinstance(value, str) and value.startswith('data:'):
|
||||
return value[:32] + '...[truncated]'
|
||||
return value
|
||||
|
||||
redacted_messages = []
|
||||
for message in messages:
|
||||
if not isinstance(message, dict):
|
||||
redacted_messages.append(message)
|
||||
continue
|
||||
content = message.get('content')
|
||||
if not isinstance(content, list):
|
||||
redacted_messages.append(message)
|
||||
continue
|
||||
redacted_content = []
|
||||
for block in content:
|
||||
if isinstance(block, dict) and block.get('type') in ('image', 'image_url'):
|
||||
new_block = block.copy()
|
||||
if 'base64' in new_block:
|
||||
new_block['base64'] = '[truncated]'
|
||||
if 'image_url' in new_block:
|
||||
image_url = new_block['image_url']
|
||||
if isinstance(image_url, dict):
|
||||
new_block['image_url'] = {**image_url, 'url': redact_value(image_url.get('url'))}
|
||||
else:
|
||||
new_block['image_url'] = redact_value(image_url)
|
||||
if 'url' in new_block:
|
||||
new_block['url'] = redact_value(new_block['url'])
|
||||
redacted_content.append(new_block)
|
||||
else:
|
||||
redacted_content.append(block)
|
||||
redacted_messages.append({**message, 'content': redacted_content})
|
||||
return redacted_messages
|
||||
|
||||
def safe_print(self):
|
||||
"""Safely log the configuration without printing sensitive information."""
|
||||
safe_dict = self.to_dict().copy()
|
||||
if 'api_key' in safe_dict and isinstance(safe_dict['api_key'], str) and safe_dict['api_key'].startswith('sk-'):
|
||||
safe_dict['api_key'] = safe_dict['api_key'][:8] + '***' + safe_dict['api_key'][-6:]
|
||||
if 'messages' in safe_dict:
|
||||
safe_dict['messages'] = self._redact_image_data(safe_dict['messages'])
|
||||
logger.info(f"config={json.dumps(safe_dict, ensure_ascii=False)}")
|
||||
|
||||
@classmethod
|
||||
|
||||
Loading…
Reference in New Issue
Block a user