| 301 | } |
| 302 | |
| 303 | func (i *imlAPIModule) Get(ctx context.Context, serviceId string, apiId string) (*ai_api_dto.API, error) { |
| 304 | info, err := i.serviceService.Get(ctx, serviceId) |
| 305 | if err != nil { |
| 306 | return nil, err |
| 307 | } |
| 308 | if info.Kind != service.AIService { |
| 309 | return nil, fmt.Errorf("service kind is not ai service") |
| 310 | } |
| 311 | apiInfo, err := i.aiAPIService.Get(ctx, apiId) |
| 312 | if err != nil { |
| 313 | return nil, err |
| 314 | } |
| 315 | prompt, err := ConvertStruct[ai_api_dto.AiPrompt](apiInfo.AdditionalConfig["ai_prompt"]) |
| 316 | if err != nil { |
| 317 | return nil, err |
| 318 | } |
| 319 | aiModel, err := ConvertStruct[ai_api_dto.AiModel](apiInfo.AdditionalConfig["ai_model"]) |
| 320 | if err != nil { |
| 321 | return nil, err |
| 322 | } |
| 323 | if aiModel.Name == "" { |
| 324 | // get provider model |
| 325 | modelInfo, _ := i.aiModelService.Get(ctx, aiModel.Id) |
| 326 | if modelInfo != nil { |
| 327 | aiModel.Name = modelInfo.Name |
| 328 | } else { |
| 329 | aiModel.Name = aiModel.Id |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | return &ai_api_dto.API{ |
| 334 | Id: apiInfo.ID, |
| 335 | Name: apiInfo.Name, |
| 336 | Path: apiInfo.Path, |
| 337 | Description: apiInfo.Description, |
| 338 | Disable: apiInfo.Disable, |
| 339 | AiPrompt: prompt, |
| 340 | AiModel: aiModel, |
| 341 | Timeout: apiInfo.Timeout, |
| 342 | Retry: apiInfo.Retry, |
| 343 | }, nil |
| 344 | } |
| 345 | |
| 346 | func ConvertStruct[T any](data interface{}) (*T, error) { |
| 347 | b, err := json.Marshal(data) |