(ctx *gin.Context, provider string, id string)
| 100 | } |
| 101 | |
| 102 | func (i *imlProviderModelModule) DeleteProviderModel(ctx *gin.Context, provider string, id string) error { |
| 103 | p, has := model_runtime.GetProvider(provider) |
| 104 | if !has { |
| 105 | return fmt.Errorf("ai provider not found") |
| 106 | } |
| 107 | // check provider exist |
| 108 | _, err := i.providerService.Get(ctx, provider) |
| 109 | if err != nil { |
| 110 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 111 | return fmt.Errorf("provider not found") |
| 112 | } |
| 113 | return err |
| 114 | } |
| 115 | modelInfo, _ := i.providerModelService.Get(ctx, id) |
| 116 | if modelInfo == nil || modelInfo.Provider != provider { |
| 117 | return fmt.Errorf("model not found") |
| 118 | } |
| 119 | return i.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 120 | // check model in use |
| 121 | count, err := i.aiApiService.CountByModel(ctx, id) |
| 122 | if err != nil { |
| 123 | return err |
| 124 | } |
| 125 | if count > 0 { |
| 126 | return fmt.Errorf("model in use") |
| 127 | } |
| 128 | if err := i.providerModelService.Delete(ctx, id); err != nil { |
| 129 | return err |
| 130 | } |
| 131 | if p.GetModelConfig().AccessConfigurationStatus { |
| 132 | err = i.syncGateway(ctx, cluster.DefaultClusterID, []*gateway.DynamicRelease{ |
| 133 | { |
| 134 | BasicItem: &gateway.BasicItem{ |
| 135 | ID: fmt.Sprintf("%s$%s", provider, modelInfo.Name), |
| 136 | Resource: "ai-model", |
| 137 | }, |
| 138 | Attr: nil, |
| 139 | }, |
| 140 | }, false) |
| 141 | if err != nil { |
| 142 | return err |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | p.RemoveModel(id) |
| 147 | return nil |
| 148 | }) |
| 149 | |
| 150 | } |
| 151 | |
| 152 | func (i *imlProviderModelModule) AddProviderModel(ctx *gin.Context, provider string, input *model_dto.Model) (*model_dto.SimpleModel, error) { |
| 153 | p, has := model_runtime.GetProvider(provider) |
nothing calls this directly
no test coverage detected