MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / DeleteProviderModel

Method DeleteProviderModel

module/ai-model/iml.go:102–150  ·  view source on GitHub ↗
(ctx *gin.Context, provider string, id string)

Source from the content-addressed store, hash-verified

100}
101
102func (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
152func (i *imlProviderModelModule) AddProviderModel(ctx *gin.Context, provider string, input *model_dto.Model) (*model_dto.SimpleModel, error) {
153 p, has := model_runtime.GetProvider(provider)

Callers

nothing calls this directly

Calls 6

syncGatewayMethod · 0.95
GetMethod · 0.65
CountByModelMethod · 0.65
DeleteMethod · 0.65
GetModelConfigMethod · 0.65
RemoveModelMethod · 0.65

Tested by

no test coverage detected