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

Method AddProvider

module/ai/iml.go:203–231  ·  view source on GitHub ↗
(ctx context.Context, input *ai_dto.NewProvider)

Source from the content-addressed store, hash-verified

201}
202
203func (i *imlProviderModule) AddProvider(ctx context.Context, input *ai_dto.NewProvider) (*ai_dto.SimpleProvider, error) {
204 _, has := model_runtime.GetProvider(strings.ToLower(input.Name))
205 if has {
206 return nil, fmt.Errorf("provider `%s` duplicate", input.Name)
207 }
208 // uuid = name
209 if has := i.providerService.CheckUuidDuplicate(ctx, input.Name); has {
210 return nil, fmt.Errorf("provider `%s` duplicate", input.Name)
211 }
212 config, defaultLLM := "{\"base_url\": \"\", \"api_key\": \"\"}", ""
213 if err := i.providerService.Create(ctx, &ai.CreateProvider{
214 Id: input.Name,
215 Name: input.Name,
216 DefaultLLM: defaultLLM,
217 Config: config,
218 Type: 1,
219 }); err != nil {
220 return nil, err
221 }
222 // register provider
223 iProvider, _ := model_runtime.NewCustomizeProvider(input.Name, input.Name, []model_runtime.IModel{}, "", "")
224 model_runtime.Register(input.Name, iProvider)
225 return &ai_dto.SimpleProvider{
226 Id: input.Name,
227 Name: input.Name,
228 DefaultConfig: config,
229 Logo: iProvider.Logo(),
230 }, nil
231}
232
233func (i *imlProviderModule) SimpleProvider(ctx context.Context, id string) (*ai_dto.SimpleProvider, error) {
234 p, has := model_runtime.GetProvider(id)

Callers

nothing calls this directly

Calls 4

CheckUuidDuplicateMethod · 0.65
CreateMethod · 0.65
LogoMethod · 0.65
RegisterMethod · 0.45

Tested by

no test coverage detected