Python
Add Novita AI provider
freecodewufac0556f8e46
diff --git a/coworker/providers/registry.py b/coworker/providers/registry.pyindex de330b28..92363699 100644--- a/coworker/providers/registry.py+++ b/coworker/providers/registry.py@@ -12,7 +12,8 @@ Chat Completions path), `anthropic` (native Messages API via`AnthropicProvider`), `gemini` (native Google GenAI API via `GeminiProvider`), `bedrock`(models in the user's own AWS account — Claude natively, everything else via Converse),`vertex` (the user's own GCP project — Gemini and Claude natively, open-weight via the-MaaS endpoint), and `ollama` (local, OpenAI-compatible `/v1`).+MaaS endpoint), `novita` (OpenAI-compatible Novita Cloud), and `ollama` (local,+OpenAI-compatible `/v1`)."""from __future__ import annotations@@ -246,10 +247,11 @@ def _build_openrouter_account(profile: dict[str, Any], secrets: Any) -> Providerdef _openai_compat(vendor: str, default_base_url: str, env_key: Optional[str] = None):"""Builder factory for vendors reached through their OpenAI-compatible API (Z AI, DeepSeek,- Kimi, MiniMax, Qwen, xAI, Mistral). The key is resolved from the vendor's OWN profile (or its- env var) — deliberately NOT from the OpenAI env/SecretStore fallback, so a configured OpenAI- key is never silently sent to a different vendor's endpoint. Missing key ⇒ fail fast with a- vendor-named error (these are only built on demand, when one of their models is selected).+ Kimi, MiniMax, Qwen, xAI, Mistral, Novita). The key is resolved from the vendor's OWN+ profile (or its env var) — deliberately NOT from the OpenAI env/SecretStore fallback, so a+ configured OpenAI key is never silently sent to a different vendor's endpoint. Missing key ⇒+ fail fast with a vendor-named error (these are only built on demand, when one of their models+ is selected)."""def build(profile: dict[str, Any], secrets: Any) -> ProviderClient:@@ -302,7 +304,7 @@ def _compat(title: str,*,base_url: str,- recommended_model: str,+ recommended_model: Optional[str] = None,env_key: str,endpoint_help: str = "",) -> ProviderDescriptor:@@ -707,6 +709,13 @@ DESCRIPTORS: list[ProviderDescriptor] = [recommended_model="zai-org/glm-5.2",env_key="ATLASCLOUD_API_KEY",),+ _compat(+ "novita",+ "Novita AI",+ base_url="https://api.novita.ai/openai/v1",+ env_key="NOVITA_API_KEY",+ endpoint_help="Prefilled with Novita's OpenAI-compatible endpoint; keep it unless you use a regional or proxy variant.",+ ),# Resellers: many labs' models behind one key, using THEIR model namespaces (the curated# ids + display labels live in providers/matrix.py). TODO: add Groq here (+ its matrix# rows) once the current provider surface is tested — deliberately deferred to bounddiff --git a/surfaces/gui/src/providers/ProviderSetup.tsx b/surfaces/gui/src/providers/ProviderSetup.tsxindex 2ac1cd9e..43f8cebf 100644--- a/surfaces/gui/src/providers/ProviderSetup.tsx+++ b/surfaces/gui/src/providers/ProviderSetup.tsx@@ -47,6 +47,7 @@ export const KEY_HELP: Record<string, { url: string; label: string; labelKey?: skimi: { url: "https://platform.moonshot.ai/console/api-keys", label: "platform.moonshot.ai" },deepseek: { url: "https://platform.deepseek.com/api_keys", label: "platform.deepseek.com" },mistral: { url: "https://console.mistral.ai/api-keys", label: "console.mistral.ai" },+ novita: { url: "https://novita.ai/", label: "novita.ai" },qwen: { url: "https://modelstudio.console.alibabacloud.com", label: "alibabacloud.com" },minimax: { url: "https://platform.minimax.io", label: "platform.minimax.io" },xai: { url: "https://console.x.ai", label: "console.x.ai" },diff --git a/surfaces/gui/src/providers/logos.ts b/surfaces/gui/src/providers/logos.tsindex 3b977b81..20c33fd0 100644--- a/surfaces/gui/src/providers/logos.ts+++ b/surfaces/gui/src/providers/logos.ts@@ -74,6 +74,7 @@ export const PROVIDER_ORDER = ["ark","ark-agent-plan-cn","meta",+ "novita","ollama","llamacpp","vllm",diff --git a/tests/test_provider_router.py b/tests/test_provider_router.pyindex 4642f948..ccf9bdd8 100644--- a/tests/test_provider_router.py+++ b/tests/test_provider_router.py@@ -74,6 +74,20 @@ def test_build_ollama_client_uses_base_url(monkeypatch):assert captured["api_key"] == "ollama" # placeholder, Ollama ignores it+def test_build_novita_client_uses_base_url(monkeypatch):+ captured: dict = {}++ class FakeOpenAI:+ def __init__(self, **kwargs):+ captured.update(kwargs)++ monkeypatch.setattr("openai.OpenAI", FakeOpenAI)+ client = build_provider_client("novita", {"api_key": "sk-nov"}, secrets=None)+ client._ensure_client() # type: ignore[attr-defined]+ assert captured["base_url"] == "https://api.novita.ai/openai/v1"+ assert captured["api_key"] == "sk-nov"++# -- router routing -------------------------------------------------------------class _Recorder(ProviderClient):def __init__(self, name: str):diff --git a/tests/test_provider_verify.py b/tests/test_provider_verify.pyindex 0b47456c..c16fd857 100644--- a/tests/test_provider_verify.py+++ b/tests/test_provider_verify.py@@ -110,6 +110,14 @@ def test_verify_orcarouter_endpoint(monkeypatch):assert cap["headers"]["Authorization"] == "Bearer sk-orca-x"+def test_verify_novita_uses_openai_compatible_endpoint(monkeypatch):+ cap: dict = {}+ _patch_get(monkeypatch, status=200, capture=cap)+ assert verify_provider_key("novita", api_key="sk-nov") == {"ok": True}+ assert cap["url"] == "https://api.novita.ai/openai/v1/models"+ assert cap["headers"]["Authorization"] == "Bearer sk-nov"++def test_verify_bad_key_is_invalid(monkeypatch):_patch_get(monkeypatch, status=401)assert verify_provider_key("openai", api_key="sk-bad") == {