MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / Edit

Method Edit

module/ai-api/iml.go:160–211  ·  view source on GitHub ↗
(ctx context.Context, serviceId string, apiId string, input *ai_api_dto.EditAPI)

Source from the content-addressed store, hash-verified

158}
159
160func (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
213func (i *imlAPIModule) Delete(ctx context.Context, serviceId string, apiId string) error {
214 info, err := i.serviceService.Get(ctx, serviceId)

Callers

nothing calls this directly

Calls 5

updateAPIDocMethod · 0.95
GetMethod · 0.65
ModelTypeMethod · 0.65
SaveMethod · 0.65
IntMethod · 0.45

Tested by

no test coverage detected