|
53 | 53 | _DISABLED_JUDGE_DEFAULT = AIJudgeConfigDefault.disabled() |
54 | 54 |
|
55 | 55 |
|
56 | | -def _parse_tools(tools_data: Optional[Dict[str, Any]]) -> Optional[Dict[str, LDTool]]: |
57 | | - """Parse the root-level tools map from a flag variation dict.""" |
58 | | - if not isinstance(tools_data, dict): |
59 | | - if tools_data is not None: |
60 | | - log.warning('Skipping tools: expected a dict, got %s', type(tools_data).__name__) |
61 | | - return None |
62 | | - result: Dict[str, LDTool] = {} |
63 | | - for tool_name, tool_dict in tools_data.items(): |
64 | | - if not isinstance(tool_dict, dict): |
65 | | - log.warning('Skipping tool "%s": expected a dict, got %s', tool_name, type(tool_dict).__name__) |
66 | | - continue |
67 | | - result[tool_name] = LDTool( |
68 | | - name=tool_dict.get('name', tool_name), |
69 | | - description=tool_dict.get('description'), |
70 | | - type=tool_dict.get('type'), |
71 | | - parameters=tool_dict.get('parameters'), |
72 | | - custom_parameters=tool_dict.get('customParameters'), |
73 | | - ) |
74 | | - return result or None |
75 | | - |
76 | | - |
77 | 56 | def _resolve_tools(variation: Dict[str, Any]) -> Optional[Dict[str, LDTool]]: |
78 | 57 | if 'tools' in variation: |
79 | | - return _parse_tools(variation['tools']) |
| 58 | + tools_data = variation['tools'] |
| 59 | + if not isinstance(tools_data, dict): |
| 60 | + return None |
| 61 | + tools: Dict[str, LDTool] = {} |
| 62 | + for tool_name, tool_dict in tools_data.items(): |
| 63 | + if isinstance(tool_dict, dict): |
| 64 | + tools[tool_name] = LDTool( |
| 65 | + name=str(tool_dict.get('name', tool_name)), |
| 66 | + description=tool_dict.get('description'), |
| 67 | + type=tool_dict.get('type'), |
| 68 | + parameters=tool_dict.get('parameters'), |
| 69 | + custom_parameters=tool_dict.get('customParameters'), |
| 70 | + ) |
| 71 | + else: |
| 72 | + log.warning('Skipping tool "%s": expected a dict, got %s', tool_name, type(tool_dict).__name__) |
| 73 | + return tools or None |
80 | 74 |
|
81 | 75 | model = variation.get('model') |
82 | 76 | if not isinstance(model, dict): |
83 | 77 | return None |
84 | 78 | parameters = model.get('parameters') |
85 | 79 | if not isinstance(parameters, dict): |
86 | 80 | return None |
87 | | - tools_data = parameters.get('tools') |
88 | | - if not isinstance(tools_data, dict): |
89 | | - if tools_data is not None: |
90 | | - log.warning('Skipping model.parameters.tools: expected a dict, got %s', type(tools_data).__name__) |
| 81 | + tools_list = parameters.get('tools') |
| 82 | + if not isinstance(tools_list, list): |
91 | 83 | return None |
92 | 84 |
|
93 | | - return _parse_tools(tools_data) |
| 85 | + tools = {} |
| 86 | + for item in tools_list: |
| 87 | + if not isinstance(item, dict): |
| 88 | + log.warning('Skipping tool entry: expected a dict, got %s', type(item).__name__) |
| 89 | + continue |
| 90 | + if not item.get('name'): |
| 91 | + log.warning('Skipping tool entry: missing name') |
| 92 | + continue |
| 93 | + tool_name = str(item['name']) |
| 94 | + tools[tool_name] = LDTool( |
| 95 | + name=tool_name, |
| 96 | + description=item.get('description'), |
| 97 | + type=item.get('type'), |
| 98 | + parameters=item.get('parameters'), |
| 99 | + custom_parameters=item.get('customParameters'), |
| 100 | + ) |
| 101 | + return tools or None |
94 | 102 |
|
95 | 103 |
|
96 | 104 | class LDAIClient: |
|
0 commit comments