MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / _truncate_large_fields

Method _truncate_large_fields

src/core/logger.py:60–84  ·  view source on GitHub ↗

对大字段进行截断处理,特别是 base64 编码的图片数据 Args: data: 要处理的数据 max_length: 字符串字段的最大长度 Returns: 截断后的数据副本

(self, data: Any, max_length: int = 200)

Source from the content-addressed store, hash-verified

58 self.logger.info(char * length)
59
60 def _truncate_large_fields(self, data: Any, max_length: int = 200) -> Any:
61 """对大字段进行截断处理,特别是 base64 编码的图片数据
62
63 Args:
64 data: 要处理的数据
65 max_length: 字符串字段的最大长度
66
67 Returns:
68 截断后的数据副本
69 """
70 if isinstance(data, dict):
71 result = {}
72 for key, value in data.items():
73 # 对特定的大字段进行截断
74 if key in ("encodedImage", "base64", "imageData", "data") and isinstance(value, str) and len(value) > max_length:
75 result[key] = f"{value[:100]}... (truncated, total {len(value)} chars)"
76 else:
77 result[key] = self._truncate_large_fields(value, max_length)
78 return result
79 elif isinstance(data, list):
80 return [self._truncate_large_fields(item, max_length) for item in data]
81 elif isinstance(data, str) and len(data) > 10000:
82 # 对超长字符串进行截断(可能是未知的 base64 字段)
83 return f"{data[:100]}... (truncated, total {len(data)} chars)"
84 return data
85
86 def log_request(
87 self,

Callers 1

log_responseMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected