MCPcopy
hub / github.com/HKUDS/OpenHarness / detect_provider

Function detect_provider

src/openharness/api/provider.py:42–94  ·  view source on GitHub ↗

Infer the active provider and rough capability set using the registry.

(settings: Settings)

Source from the content-addressed store, hash-verified

40
41
42def detect_provider(settings: Settings) -> ProviderInfo:
43 """Infer the active provider and rough capability set using the registry."""
44 if settings.provider == "openai_codex":
45 return ProviderInfo(
46 name="openai-codex",
47 auth_kind="external_oauth",
48 voice_supported=False,
49 voice_reason=_VOICE_REASON["openai_codex"],
50 )
51 if settings.provider == "anthropic_claude":
52 return ProviderInfo(
53 name="claude-subscription",
54 auth_kind="external_oauth",
55 voice_supported=False,
56 voice_reason=_VOICE_REASON["anthropic_claude"],
57 )
58 if settings.api_format == "copilot":
59 return ProviderInfo(
60 name="github_copilot",
61 auth_kind="oauth_device",
62 voice_supported=False,
63 voice_reason=_VOICE_REASON["copilot"],
64 )
65
66 spec = detect_provider_from_registry(
67 model=settings.model,
68 api_key=settings.api_key or None,
69 base_url=settings.base_url,
70 )
71
72 if spec is not None:
73 backend = spec.backend_type
74 return ProviderInfo(
75 name=spec.name,
76 auth_kind=_AUTH_KIND.get(backend, "api_key"),
77 voice_supported=False,
78 voice_reason=_VOICE_REASON.get(backend, "voice mode is not supported for this provider"),
79 )
80
81 # Fallback: use api_format to pick a sensible default
82 if settings.api_format == "openai":
83 return ProviderInfo(
84 name="openai-compatible",
85 auth_kind="api_key",
86 voice_supported=False,
87 voice_reason=_VOICE_REASON["openai_compat"],
88 )
89 return ProviderInfo(
90 name="anthropic",
91 auth_kind="api_key",
92 voice_supported=False,
93 voice_reason=_VOICE_REASON["anthropic"],
94 )
95
96
97def auth_status(settings: Settings) -> str:

Callers 6

_build_dry_run_previewFunction · 0.90
_login_handlerFunction · 0.90
_provider_handlerFunction · 0.90
_voice_handlerFunction · 0.90
build_runtimeFunction · 0.90
sync_app_stateFunction · 0.90

Calls 3

ProviderInfoClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected