获取模型详细信息 Args: model_name: 模型名称 Returns: 模型信息字典
(self, model_name: str)
| 147 | return validation_results |
| 148 | |
| 149 | def get_model_info(self, model_name: str) -> Dict[str, Any]: |
| 150 | """ |
| 151 | 获取模型详细信息 |
| 152 | |
| 153 | Args: |
| 154 | model_name: 模型名称 |
| 155 | |
| 156 | Returns: |
| 157 | 模型信息字典 |
| 158 | """ |
| 159 | model_path = self.get_model_path(model_name, create_if_missing=False) |
| 160 | if not model_path: |
| 161 | return {'exists': False} |
| 162 | |
| 163 | path_obj = Path(model_path) |
| 164 | info = { |
| 165 | 'exists': True, |
| 166 | 'path': str(path_obj), |
| 167 | 'is_directory': path_obj.is_dir(), |
| 168 | 'size_mb': 0, |
| 169 | 'files': [] |
| 170 | } |
| 171 | |
| 172 | try: |
| 173 | if path_obj.is_dir(): |
| 174 | # 计算目录大小和文件列表 |
| 175 | total_size = 0 |
| 176 | files = [] |
| 177 | for file_path in path_obj.rglob('*'): |
| 178 | if file_path.is_file(): |
| 179 | size = file_path.stat().st_size |
| 180 | total_size += size |
| 181 | files.append({ |
| 182 | 'name': file_path.name, |
| 183 | 'relative_path': str(file_path.relative_to(path_obj)), |
| 184 | 'size_mb': round(size / (1024 * 1024), 2) |
| 185 | }) |
| 186 | info['size_mb'] = round(total_size / (1024 * 1024), 2) |
| 187 | info['files'] = files |
| 188 | else: |
| 189 | # 单个文件 |
| 190 | size = path_obj.stat().st_size |
| 191 | info['size_mb'] = round(size / (1024 * 1024), 2) |
| 192 | info['files'] = [{'name': path_obj.name, 'size_mb': info['size_mb']}] |
| 193 | except Exception as e: |
| 194 | logger.error(f"获取模型信息失败: {e}") |
| 195 | info['error'] = str(e) |
| 196 | |
| 197 | return info |
| 198 | |
| 199 | |
| 200 | # 全局权重管理器实例 |
nothing calls this directly
no test coverage detected