(ctx context.Context, id string)
| 457 | } |
| 458 | |
| 459 | func (i *imlProviderModule) Provider(ctx context.Context, id string) (*ai_dto.Provider, error) { |
| 460 | p, has := model_runtime.GetProvider(id) |
| 461 | if !has { |
| 462 | return nil, fmt.Errorf("ai provider not found") |
| 463 | } |
| 464 | providerModelConfig := p.GetModelConfig() |
| 465 | info, err := i.providerService.Get(ctx, id) |
| 466 | if err != nil { |
| 467 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 468 | return nil, err |
| 469 | } |
| 470 | defaultLLM, has := p.DefaultModel(model_runtime.ModelTypeLLM) |
| 471 | if !has { |
| 472 | defaultLLM, _ = model_runtime.NewCustomizeModel("", "", "", "", "") |
| 473 | } |
| 474 | return &ai_dto.Provider{ |
| 475 | Id: p.ID(), |
| 476 | Name: p.Name(), |
| 477 | Config: p.DefaultConfig(), |
| 478 | GetAPIKeyUrl: p.HelpUrl(), |
| 479 | DefaultLLM: defaultLLM.ID(), |
| 480 | DefaultLLMConfig: defaultLLM.Logo(), |
| 481 | Status: ai_dto.ProviderDisabled, |
| 482 | //Priority: maxPriority, |
| 483 | Type: 0, |
| 484 | ModelConfig: ai_dto.ModelConfig{ |
| 485 | AccessConfigurationStatus: providerModelConfig.AccessConfigurationStatus, |
| 486 | AccessConfigurationDemo: providerModelConfig.AccessConfigurationDemo, |
| 487 | }, |
| 488 | }, nil |
| 489 | } |
| 490 | defaultLLM, has := p.GetModel(info.DefaultLLM) |
| 491 | if !has { |
| 492 | model, has := p.DefaultModel(model_runtime.ModelTypeLLM) |
| 493 | if !has || model == nil { |
| 494 | defaultLLM, _ = model_runtime.NewCustomizeModel("", "", "", "", "") |
| 495 | } else { |
| 496 | defaultLLM = model |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | return &ai_dto.Provider{ |
| 501 | Id: info.Id, |
| 502 | Name: info.Name, |
| 503 | Config: p.MaskConfig(info.Config), |
| 504 | GetAPIKeyUrl: p.HelpUrl(), |
| 505 | DefaultLLM: defaultLLM.ID(), |
| 506 | DefaultLLMConfig: defaultLLM.DefaultConfig(), |
| 507 | //Priority: info.Priority, |
| 508 | Status: ai_dto.ToProviderStatus(info.Status), |
| 509 | Configured: true, |
| 510 | Type: info.Type, |
| 511 | ModelConfig: ai_dto.ModelConfig{ |
| 512 | AccessConfigurationStatus: providerModelConfig.AccessConfigurationStatus, |
| 513 | AccessConfigurationDemo: providerModelConfig.AccessConfigurationDemo, |
| 514 | }, |
| 515 | }, nil |
| 516 | } |
nothing calls this directly
no test coverage detected