feat(providers): add ShengSuanYun gateway
This commit is contained in:
1 parent
d35b755fc2
commit
cc57c35014
10 files changed
+169
-1
No files matched your search
@@ -15,6 +15,7 @@ Match the recipe to the credential or endpoint you already have:
|
|||||||
| What you have | Recipe | Must match |
|
| What you have | Recipe | Must match |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| A gateway key and model IDs that include a model family path, such as `provider/model-name` | [OpenRouter Gateway](#recipe-openrouter-gateway) | API key, provider config key, preset provider, and gateway model ID |
|
| A gateway key and model IDs that include a model family path, such as `provider/model-name` | [OpenRouter Gateway](#recipe-openrouter-gateway) | API key, provider config key, preset provider, and gateway model ID |
|
||||||
|
| A ShengSuanYun (胜算云) API key | [ShengSuanYun](#recipe-shengsuanyun) | API key, `shengsuanyun` provider, and the full model ID |
|
||||||
| An OpenCode Zen or Go key | [OpenCode Zen or Go](#recipe-opencode-zen-or-go) | `OPENCODE_API_KEY`, the Zen/Go provider key, and a model ID from the matching OpenCode endpoint |
|
| An OpenCode Zen or Go key | [OpenCode Zen or Go](#recipe-opencode-zen-or-go) | `OPENCODE_API_KEY`, the Zen/Go provider key, and a model ID from the matching OpenCode endpoint |
|
||||||
| An OpenAI platform API key and OpenAI model ID | [OpenAI Direct](#recipe-openai-direct) | `OPENAI_API_KEY`, `provider: "openai"`, and an OpenAI model available to that account |
|
| An OpenAI platform API key and OpenAI model ID | [OpenAI Direct](#recipe-openai-direct) | `OPENAI_API_KEY`, `provider: "openai"`, and an OpenAI model available to that account |
|
||||||
| An Anthropic API key and Anthropic model ID | [Anthropic Direct](#recipe-anthropic-direct) | `ANTHROPIC_API_KEY`, `provider: "anthropic"`, and a non-gateway model ID |
|
| An Anthropic API key and Anthropic model ID | [Anthropic Direct](#recipe-anthropic-direct) | `ANTHROPIC_API_KEY`, `provider: "anthropic"`, and a non-gateway model ID |
|
||||||
@@ -104,6 +105,35 @@ nanobot agent -m "Hello!"
|
|||||||
|
|
||||||
If this fails with `401` or `unauthorized`, check that `OPENROUTER_API_KEY` is visible in the same terminal or service that starts nanobot. If it fails with `model not found`, choose a model ID that OpenRouter lists for your account.
|
If this fails with `401` or `unauthorized`, check that `OPENROUTER_API_KEY` is visible in the same terminal or service that starts nanobot. If it fails with `model not found`, choose a model ID that OpenRouter lists for your account.
|
||||||
|
|
||||||
|
## Recipe: ShengSuanYun
|
||||||
|
|
||||||
|
In **Settings → Models → New preset**, add **ShengSuanYun**, enter your API key,
|
||||||
|
and select an available model. Its default API endpoint is
|
||||||
|
`https://router.shengsuanyun.com/api/v1`. Model IDs include their upstream provider,
|
||||||
|
for example `deepseek/deepseek-v4-flash`; use the exact ID from the model list.
|
||||||
|
Availability and pricing depend on your ShengSuanYun account.
|
||||||
|
See the [official API documentation](https://lean.shengsuanyun.com/openai-api).
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Manual configuration</summary>
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"providers": {
|
||||||
|
"shengsuanyun": { "apiKey": "${SHENGSUANYUN_API_KEY}" }
|
||||||
|
},
|
||||||
|
"modelPresets": {
|
||||||
|
"primary": {
|
||||||
|
"provider": "shengsuanyun",
|
||||||
|
"model": "deepseek/deepseek-v4-flash"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"agents": { "defaults": { "modelPreset": "primary" } }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## Recipe: OpenCode Zen or Go
|
## Recipe: OpenCode Zen or Go
|
||||||
|
|
||||||
In **Settings → Models → New preset**, choose OpenCode Zen or OpenCode Go to match your account, add its credential, select a model from that endpoint, and save. Select the preset in chat.
|
In **Settings → Models → New preset**, choose OpenCode Zen or OpenCode Go to match your account, add its credential, select a model from that endpoint, and save. Select the preset in chat.
|
||||||
|
|||||||
@@ -324,6 +324,7 @@ class ProvidersConfig(Base):
|
|||||||
openai: ProviderConfig = Field(default_factory=ProviderConfig)
|
openai: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||||
openrouter: ProviderConfig = Field(default_factory=ProviderConfig)
|
openrouter: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||||
orcarouter: ProviderConfig = Field(default_factory=ProviderConfig)
|
orcarouter: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||||
|
shengsuanyun: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||||
assemblyai: ProviderConfig = Field(default_factory=ProviderConfig)
|
assemblyai: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||||
huggingface: ProviderConfig = Field(default_factory=ProviderConfig)
|
huggingface: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||||
skywork: ProviderConfig = Field(default_factory=ProviderConfig)
|
skywork: ProviderConfig = Field(default_factory=ProviderConfig)
|
||||||
|
|||||||
@@ -281,6 +281,19 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
|
|||||||
detect_by_base_keyword="orcarouter",
|
detect_by_base_keyword="orcarouter",
|
||||||
default_api_base="https://api.orcarouter.ai/v1",
|
default_api_base="https://api.orcarouter.ai/v1",
|
||||||
),
|
),
|
||||||
|
# ShengSuanYun model IDs include the upstream provider (e.g. deepseek/model).
|
||||||
|
ProviderSpec(
|
||||||
|
name="shengsuanyun",
|
||||||
|
keywords=("shengsuanyun",),
|
||||||
|
env_key="SHENGSUANYUN_API_KEY",
|
||||||
|
request_apis=("chat_completions", "responses"),
|
||||||
|
display_name="ShengSuanYun",
|
||||||
|
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",),
|
||||||
|
),
|
||||||
# Eden AI: OpenAI-compatible gateway. Models use the "provider/model"
|
# 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.
|
# naming scheme (e.g. "anthropic/claude-sonnet-4-5"); the full id is sent upstream.
|
||||||
ProviderSpec(
|
ProviderSpec(
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
import pytest
|
||||||
|
from openai import AsyncOpenAI
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def _config(model: str = "deepseek/deepseek-v4-flash") -> Config:
|
||||||
|
return Config.model_validate({
|
||||||
|
"providers": {"shengsuanyun": {"apiKey": "test-key"}},
|
||||||
|
"agents": {"defaults": {"provider": "shengsuanyun", "model": model}},
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def test_catalog_uses_gateway_credentials_and_preserves_model_ids() -> None:
|
||||||
|
def get(url: str, **kwargs: object) -> httpx.Response:
|
||||||
|
assert url == "https://router.shengsuanyun.com/api/v1/models"
|
||||||
|
assert kwargs["headers"] == {
|
||||||
|
"Accept": "application/json", "Authorization": "Bearer test-key",
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
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")
|
||||||
|
assert row["configured"] is True
|
||||||
|
assert row["default_api_base"] == "https://router.shengsuanyun.com/api/v1"
|
||||||
|
assert "test-key" not in str(payload)
|
||||||
|
|
||||||
|
|
||||||
|
def test_explicit_gateway_prefix_routes_even_with_another_provider_configured() -> None:
|
||||||
|
config = Config.model_validate({
|
||||||
|
"providers": {
|
||||||
|
"shengsuanyun": {"apiKey": "test-key"},
|
||||||
|
"deepseek": {"apiKey": "other-key"},
|
||||||
|
},
|
||||||
|
"agents": {"defaults": {"model": "shengsuanyun/deepseek/deepseek-v4-flash"}},
|
||||||
|
})
|
||||||
|
assert config.get_provider_name(config.agents.defaults.model) == "shengsuanyun"
|
||||||
|
assert config.get_api_key(config.agents.defaults.model) == "test-key"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("model", [
|
||||||
|
"deepseek/deepseek-v4-flash", "shengsuanyun/deepseek/deepseek-v4-flash",
|
||||||
|
])
|
||||||
|
async def test_chat_and_stream_route_model_and_tools(model: str) -> None:
|
||||||
|
requests = []
|
||||||
|
|
||||||
|
def handler(request: httpx.Request) -> httpx.Response:
|
||||||
|
requests.append(json.loads(request.content))
|
||||||
|
assert str(request.url) == "https://router.shengsuanyun.com/api/v1/chat/completions"
|
||||||
|
assert request.headers["Authorization"] == "Bearer test-key"
|
||||||
|
assert requests[-1]["model"] == "deepseek/deepseek-v4-flash"
|
||||||
|
assert requests[-1]["tools"][0]["function"]["name"] == "weather"
|
||||||
|
if requests[-1].get("stream"):
|
||||||
|
events = [
|
||||||
|
{"id": "1", "object": "chat.completion.chunk", "created": 0,
|
||||||
|
"model": model, "choices": [{"index": 0, "delta": {"content": "Hello"},
|
||||||
|
"finish_reason": None}]},
|
||||||
|
{"id": "1", "object": "chat.completion.chunk", "created": 0,
|
||||||
|
"model": model, "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]},
|
||||||
|
]
|
||||||
|
content = "".join(f"data: {json.dumps(event)}\n\n" for event in events) + "data: [DONE]\n\n"
|
||||||
|
return httpx.Response(200, text=content, headers={"content-type": "text/event-stream"})
|
||||||
|
return httpx.Response(200, json={
|
||||||
|
"id": "1", "object": "chat.completion", "created": 0, "model": model,
|
||||||
|
"choices": [{"index": 0, "finish_reason": "tool_calls", "message": {
|
||||||
|
"role": "assistant", "content": None, "tool_calls": [{
|
||||||
|
"id": "call_1", "type": "function",
|
||||||
|
"function": {"name": "weather", "arguments": '{"city":"Shanghai"}'},
|
||||||
|
}],
|
||||||
|
}}],
|
||||||
|
})
|
||||||
|
|
||||||
|
provider = make_provider(_config(model))
|
||||||
|
assert isinstance(provider, OpenAICompatProvider)
|
||||||
|
async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as http:
|
||||||
|
provider._client = AsyncOpenAI(api_key="test-key", base_url=provider._effective_base,
|
||||||
|
http_client=http, max_retries=0)
|
||||||
|
tools = [{"type": "function", "function": {"name": "weather", "parameters": {"type": "object"}}}]
|
||||||
|
result = await provider.chat([{"role": "user", "content": "Weather?"}], tools=tools)
|
||||||
|
assert result.tool_calls[0].name == "weather"
|
||||||
|
assert result.tool_calls[0].arguments == {"city": "Shanghai"}
|
||||||
|
deltas = []
|
||||||
|
|
||||||
|
async def on_delta(text: str) -> None:
|
||||||
|
deltas.append(text)
|
||||||
|
|
||||||
|
result = await provider.chat_stream([{"role": "user", "content": "Hi"}], tools=tools,
|
||||||
|
on_content_delta=on_delta)
|
||||||
|
assert result.content == "Hello"
|
||||||
|
assert deltas == ["Hello"]
|
||||||
|
assert len(requests) == 2
|
||||||
@@ -27,6 +27,7 @@ const PROVIDER_SEARCH_ALIASES: Record<string, string> = {
|
|||||||
minimax: "海螺 稀宇",
|
minimax: "海螺 稀宇",
|
||||||
minimax_anthropic: "海螺 稀宇",
|
minimax_anthropic: "海螺 稀宇",
|
||||||
siliconflow: "硅基流动 矽基流動 硅基流動",
|
siliconflow: "硅基流动 矽基流動 硅基流動",
|
||||||
|
shengsuanyun: "胜算云 勝算雲",
|
||||||
stepfun: "阶跃星辰 階躍星辰",
|
stepfun: "阶跃星辰 階躍星辰",
|
||||||
xiaomi_mimo: "小米 mimo",
|
xiaomi_mimo: "小米 mimo",
|
||||||
longcat: "美团 美團",
|
longcat: "美团 美團",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ const DEFERRED_MODEL_LIST_PROVIDERS = new Set([
|
|||||||
"orcarouter",
|
"orcarouter",
|
||||||
"ovms",
|
"ovms",
|
||||||
"siliconflow",
|
"siliconflow",
|
||||||
|
"shengsuanyun",
|
||||||
"vllm",
|
"vllm",
|
||||||
"volcengine",
|
"volcengine",
|
||||||
"volcengine_coding_plan",
|
"volcengine_coding_plan",
|
||||||
|
|||||||
@@ -228,6 +228,9 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
|||||||
initials: "SX",
|
initials: "SX",
|
||||||
},
|
},
|
||||||
siliconflow: brand("siliconflow.cn", "#111827", "SF"),
|
siliconflow: brand("siliconflow.cn", "#111827", "SF"),
|
||||||
|
shengsuanyun: { ...brand("shengsuanyun.com", "#5742EE", "SSY", [
|
||||||
|
"https://www.shengsuanyun.com/svg/logo-C_e87Vaj.svg",
|
||||||
|
]), logoLayout: "tile" },
|
||||||
skywork: brand("skywork.ai", "#5B5BF6", "SW"),
|
skywork: brand("skywork.ai", "#5B5BF6", "SW"),
|
||||||
stepfun: brand("stepfun.com", "#2F6BFF", "SF", [
|
stepfun: brand("stepfun.com", "#2F6BFF", "SF", [
|
||||||
"https://www.stepfun.com/step_favicon.svg",
|
"https://www.stepfun.com/step_favicon.svg",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export const PROVIDER_ICONS: Record<string, LucideIcon> = {
|
|||||||
gemini: Gem,
|
gemini: Gem,
|
||||||
mistral: Orbit,
|
mistral: Orbit,
|
||||||
siliconflow: Layers,
|
siliconflow: Layers,
|
||||||
|
shengsuanyun: Cloud,
|
||||||
volcengine: Cloud,
|
volcengine: Cloud,
|
||||||
volcengine_coding_plan: Cloud,
|
volcengine_coding_plan: Cloud,
|
||||||
byteplus: Cloud,
|
byteplus: Cloud,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ describe("settings provider icons", () => {
|
|||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
"aihubmix", "bedrock", "exa", "groq", "lm_studio", "minimax", "minimax_anthropic",
|
"aihubmix", "bedrock", "exa", "groq", "lm_studio", "minimax", "minimax_anthropic",
|
||||||
"modelscope", "moonshot", "olostep", "tavily", "xiaomi_mimo", "zhipu",
|
"modelscope", "moonshot", "olostep", "shengsuanyun", "tavily", "xiaomi_mimo", "zhipu",
|
||||||
])(
|
])(
|
||||||
"does not double-frame %s's primary tile, but preserves unknown fallback assets",
|
"does not double-frame %s's primary tile, but preserves unknown fallback assets",
|
||||||
(provider) => {
|
(provider) => {
|
||||||
|
|||||||
@@ -21,6 +21,18 @@ async function chooseProviderToConfigure(label: string) {
|
|||||||
describe("Settings providers", () => {
|
describe("Settings providers", () => {
|
||||||
installSettingsViewTestHooks();
|
installSettingsViewTestHooks();
|
||||||
|
|
||||||
|
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 }];
|
||||||
|
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();
|
||||||
|
expect(screen.getByPlaceholderText("Enter API key")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it("manages providers unused by presets and returns focus through the manager", async () => {
|
it("manages providers unused by presets and returns focus through the manager", async () => {
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
const payload = settingsPayload();
|
const payload = settingsPayload();
|
||||||
|
|||||||
Reference in new issue
Block a user