fix(providers): preserve existing ShengSuanYun connections
This commit is contained in:
1 parent
41f7f6f337
commit
eb1df4d7b1
10 files changed
+110
-27
No files matched your search
@@ -304,6 +304,7 @@ A Base URL is the service address nanobot sends model requests to. Change it onl
|
||||
> - **Kimi Coding Plan**: Use `providers.kimiCoding` with `provider: "kimi_coding"` for Kimi's dedicated Anthropic Messages API endpoint. The endpoint requires a Claude-compatible `User-Agent`; nanobot sends `claude-code/0.1.0` by default, and you can override it with `extraHeaders.User-Agent` if your account requires a different value.
|
||||
> - **VolcEngine / BytePlus Coding Plan**: Subscription endpoints are configured through dedicated providers `volcengineCodingPlan` or `byteplusCodingPlan`, separate from the pay-per-use `volcengine` / `byteplus` providers.
|
||||
> - **OpenCode Zen / Go**: `providers.opencode` (canonical Zen), the legacy-compatible `providers.opencodeZen`, and `providers.opencodeGo` use the same `OPENCODE_API_KEY`, but route to different OpenCode gateways. These providers use OpenCode's OpenAI-compatible `chat/completions` endpoints; choose model IDs from that endpoint family.
|
||||
> - **ShengSuanYun (胜算云)**: The built-in connection uses `providers.shengsuanyunRouter` and `provider: "shengsuanyun_router"`. Keep the model's namespace, for example `deepseek/deepseek-v4-flash`. Chat Completions is the default; select Responses in a preset's **Advanced options** only for a model that [ShengSuanYun lists as supporting it](https://lean.shengsuanyun.com/openai-api). Existing custom connections named `shengsuanyun` continue to work as configured.
|
||||
> - **Zhipu Coding Plan**: If you're on Zhipu's coding plan, open the zhipu connection in **Settings → Models** and set its base URL to `https://open.bigmodel.cn/api/coding/paas/v4`.
|
||||
> - **Alibaba Cloud BaiLian**: The built-in `dashscope` provider already defaults to `https://dashscope.aliyuncs.com/compatible-mode/v1`; no endpoint override is needed for that service.
|
||||
> - **ModelScope**: The built-in `modelscope` provider already defaults to `https://api-inference.modelscope.cn/v1`; no endpoint override is needed for that service.
|
||||
|
||||
@@ -324,7 +324,7 @@ class ProvidersConfig(Base):
|
||||
openai: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||
openrouter: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||
orcarouter: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||
shengsuanyun: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||
shengsuanyun_router: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||
assemblyai: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||
huggingface: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||
skywork: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||
|
||||
@@ -281,18 +281,18 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
|
||||
detect_by_base_keyword="orcarouter",
|
||||
default_api_base="https://api.orcarouter.ai/v1",
|
||||
),
|
||||
# ShengSuanYun model IDs include the upstream provider (e.g. deepseek/model).
|
||||
# Keep the Router ID separate from existing custom connections named "shengsuanyun".
|
||||
# Upstream model IDs retain their provider namespace (e.g. deepseek/model).
|
||||
ProviderSpec(
|
||||
name="shengsuanyun",
|
||||
keywords=("shengsuanyun",),
|
||||
name="shengsuanyun_router",
|
||||
keywords=("shengsuanyun_router",),
|
||||
env_key="SHENGSUANYUN_API_KEY",
|
||||
request_apis=("chat_completions", "responses"),
|
||||
display_name="ShengSuanYun",
|
||||
display_name="ShengSuanYun Router",
|
||||
backend="openai_compat",
|
||||
is_gateway=True,
|
||||
detect_by_base_keyword="shengsuanyun.com",
|
||||
default_api_base="https://router.shengsuanyun.com/api/v1",
|
||||
strip_model_prefixes=("shengsuanyun",),
|
||||
strip_model_prefixes=("shengsuanyun_router",),
|
||||
),
|
||||
# Eden AI: OpenAI-compatible gateway. Models use the "provider/model"
|
||||
# naming scheme (e.g. "anthropic/claude-sonnet-4-5"); the full id is sent upstream.
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
from openai import AsyncOpenAI
|
||||
|
||||
from nanobot.config.loader import load_config, save_config
|
||||
from nanobot.config.schema import Config
|
||||
from nanobot.providers.factory import make_provider
|
||||
from nanobot.providers.openai_compat_provider import OpenAICompatProvider
|
||||
from nanobot.webui.settings_models import model_settings_payload, provider_models_payload
|
||||
from nanobot.providers.routing import resolve_provider_route
|
||||
from nanobot.webui.settings_models import (
|
||||
create_model_configuration,
|
||||
model_settings_payload,
|
||||
provider_models_payload,
|
||||
update_provider_settings,
|
||||
)
|
||||
|
||||
|
||||
def _config(model: str = "deepseek/deepseek-v4-flash") -> Config:
|
||||
return Config.model_validate({
|
||||
"providers": {"shengsuanyun": {"apiKey": "test-key"}},
|
||||
"agents": {"defaults": {"provider": "shengsuanyun", "model": model}},
|
||||
"providers": {"shengsuanyunRouter": {"apiKey": "test-key"}},
|
||||
"agents": {"defaults": {"provider": "shengsuanyun_router", "model": model}},
|
||||
})
|
||||
|
||||
|
||||
@@ -26,35 +34,66 @@ def test_catalog_uses_gateway_credentials_and_preserves_model_ids() -> None:
|
||||
return httpx.Response(200, json={"data": [{"id": "deepseek/deepseek-v4-flash"}]},
|
||||
request=httpx.Request("GET", url))
|
||||
|
||||
payload = provider_models_payload(_config(), {"provider": ["shengsuanyun"]}, http_get=get)
|
||||
payload = provider_models_payload(_config(), {"provider": ["shengsuanyun_router"]}, http_get=get)
|
||||
assert payload["status"] == "available"
|
||||
assert payload["models"][0]["id"] == "deepseek/deepseek-v4-flash"
|
||||
|
||||
|
||||
def test_settings_exposes_gateway_without_exposing_api_key() -> None:
|
||||
payload = model_settings_payload(_config(), oauth_status=lambda _: {
|
||||
"configured": False, "account": None, "expires_at": None, "login_supported": False,
|
||||
})
|
||||
row = next(row for row in payload["providers"] if row["name"] == "shengsuanyun")
|
||||
payload = model_settings_payload(_config(), oauth_status=_not_signed_in)
|
||||
row = next(row for row in payload["providers"] if row["name"] == "shengsuanyun_router")
|
||||
assert row["configured"] is True
|
||||
assert row["default_api_base"] == "https://router.shengsuanyun.com/api/v1"
|
||||
assert "test-key" not in str(payload)
|
||||
|
||||
|
||||
def _not_signed_in(_: object) -> dict[str, object]:
|
||||
return {"configured": False, "account": None, "expires_at": None, "login_supported": False}
|
||||
|
||||
|
||||
def test_existing_custom_shengsuanyun_connection_keeps_anthropic_route(tmp_path: Path) -> None:
|
||||
path = tmp_path / "config.json"
|
||||
path.write_text(json.dumps({
|
||||
"providers": {"shengsuanyun": {
|
||||
"apiKey": "old-key",
|
||||
"apiBase": "https://router.shengsuanyun.com/api",
|
||||
"api": {"supportedApis": ["anthropic_messages"], "preferredApi": "anthropic_messages"},
|
||||
}},
|
||||
"agents": {"defaults": {"provider": "shengsuanyun", "model": "anthropic/claude-sonnet-4-6"}},
|
||||
}), encoding="utf-8")
|
||||
|
||||
config = load_config(path)
|
||||
route = resolve_provider_route(config, preset=config.resolve_preset())
|
||||
assert route.backend == "anthropic"
|
||||
assert config.get_api_base() == "https://router.shengsuanyun.com/api"
|
||||
row = next(item for item in model_settings_payload(
|
||||
config, oauth_status=_not_signed_in,
|
||||
)["providers"] if item["name"] == "shengsuanyun")
|
||||
assert row["is_custom"] and row["provider_api_configurable"]
|
||||
|
||||
assert update_provider_settings(config, {
|
||||
"provider": ["shengsuanyun"], "api_key": ["rotated-key"], "display_name": [row["label"]],
|
||||
})[0]
|
||||
save_config(config, path)
|
||||
reloaded = load_config(path)
|
||||
assert reloaded.get_api_key() == "rotated-key"
|
||||
assert resolve_provider_route(reloaded, preset=reloaded.resolve_preset()).backend == "anthropic"
|
||||
|
||||
|
||||
def test_explicit_gateway_prefix_routes_even_with_another_provider_configured() -> None:
|
||||
config = Config.model_validate({
|
||||
"providers": {
|
||||
"shengsuanyun": {"apiKey": "test-key"},
|
||||
"shengsuanyunRouter": {"apiKey": "test-key"},
|
||||
"deepseek": {"apiKey": "other-key"},
|
||||
},
|
||||
"agents": {"defaults": {"model": "shengsuanyun/deepseek/deepseek-v4-flash"}},
|
||||
"agents": {"defaults": {"model": "shengsuanyun_router/deepseek/deepseek-v4-flash"}},
|
||||
})
|
||||
assert config.get_provider_name(config.agents.defaults.model) == "shengsuanyun"
|
||||
assert config.get_provider_name(config.agents.defaults.model) == "shengsuanyun_router"
|
||||
assert config.get_api_key(config.agents.defaults.model) == "test-key"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model", [
|
||||
"deepseek/deepseek-v4-flash", "shengsuanyun/deepseek/deepseek-v4-flash",
|
||||
"deepseek/deepseek-v4-flash", "shengsuanyun_router/deepseek/deepseek-v4-flash",
|
||||
])
|
||||
async def test_chat_and_stream_route_model_and_tools(model: str) -> None:
|
||||
requests = []
|
||||
@@ -104,3 +143,46 @@ async def test_chat_and_stream_route_model_and_tools(model: str) -> None:
|
||||
assert result.content == "Hello"
|
||||
assert deltas == ["Hello"]
|
||||
assert len(requests) == 2
|
||||
|
||||
|
||||
async def test_saved_responses_preset_uses_router_with_full_model_id(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
config = Config.model_validate({"providers": {"openai": {"apiKey": "other-key"}}})
|
||||
assert update_provider_settings(config, {
|
||||
"provider": ["shengsuanyun_router"], "api_key": ["test-key"],
|
||||
})[0]
|
||||
name = create_model_configuration(config, {
|
||||
"name": ["Router GPT"],
|
||||
"provider": ["shengsuanyun_router"],
|
||||
"model": ["openai/gpt-5.4"],
|
||||
"api": ['{"supportedApis":["responses"],"preferredApi":"responses"}'],
|
||||
}, oauth_status=_not_signed_in)
|
||||
path = tmp_path / "config.json"
|
||||
save_config(config, path)
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
assert str(request.url) == "https://router.shengsuanyun.com/api/v1/responses"
|
||||
assert request.headers["Authorization"] == "Bearer test-key"
|
||||
body = json.loads(request.content)
|
||||
assert body["model"] == "openai/gpt-5.4"
|
||||
assert body["input"][0]["content"][0]["text"] == "Hi"
|
||||
return httpx.Response(200, json={
|
||||
"id": "resp_1", "object": "response", "status": "completed",
|
||||
"output": [{
|
||||
"id": "msg_1", "type": "message", "role": "assistant", "status": "completed",
|
||||
"content": [{"type": "output_text", "text": "Hello", "annotations": []}],
|
||||
}],
|
||||
})
|
||||
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as http:
|
||||
def create_client(**kwargs):
|
||||
return AsyncOpenAI(**(kwargs | {"http_client": http}))
|
||||
|
||||
monkeypatch.setattr("nanobot.providers.openai_compat_provider.AsyncOpenAI", create_client)
|
||||
provider = make_provider(load_config(path), preset_name=name)
|
||||
try:
|
||||
response = await provider.chat([{"role": "user", "content": "Hi"}])
|
||||
assert response.content == "Hello"
|
||||
finally:
|
||||
await provider.aclose()
|
||||
@@ -27,7 +27,7 @@ const PROVIDER_SEARCH_ALIASES: Record<string, string> = {
|
||||
minimax: "海螺 稀宇",
|
||||
minimax_anthropic: "海螺 稀宇",
|
||||
siliconflow: "硅基流动 矽基流動 硅基流動",
|
||||
shengsuanyun: "胜算云 勝算雲",
|
||||
shengsuanyun_router: "胜算云 勝算雲",
|
||||
stepfun: "阶跃星辰 階躍星辰",
|
||||
xiaomi_mimo: "小米 mimo",
|
||||
longcat: "美团 美團",
|
||||
|
||||
@@ -38,8 +38,8 @@ const DEFERRED_MODEL_LIST_PROVIDERS = new Set([
|
||||
"openrouter",
|
||||
"orcarouter",
|
||||
"ovms",
|
||||
"shengsuanyun_router",
|
||||
"siliconflow",
|
||||
"shengsuanyun",
|
||||
"vllm",
|
||||
"volcengine",
|
||||
"volcengine_coding_plan",
|
||||
|
||||
@@ -228,7 +228,7 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
initials: "SX",
|
||||
},
|
||||
siliconflow: brand("siliconflow.cn", "#111827", "SF"),
|
||||
shengsuanyun: { ...brand("shengsuanyun.com", "#5742EE", "SSY", [
|
||||
shengsuanyun_router: { ...brand("shengsuanyun.com", "#5742EE", "SSY", [
|
||||
"https://www.shengsuanyun.com/svg/logo-C_e87Vaj.svg",
|
||||
]), logoLayout: "tile" },
|
||||
skywork: brand("skywork.ai", "#5B5BF6", "SW"),
|
||||
|
||||
@@ -20,7 +20,7 @@ export const PROVIDER_ICONS: Record<string, LucideIcon> = {
|
||||
gemini: Gem,
|
||||
mistral: Orbit,
|
||||
siliconflow: Layers,
|
||||
shengsuanyun: Cloud,
|
||||
shengsuanyun_router: Cloud,
|
||||
volcengine: Cloud,
|
||||
volcengine_coding_plan: Cloud,
|
||||
byteplus: Cloud,
|
||||
|
||||
@@ -48,7 +48,7 @@ describe("settings provider icons", () => {
|
||||
|
||||
it.each([
|
||||
"aihubmix", "bedrock", "exa", "groq", "lm_studio", "minimax", "minimax_anthropic",
|
||||
"modelscope", "moonshot", "olostep", "shengsuanyun", "tavily", "xiaomi_mimo", "zhipu",
|
||||
"modelscope", "moonshot", "olostep", "shengsuanyun_router", "tavily", "xiaomi_mimo", "zhipu",
|
||||
])(
|
||||
"does not double-frame %s's primary tile, but preserves unknown fallback assets",
|
||||
(provider) => {
|
||||
|
||||
@@ -24,12 +24,12 @@ describe("Settings providers", () => {
|
||||
it("finds ShengSuanYun by its Chinese name and opens its credential form", async () => {
|
||||
const user = userEvent.setup();
|
||||
const payload = settingsPayload();
|
||||
payload.providers = [{ name: "shengsuanyun", label: "ShengSuanYun", configured: false }];
|
||||
payload.providers = [{ name: "shengsuanyun_router", label: "ShengSuanYun Router", configured: false }];
|
||||
renderProviderManager({ initialSection: "models", initialSettings: payload });
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
await user.type(screen.getByRole("combobox", { name: "Search providers" }), "胜算云");
|
||||
await user.click(screen.getByRole("option", { name: "ShengSuanYun" }));
|
||||
expect(screen.getByRole("dialog", { name: "ShengSuanYun" })).toBeVisible();
|
||||
await user.click(screen.getByRole("option", { name: "ShengSuanYun Router" }));
|
||||
expect(screen.getByRole("dialog", { name: "ShengSuanYun Router" })).toBeVisible();
|
||||
expect(screen.getByPlaceholderText("Enter API key")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user