Просмотр исходного кода

fix(ai): cover both official SiliconFlow API hosts

saladday 2 месяцев назад
Родитель
Сommit
76eac78ce4

+ 12 - 5
packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts

@@ -1447,25 +1447,32 @@ describe('LocalModelResolver custom provider compat overrides', () => {
     expect(await systemPromptRoleFor(undefined)).toBe('developer');
   });
 
-  it('keeps the system role for a thinking model on SiliconFlow China', async () => {
-    expect(await systemPromptRoleFor(undefined, 'https://api.siliconflow.cn/v1')).toBe('system');
+  it.each([
+    'https://api.siliconflow.cn/v1',
+    'https://api.siliconflow.com/v1',
+  ])('keeps the system role for a thinking model at %s', async (baseURL) => {
+    expect(await systemPromptRoleFor(undefined, baseURL)).toBe('system');
   });
 
   it.each([
     ['https://api.openai.com/v1', 'developer'],
     ['https://api.deepseek.com/v1', 'system'],
-    ['https://api.siliconflow.com/v1', 'developer'],
     ['https://api.siliconflow.cn.example/v1', 'developer'],
     ['https://gateway.example/api.siliconflow.cn/v1', 'developer'],
+    ['https://api.siliconflow.com.example/v1', 'developer'],
+    ['https://gateway.example/api.siliconflow.com/v1', 'developer'],
   ])('preserves the system prompt role for %s', async (baseURL, role) => {
     expect(await systemPromptRoleFor(undefined, baseURL)).toBe(role);
   });
 
-  it('honors an explicit developer-role override on SiliconFlow China', async () => {
+  it.each([
+    'https://api.siliconflow.cn/v1',
+    'https://api.siliconflow.com/v1',
+  ])('honors an explicit developer-role override on %s', async (baseURL) => {
     expect(
       await systemPromptRoleFor(
         { supportsDeveloperRole: true },
-        'https://api.siliconflow.cn/v1',
+        baseURL,
       ),
     ).toBe('developer');
   });

+ 5 - 4
third_party/pi-mono/MINIMAX_CHANGES.md

@@ -13,13 +13,14 @@ This directory vendors `pi-mono` as source so MiniMax can patch, validate, and s
 
 No upstream source files are changed in the baseline import.
 
-### 2026-09-19 — preserve the system role for SiliconFlow China
+### 2026-09-19 — preserve the system role for SiliconFlow
 
-- Reason: thinking-enabled OpenAI-compatible requests to `api.siliconflow.cn` sent the unsupported `developer` role and failed with HTTP 400.
+- Reason: thinking-enabled OpenAI-compatible requests sent the `developer` role, which is absent from SiliconFlow's documented message schema.
 - Affected package: `packages/ai` (`@earendil-works/pi-ai`), OpenAI Completions compatibility detection.
-- 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.
+- 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.
+- 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).
 - Upstream PR: not opened.
-- 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.
+- 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.
 
 ### 2026-08-31 — Windows PowerShell ConstrainedLanguage compatibility
 

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

@@ -1090,7 +1090,7 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet
 	const isTogether =
 		provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
 	const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
-	const isSiliconFlowChina = /^https?:\/\/api\.siliconflow\.cn(?::\d+)?(?:\/|$)/i.test(baseUrl);
+	const isSiliconFlow = /^https?:\/\/api\.siliconflow\.(?:cn|com)(?::\d+)?(?:\/|$)/i.test(baseUrl);
 	const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai");
 	const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com");
 	const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");
@@ -1126,7 +1126,7 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet
 	return {
 		supportsStore: !isNonStandard,
 		supportsDeveloperRole:
-			!isSiliconFlowChina && (isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter)),
+			!isSiliconFlow && (isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter)),
 		supportsReasoningEffort:
 			!isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,
 		supportsUsageInStreaming: true,