递归清除 JSON Schema 中 DeepSeek 不支持的字段
(obj)
| 101 | |
| 102 | |
| 103 | def _clean_schema(obj): |
| 104 | """递归清除 JSON Schema 中 DeepSeek 不支持的字段""" |
| 105 | if not isinstance(obj, dict): |
| 106 | return obj |
| 107 | cleaned = {} |
| 108 | for k, v in obj.items(): |
| 109 | if k in ("additionalProperties", "strict"): |
| 110 | continue |
| 111 | if isinstance(v, dict): |
| 112 | cleaned[k] = _clean_schema(v) |
| 113 | elif isinstance(v, list): |
| 114 | cleaned[k] = [_clean_schema(i) if isinstance(i, dict) else i for i in v] |
| 115 | else: |
| 116 | cleaned[k] = v |
| 117 | return cleaned |
| 118 | |
| 119 | |
| 120 | def _convert_tools(tools: list) -> list: |