(response_content: str, data_response_content: str)
| 604 | |
| 605 | |
| 606 | def parse_evaluation_response(response_content: str, data_response_content: str) -> Dict: |
| 607 | # 首先按照原有逻辑解析主要的视觉评估结果 |
| 608 | evaluation = None |
| 609 | |
| 610 | # 尝试从response_content解析JSON |
| 611 | try: |
| 612 | evaluation = json.loads(response_content) |
| 613 | except json.JSONDecodeError: |
| 614 | pass |
| 615 | |
| 616 | # 尝试从代码块中解析JSON |
| 617 | if evaluation is None: |
| 618 | json_match = re.search(r'```json\s*\n(.*?)\n```', response_content, re.DOTALL) |
| 619 | if json_match: |
| 620 | try: |
| 621 | evaluation = json.loads(json_match.group(1)) |
| 622 | except json.JSONDecodeError: |
| 623 | pass |
| 624 | |
| 625 | # 尝试从任意JSON对象中解析 |
| 626 | if evaluation is None: |
| 627 | json_match = re.search(r'\{.*\}', response_content, re.DOTALL) |
| 628 | if json_match: |
| 629 | try: |
| 630 | evaluation = json.loads(json_match.group(0)) |
| 631 | except json.JSONDecodeError: |
| 632 | pass |
| 633 | |
| 634 | # 如果所有解析都失败,使用空的评估结构 |
| 635 | if evaluation is None: |
| 636 | evaluation = create_empty_evaluation() |
| 637 | |
| 638 | # 确保evaluation是字典类型,不是字符串 |
| 639 | if isinstance(evaluation, str): |
| 640 | evaluation = create_empty_evaluation() |
| 641 | |
| 642 | # 从data_response_content中提取<result>标签内容 |
| 643 | data_alignment = {'score': 0, 'reason': 'Data alignment not evaluated'} # 默认值 |
| 644 | |
| 645 | if data_response_content: |
| 646 | # 尝试提取 <result> 标签内容 |
| 647 | result_match = re.search(r'<result>(YES|NO)</result>', data_response_content, re.IGNORECASE) |
| 648 | if result_match: |
| 649 | result = result_match.group(1).upper() |
| 650 | if result == 'YES': |
| 651 | data_alignment = {'score': 2, 'reason': 'Data alignment confirmed - identical data usage across all subplots'} |
| 652 | else: |
| 653 | data_alignment = {'score': 0, 'reason': 'Data alignment failed - different data usage detected'} |
| 654 | |
| 655 | # 将data_alignment添加到评估结果中 |
| 656 | evaluation['data_alignment'] = data_alignment |
| 657 | |
| 658 | return evaluation |
| 659 | |
| 660 | |
| 661 | def create_empty_evaluation() -> Dict: |
no test coverage detected