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

Method AddProviderModel

module/ai-model/iml.go:152–202  ·  view source on GitHub ↗
(ctx *gin.Context, provider string, input *model_dto.Model)

Source from the content-addressed store, hash-verified

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)
154 if !has {
155 return nil, fmt.Errorf("ai provider not found")
156 }
157 // check model name duplicate
158 if has := i.providerModelService.CheckNameDuplicate(ctx, provider, input.Name, ""); has {
159 return nil, fmt.Errorf("model name: `%s` duplicate", input.Name)
160 }
161 // check provider model exist
162 if _, has := p.GetModel(input.Name); has {
163 return nil, fmt.Errorf("provider model already exist")
164 }
165 id := uuid.New().String()
166 err := i.transaction.Transaction(ctx, func(ctx context.Context) error {
167 typeValue := "chat"
168 err := i.providerModelService.Save(ctx, id, &ai_model.Model{
169 Name: &input.Name,
170 Type: &typeValue,
171 Provider: &provider,
172 AccessConfiguration: &input.AccessConfiguration,
173 ModelParameters: &input.ModelParameters,
174 })
175 if err != nil {
176 return err
177 }
178 // update provider model
179 iModel, err := model_runtime.NewCustomizeModel(id, input.Name, p.Logo(), input.AccessConfiguration, input.ModelParameters)
180 if err != nil {
181 return err
182 }
183 // 判断是否需要发布model
184 if p.GetModelConfig().AccessConfigurationStatus {
185 if err := i.syncGateway(ctx, cluster.DefaultClusterID, []*gateway.DynamicRelease{
186 newModel(provider, input.Name, input.AccessConfiguration),
187 }, true); err != nil {
188 return err
189 }
190 }
191
192 p.SetModel(id, iModel)
193 return nil
194 })
195 if err != nil {
196 return nil, err
197 }
198 return &model_dto.SimpleModel{
199 Id: id,
200 Name: input.Name,
201 }, nil
202}
203
204func newModel(provider string, model string, config string) *gateway.DynamicRelease {
205 if config == "" {

Callers

nothing calls this directly

Calls 9

syncGatewayMethod · 0.95
newModelFunction · 0.85
CheckNameDuplicateMethod · 0.65
GetModelMethod · 0.65
SaveMethod · 0.65
LogoMethod · 0.65
GetModelConfigMethod · 0.65
SetModelMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected