Skip to content

Commit 76eac78

Browse files
committed
fix(ai): cover both official SiliconFlow API hosts
1 parent 6797d2c commit 76eac78

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

‎packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,25 +1447,32 @@ describe('LocalModelResolver custom provider compat overrides', () => {
14471447
expect(await systemPromptRoleFor(undefined)).toBe('developer');
14481448
});
14491449

1450-
it('keeps the system role for a thinking model on SiliconFlow China', async () => {
1451-
expect(await systemPromptRoleFor(undefined, 'https://api.siliconflow.cn/v1')).toBe('system');
1450+
it.each([
1451+
'https://api.siliconflow.cn/v1',
1452+
'https://api.siliconflow.com/v1',
1453+
])('keeps the system role for a thinking model at %s', async (baseURL) => {
1454+
expect(await systemPromptRoleFor(undefined, baseURL)).toBe('system');
14521455
});
14531456

14541457
it.each([
14551458
['https://api.openai.com/v1', 'developer'],
14561459
['https://api.deepseek.com/v1', 'system'],
1457-
['https://api.siliconflow.com/v1', 'developer'],
14581460
['https://api.siliconflow.cn.example/v1', 'developer'],
14591461
['https://gateway.example/api.siliconflow.cn/v1', 'developer'],
1462+
['https://api.siliconflow.com.example/v1', 'developer'],
1463+
['https://gateway.example/api.siliconflow.com/v1', 'developer'],
14601464
])('preserves the system prompt role for %s', async (baseURL, role) => {
14611465
expect(await systemPromptRoleFor(undefined, baseURL)).toBe(role);
14621466
});
14631467

1464-
it('honors an explicit developer-role override on SiliconFlow China', async () => {
1468+
it.each([
1469+
'https://api.siliconflow.cn/v1',
1470+
'https://api.siliconflow.com/v1',
1471+
])('honors an explicit developer-role override on %s', async (baseURL) => {
14651472
expect(
14661473
await systemPromptRoleFor(
14671474
{ supportsDeveloperRole: true },
1468-
'https://api.siliconflow.cn/v1',
1475+
baseURL,
14691476
),
14701477
).toBe('developer');
14711478
});

‎third_party/pi-mono/MINIMAX_CHANGES.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ This directory vendors `pi-mono` as source so MiniMax can patch, validate, and s
1313

1414
No upstream source files are changed in the baseline import.
1515

16-
### 2026-09-19 — preserve the system role for SiliconFlow China
16+
### 2026-09-19 — preserve the system role for SiliconFlow
1717

18-
- Reason: thinking-enabled OpenAI-compatible requests to `api.siliconflow.cn` sent the unsupported `developer` role and failed with HTTP 400.
18+
- Reason: thinking-enabled OpenAI-compatible requests sent the `developer` role, which is absent from SiliconFlow's documented message schema.
1919
- Affected package: `packages/ai` (`@earendil-works/pi-ai`), OpenAI Completions compatibility detection.
20-
- Change: default to the `system` role on the exact China API host. Preserve thinking, explicit compatibility overrides, other request options, and other endpoints; the international host is outside this patch.
20+
- Change: default to the `system` role on the exact `api.siliconflow.cn` and `api.siliconflow.com` hosts. Preserve thinking, explicit compatibility overrides, other request options, and other endpoints.
21+
- References: [official Chat Completions schema](https://docs.siliconflow.com/en/api-reference/chat-completions/chat-completions) and [pi's SiliconFlow provider proposal](https://github.com/earendil-works/pi/pull/8113) (closed without merging).
2122
- Upstream PR: not opened.
22-
- Validation: outgoing-payload regressions in `packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts`. Live role comparisons on `Qwen/Qwen3.5-4B` and `deepseek-ai/DeepSeek-R1` returned HTTP 200 for `system` and HTTP 400 for `developer`. The real resolver and streaming adapter with DeepSeek-R1 failed before the fix and completed after it with identical other request options. Full interactive CLI and tool-loop acceptance remain untested.
23+
- Validation: outgoing-payload regressions in `packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts`, including both official hosts, unrelated hosts, and explicit compatibility overrides.
2324

2425
### 2026-08-31 — Windows PowerShell ConstrainedLanguage compatibility
2526

‎third_party/pi-mono/packages/ai/src/providers/openai-completions.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet
10901090
const isTogether =
10911091
provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
10921092
const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
1093-
const isSiliconFlowChina = /^https?:\/\/api\.siliconflow\.cn(?::\d+)?(?:\/|$)/i.test(baseUrl);
1093+
const isSiliconFlow = /^https?:\/\/api\.siliconflow\.(?:cn|com)(?::\d+)?(?:\/|$)/i.test(baseUrl);
10941094
const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai");
10951095
const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com");
10961096
const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");
@@ -1126,7 +1126,7 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet
11261126
return {
11271127
supportsStore: !isNonStandard,
11281128
supportsDeveloperRole:
1129-
!isSiliconFlowChina && (isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter)),
1129+
!isSiliconFlow && (isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter)),
11301130
supportsReasoningEffort:
11311131
!isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,
11321132
supportsUsageInStreaming: true,

0 commit comments

Comments
 (0)