(ctx context.Context, serviceId string, apiId string, input *ai_api_dto.EditAPI)
| 158 | } |
| 159 | |
| 160 | func (i *imlAPIModule) Edit(ctx context.Context, serviceId string, apiId string, input *ai_api_dto.EditAPI) error { |
| 161 | info, err := i.serviceService.Get(ctx, serviceId) |
| 162 | if err != nil { |
| 163 | return err |
| 164 | } |
| 165 | if info.Kind != service.AIService { |
| 166 | return fmt.Errorf("service kind is not ai service") |
| 167 | } |
| 168 | |
| 169 | return i.transaction.Transaction(ctx, func(txCtx context.Context) error { |
| 170 | apiInfo, err := i.aiAPIService.Get(ctx, apiId) |
| 171 | if err != nil { |
| 172 | return err |
| 173 | } |
| 174 | orgPath := apiInfo.Path |
| 175 | if input.Path != nil { |
| 176 | apiInfo.Path = *input.Path |
| 177 | } |
| 178 | if input.Description != nil { |
| 179 | apiInfo.Description = *input.Description |
| 180 | } |
| 181 | err = i.updateAPIDoc(ctx, serviceId, info.Name, orgPath, apiInfo.Path, apiInfo.Name, apiInfo.Description, input.AiPrompt) |
| 182 | if err != nil { |
| 183 | return err |
| 184 | } |
| 185 | var modelId *string |
| 186 | var providerId *string |
| 187 | if input.AiModel != nil { |
| 188 | modelId = &input.AiModel.Id |
| 189 | providerId = &input.AiModel.Provider |
| 190 | } |
| 191 | if input.AiPrompt != nil { |
| 192 | apiInfo.AdditionalConfig["ai_prompt"] = input.AiPrompt |
| 193 | } |
| 194 | if input.AiModel != nil { |
| 195 | apiInfo.AdditionalConfig["ai_model"] = input.AiModel |
| 196 | } |
| 197 | typ := ai_api_dto.ModelType(input.AiModel.Type).Int() |
| 198 | return i.aiAPIService.Save(ctx, apiId, &ai_api.Edit{ |
| 199 | Name: input.Name, |
| 200 | Path: input.Path, |
| 201 | Description: input.Description, |
| 202 | Timeout: input.Timeout, |
| 203 | Retry: input.Retry, |
| 204 | Model: modelId, |
| 205 | Provider: providerId, |
| 206 | Type: &typ, |
| 207 | AdditionalConfig: &apiInfo.AdditionalConfig, |
| 208 | Disable: input.Disable, |
| 209 | }) |
| 210 | }) |
| 211 | } |
| 212 | |
| 213 | func (i *imlAPIModule) Delete(ctx context.Context, serviceId string, apiId string) error { |
| 214 | info, err := i.serviceService.Get(ctx, serviceId) |
nothing calls this directly
no test coverage detected