| 92 | } |
| 93 | |
| 94 | func (i *imlAPIController) Edit(ctx *gin.Context, serviceId string, apiId string, input *ai_api_dto.EditAPI) (*ai_api_dto.API, error) { |
| 95 | _, err := i.serviceModule.Get(ctx, serviceId) |
| 96 | if err != nil { |
| 97 | return nil, err |
| 98 | } |
| 99 | err = i.transaction.Transaction(ctx, func(txCtx context.Context) error { |
| 100 | apiInfo, err := i.routerModule.Detail(ctx, serviceId, apiId) |
| 101 | if err != nil { |
| 102 | return err |
| 103 | } |
| 104 | proxy := &router_dto.InputProxy{ |
| 105 | Path: apiInfo.Proxy.Path, |
| 106 | Timeout: apiInfo.Proxy.Timeout, |
| 107 | Retry: apiInfo.Proxy.Retry, |
| 108 | Plugins: apiInfo.Proxy.Plugins, |
| 109 | } |
| 110 | //var upstream *string |
| 111 | if input.AiModel != nil { |
| 112 | provider := ai_provider_local.ProviderLocal |
| 113 | if input.AiModel.Type != "local" { |
| 114 | provider = input.AiModel.Provider |
| 115 | } |
| 116 | modelName := input.AiModel.Name |
| 117 | if modelName == "" { |
| 118 | modelName = input.AiModel.Id |
| 119 | } |
| 120 | proxy.Plugins["ai_formatter"] = api.PluginSetting{ |
| 121 | Config: plugin_model.ConfigType{ |
| 122 | "model": modelName, |
| 123 | "provider": provider, |
| 124 | "config": input.AiModel.Config, |
| 125 | }, |
| 126 | } |
| 127 | //upstream = &input.AiModel.Provider |
| 128 | } |
| 129 | |
| 130 | if input.AiPrompt != nil { |
| 131 | proxy.Plugins["ai_prompt"] = api.PluginSetting{ |
| 132 | Config: plugin_model.ConfigType{ |
| 133 | "prompt": input.AiPrompt.Prompt, |
| 134 | "variables": input.AiPrompt.Variables, |
| 135 | }, |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | _, err = i.routerModule.Edit(ctx, serviceId, apiId, &router_dto.Edit{ |
| 140 | Name: input.Name, |
| 141 | Description: input.Description, |
| 142 | Proxy: proxy, |
| 143 | Path: input.Path, |
| 144 | Disable: input.Disable, |
| 145 | Methods: &apiInfo.Methods, |
| 146 | //Upstream: upstream, |
| 147 | }) |
| 148 | if err != nil { |
| 149 | return err |
| 150 | } |
| 151 | |