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

Method UpdateProviderConfig

module/ai/iml.go:569–703  ·  view source on GitHub ↗
(ctx context.Context, id string, input *ai_dto.UpdateConfig)

Source from the content-addressed store, hash-verified

567}
568
569func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string, input *ai_dto.UpdateConfig) error {
570 p, has := model_runtime.GetProvider(id)
571 if !has {
572 return fmt.Errorf("ai provider not found")
573 }
574
575 return i.transaction.Transaction(ctx, func(ctx context.Context) error {
576 info, err := i.providerService.Get(ctx, id)
577 if err != nil {
578 if !errors.Is(err, gorm.ErrRecordNotFound) {
579 return err
580 }
581 if input.DefaultLLM == "" {
582 defaultLLM, has := p.DefaultModel(model_runtime.ModelTypeLLM)
583 if !has {
584 return fmt.Errorf("ai provider default llm not found")
585 }
586 input.DefaultLLM = defaultLLM.ID()
587 }
588 info = &ai.Provider{
589 Id: id,
590 Name: p.Name(),
591 DefaultLLM: input.DefaultLLM,
592 Config: input.Config,
593 }
594 err = i.providerService.Create(ctx, &ai.CreateProvider{
595 Id: info.Id,
596 Name: info.Name,
597 DefaultLLM: input.DefaultLLM,
598 Config: input.Config,
599 })
600 if err != nil {
601 return err
602 }
603 }
604 model, has := p.GetModel(input.DefaultLLM)
605 if !has {
606 return fmt.Errorf("ai provider model not found")
607 }
608 err = p.Check(input.Config)
609 if err != nil {
610 return err
611 }
612 input.Config, err = p.GenConfig(input.Config, info.Config)
613 if err != nil {
614 return err
615 }
616 if input.DefaultLLM != "" {
617 if defaultLLM, has := p.GetModel(input.DefaultLLM); has {
618 p.SetDefaultModel(model_runtime.ModelTypeLLM, defaultLLM)
619 }
620 }
621 status := 0
622 if input.Enable != nil && *input.Enable {
623 status = 1
624 }
625 pInfo := &ai.SetProvider{
626 Name: &info.Name,

Callers

nothing calls this directly

Calls 15

syncGatewayMethod · 0.95
newKeyFunction · 0.70
GetMethod · 0.65
DefaultModelMethod · 0.65
IDMethod · 0.65
NameMethod · 0.65
CreateMethod · 0.65
GetModelMethod · 0.65
CheckMethod · 0.65
GenConfigMethod · 0.65
SetDefaultModelMethod · 0.65
DefaultKeyMethod · 0.65

Tested by

no test coverage detected