MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / load_providers

Function load_providers

uncommon_route/providers.py:92–117  ·  view source on GitHub ↗

Load provider config from disk.

(path: Path | None = None)

Source from the content-addressed store, hash-verified

90
91
92def load_providers(path: Path | None = None) -> ProvidersConfig:
93 """Load provider config from disk."""
94 filepath = path or _PROVIDERS_FILE
95 if not filepath.exists():
96 return ProvidersConfig()
97 try:
98 raw = json.loads(filepath.read_text())
99 config = ProvidersConfig()
100 for name, data in raw.get("providers", {}).items():
101 if not isinstance(data, dict) or not data.get("api_key"):
102 continue
103 config.providers[name] = ProviderEntry(
104 name=name,
105 api_key=data["api_key"],
106 base_url=data.get("base_url", KNOWN_BASE_URLS.get(name, "")),
107 models=data.get("models", PROVIDER_MODELS.get(name, [])),
108 plan=data.get("plan", ""),
109 )
110 return config
111 except Exception as exc:
112 print(
113 f"[UncommonRoute] warning: failed to load providers from {filepath}: {exc}. "
114 "BYOK routing disabled until resolved.",
115 file=sys.stderr,
116 )
117 return ProvidersConfig()
118
119
120def save_providers(config: ProvidersConfig, path: Path | None = None) -> None:

Callers 15

test_empty_configMethod · 0.90
test_remove_providerMethod · 0.90
test_persistenceMethod · 0.90
test_keyed_modelsMethod · 0.90
test_get_for_modelMethod · 0.90
_cmd_doctorFunction · 0.90
_cmd_initFunction · 0.90
_providers_payloadFunction · 0.90
create_appFunction · 0.90
_reload_providersFunction · 0.90
serveFunction · 0.90

Calls 3

ProvidersConfigClass · 0.85
ProviderEntryClass · 0.85
getMethod · 0.45

Tested by 6

test_empty_configMethod · 0.72
test_remove_providerMethod · 0.72
test_persistenceMethod · 0.72
test_keyed_modelsMethod · 0.72
test_get_for_modelMethod · 0.72