Convert a string value to its appropriate type (int, float, bool, None, or keep as string). Work as a more broad 'eval()
(value: str)
| 98 | # 输出 JSON 字符串(可选择写入文件) |
| 99 | return result |
| 100 | def parse_value(value: str): |
| 101 | """Convert a string value to its appropriate type (int, float, bool, None, or keep as string). Work as a more broad 'eval()'""" |
| 102 | value = value.strip() |
| 103 | |
| 104 | if value == "null": |
| 105 | return None |
| 106 | elif value == "true": |
| 107 | return True |
| 108 | elif value == "false": |
| 109 | return False |
| 110 | else: |
| 111 | # Try to convert to int or float |
| 112 | try: |
| 113 | if '.' in value: # If there's a dot, it might be a float |
| 114 | return float(value) |
| 115 | else: |
| 116 | return int(value) |
| 117 | except ValueError: |
| 118 | # If conversion fails, return the value as-is (likely a string) |
| 119 | return value.strip('"') # Remove surrounding quotes if they exist |
| 120 | def extract_values_from_json(json_string, keys=["reasoning", "answer", "data"], allow_no_quotes=False): |
| 121 | """Extract key values from a non-standard or malformed JSON string, handling nested objects.""" |
| 122 | extracted_values = {} |
no outgoing calls
no test coverage detected