Format content for logging, truncating if too long.
(
self, content: Optional[types.Content], max_length: int = 200
)
| 288 | print(formatted_message) |
| 289 | |
| 290 | def _format_content( |
| 291 | self, content: Optional[types.Content], max_length: int = 200 |
| 292 | ) -> str: |
| 293 | """Format content for logging, truncating if too long.""" |
| 294 | if not content or not content.parts: |
| 295 | return "None" |
| 296 | |
| 297 | parts = [] |
| 298 | for part in content.parts: |
| 299 | if part.text: |
| 300 | text = part.text.strip() |
| 301 | if len(text) > max_length: |
| 302 | text = text[:max_length] + "..." |
| 303 | parts.append(f"text: '{text}'") |
| 304 | elif part.function_call: |
| 305 | parts.append(f"function_call: {part.function_call.name}") |
| 306 | elif part.function_response: |
| 307 | parts.append(f"function_response: {part.function_response.name}") |
| 308 | elif part.code_execution_result: |
| 309 | parts.append("code_execution_result") |
| 310 | else: |
| 311 | parts.append("other_part") |
| 312 | |
| 313 | return " | ".join(parts) |
| 314 | |
| 315 | def _format_args(self, args: dict[str, Any], max_length: int = 300) -> str: |
| 316 | """Format arguments dictionary for logging.""" |
no test coverage detected