Răsfoiți Sursa

fix: preserve system prompts for SiliconFlow (#209)

* fix: preserve system prompts for DashScope

* fix: preserve system prompts for SiliconFlow China

* fix(ai): cover official DashScope plan and workspace hosts

* fix(ai): cover both official SiliconFlow API hosts
SaladDay 2 luni în urmă
părinte
comite
0fa4888cba

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

@@ -1448,6 +1448,8 @@ describe('LocalModelResolver custom provider compat overrides', () => {
   });
 
   it.each([
+    'https://api.siliconflow.cn/v1',
+    'https://api.siliconflow.com/v1',
     'https://dashscope.aliyuncs.com/compatible-mode/v1',
     'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
     'https://dashscope-us.aliyuncs.com/compatible-mode/v1',
@@ -1471,6 +1473,11 @@ describe('LocalModelResolver custom provider compat overrides', () => {
 
   it.each([
     ['https://api.openai.com/v1', 'developer'],
+    ['https://api.deepseek.com/v1', 'system'],
+    ['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'],
     ['https://api.moonshot.cn/v1', 'system'],
     ['https://api.moonshot.ai/v1', 'system'],
     ['https://dashscope.aliyuncs.com.example/v1', 'developer'],
@@ -1487,6 +1494,8 @@ describe('LocalModelResolver custom provider compat overrides', () => {
   });
 
   it.each([
+    'https://api.siliconflow.cn/v1',
+    'https://api.siliconflow.com/v1',
     'https://dashscope.aliyuncs.com/compatible-mode/v1',
     'https://coding.dashscope.aliyuncs.com/v1',
     'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',

+ 9 - 0
third_party/pi-mono/MINIMAX_CHANGES.md

@@ -13,6 +13,15 @@ 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
+
+- 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 `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`, including both official hosts, unrelated hosts, and explicit compatibility overrides.
+
 ### 2026-09-19 — preserve the system role for DashScope
 
 - Reason: DashScope endpoints were treated as supporting the `developer` role, causing thinking-enabled OpenAI-compatible conversations to send an unsupported system-prompt role.

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

@@ -1094,6 +1094,7 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet
 	const isDashScope =
 		/^https?:\/\/(?:dashscope(?:-intl|-us)?|(?:coding(?:-intl)?|cn-hongkong)\.dashscope)\.aliyuncs\.com(?::\d+)?(?:\/|$)/i.test(baseUrl) ||
 		/^https?:\/\/[a-z0-9-]+\.(?:cn-beijing|cn-hongkong|ap-southeast-1|ap-northeast-1|eu-central-1|us-east-1)\.maas\.aliyuncs\.com(?::\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");
@@ -1129,7 +1130,7 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet
 	return {
 		supportsStore: !isNonStandard,
 		supportsDeveloperRole:
-			!isKimiCoding && !isDashScope && (isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter)),
+			!isKimiCoding && !isDashScope && !isSiliconFlow && (isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter)),
 		supportsReasoningEffort:
 			!isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,
 		supportsUsageInStreaming: true,