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

Method createAIService

controller/service/iml.go:505–653  ·  view source on GitHub ↗
(ctx *gin.Context, teamID string, input *service_dto.CreateService)

Source from the content-addressed store, hash-verified

503}
504
505func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string, input *service_dto.CreateService) (*service_dto.Service, error) {
506 if input.Provider == nil {
507 return nil, fmt.Errorf("provider is required")
508 }
509
510 if input.Id == "" {
511 input.Id = uuid.New().String()
512 }
513 if input.Prefix == "" {
514 if len(input.Id) < 9 {
515 input.Prefix = input.Id
516 } else {
517 input.Prefix = input.Id[:8]
518 }
519 }
520 modelId := ""
521 modelCfg := ""
522 modelType := "online"
523 if input.Model != nil {
524 modelId = *input.Model
525 }
526 if *input.Provider == ai_provider_local.ProviderLocal {
527 modelType = "local"
528 if modelId == "" {
529 list, err := i.aiLocalModel.SimpleList(ctx)
530 if err != nil {
531 return nil, err
532 }
533 if len(list) == 0 {
534 return nil, fmt.Errorf("no local model")
535 }
536 modelId = list[0].Id
537 }
538 modelCfg = ai_provider_local.LocalConfig
539 } else {
540 pv, err := i.providerModule.Provider(ctx, *input.Provider)
541 if err != nil {
542 return nil, err
543 }
544 p, has := model_runtime.GetProvider(*input.Provider)
545 if !has {
546 return nil, fmt.Errorf("provider not found")
547 }
548 if modelId == "" {
549 modelId = pv.DefaultLLM
550 }
551 m, has := p.GetModel(modelId)
552 if !has {
553 return nil, fmt.Errorf("model %s not found", pv.DefaultLLM)
554 }
555 modelId = m.Name()
556 modelCfg = m.DefaultConfig()
557 }
558
559 var info *service_dto.Service
560 err := i.transaction.Transaction(ctx, func(txCtx context.Context) error {
561 var err error
562 info, err = i.module.Create(ctx, teamID, input)

Callers 2

QuickCreateAIServiceMethod · 0.95
CreateMethod · 0.95

Calls 10

SimpleListMethod · 0.65
ProviderMethod · 0.65
GetModelMethod · 0.65
NameMethod · 0.65
DefaultConfigMethod · 0.65
CreateMethod · 0.65
SearchMethod · 0.65
AddSubscriberMethod · 0.65
SaveServiceDocMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected