Compute sha256 hash of a message block for comparison
(self, block: List[Message])
| 359 | return blocks |
| 360 | |
| 361 | def _hash_block(self, block: List[Message]) -> str: |
| 362 | """Compute sha256 hash of a message block for comparison""" |
| 363 | data = [message.to_dict_clean() for message in block] |
| 364 | allow_role = ['user', 'system', 'assistant', 'tool'] |
| 365 | allow_role = [ |
| 366 | role for role in allow_role if role not in self.ignore_roles |
| 367 | ] |
| 368 | allow_fields = ['reasoning_content', 'content', 'tool_calls', 'role'] |
| 369 | allow_fields = [ |
| 370 | field for field in allow_fields if field not in self.ignore_fields |
| 371 | ] |
| 372 | |
| 373 | data = [{ |
| 374 | field: value |
| 375 | for field, value in msg.items() if field in allow_fields |
| 376 | } for msg in data if msg['role'] in allow_role] |
| 377 | |
| 378 | block_data = json5.dumps(data) |
| 379 | return hashlib.sha256(block_data.encode('utf-8')).hexdigest() |
| 380 | |
| 381 | def _analyze_messages( |
| 382 | self, |
no test coverage detected