MCPcopy Index your code
hub / github.com/docker/docker-agent / createProviderFromConfig

Method createProviderFromConfig

pkg/runtime/model_switcher.go:860–893  ·  view source on GitHub ↗

createProviderFromConfig creates a provider from a ModelConfig using the runtime's configuration.

(ctx context.Context, cfg *latest.ModelConfig)

Source from the content-addressed store, hash-verified

858
859// createProviderFromConfig creates a provider from a ModelConfig using the runtime's configuration.
860func (r *LocalRuntime) createProviderFromConfig(ctx context.Context, cfg *latest.ModelConfig) (provider.Provider, error) {
861 opts := []options.Opt{
862 options.WithGateway(r.modelSwitcherCfg.ModelsGateway),
863 options.WithProviders(r.modelSwitcherCfg.Providers),
864 }
865
866 // Use max_tokens from config if specified, otherwise look up from models.dev
867 if cfg.MaxTokens != nil {
868 opts = append(opts, options.WithMaxTokens(*cfg.MaxTokens))
869 } else if r.modelsStore != nil {
870 m, err := r.modelsStore.GetModel(ctx, modelsdev.NewID(cfg.Provider, cfg.Model))
871 if err == nil && m != nil {
872 opts = append(opts, options.WithMaxTokens(m.Limit.Output))
873 }
874 }
875
876 if store, ok := r.modelsStore.(*modelsdev.Store); ok && store != nil {
877 opts = append(opts, options.WithModelsDevStore(store))
878 }
879
880 registry := r.modelSwitcherCfg.ProviderRegistry
881 if registry == nil {
882 registry = r.providerRegistry
883 }
884 if registry == nil {
885 registry = provider.DefaultRegistry()
886 }
887 return registry.NewWithModels(ctx,
888 cfg,
889 r.modelSwitcherCfg.Models,
890 r.modelSwitcherCfg.EnvProvider,
891 opts...,
892 )
893}
894
895// WithModelSwitcherConfig sets the model switcher configuration for the runtime.
896func WithModelSwitcherConfig(cfg *ModelSwitcherConfig) Opt {

Callers 4

setAgentModelInternalMethod · 0.95
resolveModelRefMethod · 0.95
resolveModelRefsMethod · 0.95

Calls 8

WithGatewayFunction · 0.92
WithProvidersFunction · 0.92
WithMaxTokensFunction · 0.92
NewIDFunction · 0.92
WithModelsDevStoreFunction · 0.92
DefaultRegistryFunction · 0.92
GetModelMethod · 0.65
NewWithModelsMethod · 0.45

Tested by

no test coverage detected