| @@ -1,20 +1,11 @@ | |||
| package ai | |||
| import ( | |||
| "encoding/json" | |||
| "fmt" | |||
| ) | |||
| type CreateAlgorithmParameter interface { | |||
| AlgorithmCreateParam() | |||
| } | |||
| type CreateAlgorithmReq struct { | |||
| Name string `json:"name" binding:"required"` | |||
| ClusterId string `json:"clusterId,omitempty"` | |||
| Desc string `json:"desc,omitempty"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param CreateAlgorithmParameter `json:"param,omitempty"` | |||
| Name string `json:"name" binding:"required"` | |||
| ClusterId string `json:"clusterId,omitempty"` | |||
| Desc string `json:"desc,omitempty"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param interface{} `json:"param,omitempty"` | |||
| } | |||
| type CreateAlgorithmResp struct { | |||
| @@ -22,62 +13,3 @@ type CreateAlgorithmResp struct { | |||
| Msg string `json:"msg,omitempty" copier:"Msg"` | |||
| ErrorMsg string `json:"errorMsg,omitempty" copier:"ErrorMsg"` | |||
| } | |||
| type OpenIAlgorithm struct { | |||
| BootFile string `json:"bootFile,omitempty"` | |||
| DefaultBranch string `json:"defaultBranch,omitempty"` | |||
| } | |||
| func (o *OpenIAlgorithm) AlgorithmCreateParam() { | |||
| } | |||
| type OctopusAlgorithm struct { | |||
| } | |||
| func (o *OctopusAlgorithm) AlgorithmCreateParam() { | |||
| } | |||
| func (cp *CreateAlgorithmReq) UnmarshalJSON(data []byte) error { | |||
| // 临时结构体:用于捕获原始 JSON 中的 param 字段数据 | |||
| type TempCreateParam struct { | |||
| Name string `json:"name"` | |||
| ClusterId string `json:"clusterId"` | |||
| Desc string `json:"desc"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param json.RawMessage `json:"param,omitempty"` // 捕获原始 JSON 数据 | |||
| } | |||
| var temp TempCreateParam | |||
| if err := json.Unmarshal(data, &temp); err != nil { | |||
| return err | |||
| } | |||
| // 将临时结构体的字段赋值给原结构体(除 Param 外) | |||
| cp.Name = temp.Name | |||
| cp.ClusterId = temp.ClusterId | |||
| cp.Desc = temp.Desc | |||
| cp.Src = temp.Src | |||
| // 解析 param 字段的原始数据为具体类型 | |||
| if temp.Param != nil { | |||
| // 尝试解析为 OpenI 类型 | |||
| var openi OpenIAlgorithm | |||
| if err := json.Unmarshal(temp.Param, &openi); err != nil { | |||
| // 打印详细错误(如字段不匹配、类型错误等) | |||
| fmt.Printf("解析 OpenI 失败: %v\n", err) // 关键调试日志 | |||
| } else { | |||
| cp.Param = &openi | |||
| return nil | |||
| } | |||
| // 新增:尝试解析为 Octopus 类型 | |||
| var octopus OctopusAlgorithm | |||
| if err := json.Unmarshal(temp.Param, &octopus); err == nil { | |||
| cp.Param = &octopus | |||
| return nil | |||
| } | |||
| return fmt.Errorf("unsupported param type in CreateParam") | |||
| } | |||
| return nil | |||
| } | |||
| @@ -1,20 +1,11 @@ | |||
| package ai | |||
| import ( | |||
| "encoding/json" | |||
| "fmt" | |||
| ) | |||
| type CreateDatasetParameter interface { | |||
| DatasetCreateParam() | |||
| } | |||
| type CreateDatasetReq struct { | |||
| Name string `json:"name" binding:"required"` | |||
| ClusterId string `json:"clusterId"` | |||
| Desc string `json:"desc"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param CreateDatasetParameter `json:"param,omitempty"` | |||
| Name string `json:"name" binding:"required"` | |||
| ClusterId string `json:"clusterId"` | |||
| Desc string `json:"desc"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param interface{} `json:"param,omitempty"` | |||
| } | |||
| type CreateDatasetResp struct { | |||
| @@ -22,61 +13,3 @@ type CreateDatasetResp struct { | |||
| Msg string `json:"msg,omitempty" copier:"Msg"` | |||
| ErrorMsg string `json:"errorMsg,omitempty" copier:"ErrorMsg"` | |||
| } | |||
| type OpenIDataset struct { | |||
| Repo string `json:"repo,omitempty"` | |||
| } | |||
| func (o *OpenIDataset) DatasetCreateParam() { | |||
| } | |||
| type OctopusDataset struct { | |||
| } | |||
| func (o *OctopusDataset) DatasetCreateParam() { | |||
| } | |||
| func (cp *CreateDatasetReq) UnmarshalJSON(data []byte) error { | |||
| // 临时结构体:用于捕获原始 JSON 中的 param 字段数据 | |||
| type TempCreateParam struct { | |||
| Name string `json:"name"` | |||
| ClusterId string `json:"clusterId"` | |||
| Desc string `json:"desc"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param json.RawMessage `json:"param,omitempty"` // 捕获原始 JSON 数据 | |||
| } | |||
| var temp TempCreateParam | |||
| if err := json.Unmarshal(data, &temp); err != nil { | |||
| return err | |||
| } | |||
| // 将临时结构体的字段赋值给原结构体(除 Param 外) | |||
| cp.Name = temp.Name | |||
| cp.ClusterId = temp.ClusterId | |||
| cp.Desc = temp.Desc | |||
| cp.Src = temp.Src | |||
| // 解析 param 字段的原始数据为具体类型 | |||
| if temp.Param != nil { | |||
| // 尝试解析为 OpenI 类型 | |||
| var openi OpenIDataset | |||
| if err := json.Unmarshal(temp.Param, &openi); err != nil { | |||
| // 打印详细错误(如字段不匹配、类型错误等) | |||
| fmt.Printf("解析 OpenI 失败: %v\n", err) // 关键调试日志 | |||
| } else { | |||
| cp.Param = &openi | |||
| return nil | |||
| } | |||
| // 新增:尝试解析为 Octopus 类型 | |||
| var octopus OctopusDataset | |||
| if err := json.Unmarshal(temp.Param, &octopus); err == nil { | |||
| cp.Param = &octopus | |||
| return nil | |||
| } | |||
| return fmt.Errorf("unsupported param type in CreateParam") | |||
| } | |||
| return nil | |||
| } | |||
| @@ -1,20 +1,11 @@ | |||
| package ai | |||
| import ( | |||
| "encoding/json" | |||
| "fmt" | |||
| ) | |||
| type CreateModelParameter interface { | |||
| ModelCreateParam() | |||
| } | |||
| type CreateModelReq struct { | |||
| Name string `json:"name" binding:"required"` | |||
| ClusterId string `json:"clusterId"` | |||
| Desc string `json:"desc"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param CreateModelParameter `json:"param,omitempty"` | |||
| Name string `json:"name" binding:"required"` | |||
| ClusterId string `json:"clusterId"` | |||
| Desc string `json:"desc"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param interface{} `json:"param,omitempty"` | |||
| } | |||
| type CreateModelResp struct { | |||
| @@ -22,61 +13,3 @@ type CreateModelResp struct { | |||
| Msg string `json:"msg,omitempty" copier:"Msg"` | |||
| ErrorMsg string `json:"errorMsg,omitempty" copier:"ErrorMsg"` | |||
| } | |||
| type OpenIModel struct { | |||
| RepoName string `json:"repoName,omitempty"` | |||
| } | |||
| func (o *OpenIModel) ModelCreateParam() { | |||
| } | |||
| type OctopusModel struct { | |||
| } | |||
| func (o *OctopusModel) ModelCreateParam() { | |||
| } | |||
| func (cp *CreateModelReq) UnmarshalJSON(data []byte) error { | |||
| // 临时结构体:用于捕获原始 JSON 中的 param 字段数据 | |||
| type TempCreateParam struct { | |||
| Name string `json:"name"` | |||
| ClusterId string `json:"clusterId"` | |||
| Desc string `json:"desc"` | |||
| Src Source `json:"src,omitempty"` | |||
| Param json.RawMessage `json:"param,omitempty"` // 捕获原始 JSON 数据 | |||
| } | |||
| var temp TempCreateParam | |||
| if err := json.Unmarshal(data, &temp); err != nil { | |||
| return err | |||
| } | |||
| // 将临时结构体的字段赋值给原结构体(除 Param 外) | |||
| cp.Name = temp.Name | |||
| cp.ClusterId = temp.ClusterId | |||
| cp.Desc = temp.Desc | |||
| cp.Src = temp.Src | |||
| // 解析 param 字段的原始数据为具体类型 | |||
| if temp.Param != nil { | |||
| // 尝试解析为 OpenI 类型 | |||
| var openi OpenIModel | |||
| if err := json.Unmarshal(temp.Param, &openi); err != nil { | |||
| // 打印详细错误(如字段不匹配、类型错误等) | |||
| fmt.Printf("解析 OpenI 失败: %v\n", err) // 关键调试日志 | |||
| } else { | |||
| cp.Param = &openi | |||
| return nil | |||
| } | |||
| // 新增:尝试解析为 Octopus 类型 | |||
| var octopus OctopusModel | |||
| if err := json.Unmarshal(temp.Param, &octopus); err == nil { | |||
| cp.Param = &octopus | |||
| return nil | |||
| } | |||
| return fmt.Errorf("unsupported param type in CreateParam") | |||
| } | |||
| return nil | |||
| } | |||