| 120 | } |
| 121 | |
| 122 | func (i *imlAPIModule) Create(ctx context.Context, serviceId string, input *ai_api_dto.CreateAPI) error { |
| 123 | info, err := i.serviceService.Get(ctx, serviceId) |
| 124 | if err != nil { |
| 125 | return err |
| 126 | } |
| 127 | if info.Kind != service.AIService { |
| 128 | return fmt.Errorf("service kind is not ai service") |
| 129 | } |
| 130 | if input.Id == "" { |
| 131 | input.Id = uuid.New().String() |
| 132 | } |
| 133 | return i.transaction.Transaction(ctx, func(txCtx context.Context) error { |
| 134 | err = i.updateAPIDoc(ctx, serviceId, info.Name, "", input.Path, input.Name, input.Description, input.AiPrompt) |
| 135 | if err != nil { |
| 136 | return err |
| 137 | } |
| 138 | |
| 139 | return i.aiAPIService.Create(ctx, &ai_api.Create{ |
| 140 | ID: input.Id, |
| 141 | Name: input.Name, |
| 142 | Service: serviceId, |
| 143 | Path: input.Path, |
| 144 | Disable: input.Disable, |
| 145 | Description: input.Description, |
| 146 | Timeout: input.Timeout, |
| 147 | Retry: input.Retry, |
| 148 | Model: input.AiModel.Id, |
| 149 | Provider: input.AiModel.Provider, |
| 150 | Type: ai_api_dto.ModelType(input.AiModel.Type).Int(), |
| 151 | AdditionalConfig: map[string]interface{}{ |
| 152 | "ai_prompt": input.AiPrompt, |
| 153 | "ai_model": input.AiModel, |
| 154 | }, |
| 155 | }) |
| 156 | }) |
| 157 | |
| 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) |