Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): 未知自定义 Chat Completions 端点默认收敛 system role (#3832) (#3834)

fico-hubc2bb4487c11e
diff --git a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
index 9121f88305..1656d283fe 100644
--- a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
@@ -281,9 +281,72 @@ describe('buildPiNativeProvidersFromConfigs', () => {
id: 'models-url-only',
name: 'Models URL Only',
contextWindow: 64_000,
+ // 无目录元数据的 Chat Completions 模型默认收敛 system role(#3832)。
+ compat: { supportsDeveloperRole: false },
});
});
+ it('defaults unknown custom Chat Completions models to system role (#3832)', () => {
+ const { providers } = buildPiNativeProvidersFromConfigs(
+ [
+ {
+ id: 'volcengine',
+ name: 'Volcengine Ark',
+ auth: { method: 'apiKey' },
+ runtimes: {
+ pi: piRuntime({
+ baseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
+ wireProtocol: 'openai-chat',
+ models: [{ id: 'doubao-seed-2-0', name: 'Doubao Seed 2.0' }],
+ }),
+ },
+ },
+ ],
+ () => 'ark-key',
+ );
+ expect(providers[0]?.models[0]).toMatchObject({
+ id: 'doubao-seed-2-0',
+ compat: { supportsDeveloperRole: false },
+ });
+ });
+
+ it('does not inject the system-role fallback for non-Chat protocols (#3832)', () => {
+ const { providers } = buildPiNativeProvidersFromConfigs(
+ [
+ {
+ id: 'custom-anthropic',
+ name: 'Custom Anthropic Compatible',
+ auth: { method: 'apiKey' },
+ runtimes: {
+ pi: piRuntime({
+ baseUrl: 'https://compat.example/v1',
+ wireProtocol: 'anthropic-messages',
+ models: [{ id: 'compat-model' }],
+ }),
+ },
+ },
+ {
+ id: 'custom-responses',
+ name: 'Custom Responses Compatible',
+ auth: { method: 'apiKey' },
+ runtimes: {
+ pi: piRuntime({
+ baseUrl: 'https://responses.example/v1',
+ wireProtocol: 'openai-responses',
+ models: [{ id: 'responses-model' }],
+ }),
+ },
+ },
+ ],
+ () => 'key',
+ );
+ for (const provider of providers) {
+ for (const model of provider.models) {
+ expect(model).not.toHaveProperty('compat');
+ }
+ }
+ });
+
it('does not apply official per-model routing after the user changes endpoint or protocol', () => {
const { providers } = buildPiNativeProvidersFromConfigs(
[
@@ -378,6 +441,8 @@ describe('buildPiNativeProvidersFromConfigs', () => {
xhigh: null,
max: null,
},
+ // 目录标记清除后无同源元数据,Chat Completions 默认收敛 system role(#3832)。
+ compat: { supportsDeveloperRole: false },
});
});
@@ -1859,9 +1924,16 @@ describe('buildPiNativeProvidersFromConfigs', () => {
],
() => null,
);
+ const chatDefaultCompat = { compat: { supportsDeveloperRole: false } };
expect(providers[0].models).toEqual([
- { id: 'vision', name: 'Vision', contextWindow: undefined, input: ['text', 'image'] },
- { id: 'legacy', name: 'Legacy', contextWindow: undefined },
+ {
+ id: 'vision',
+ name: 'Vision',
+ contextWindow: undefined,
+ input: ['text', 'image'],
+ ...chatDefaultCompat,
+ },
+ { id: 'legacy', name: 'Legacy', contextWindow: undefined, ...chatDefaultCompat },
]);
});
@@ -2059,6 +2131,8 @@ describe('buildPiNativeProvidersFromConfigs', () => {
xhigh: null,
max: 'max',
},
+ // 显式声明能力但无同源元数据,Chat Completions 默认收敛 system role(#3832)。
+ compat: { supportsDeveloperRole: false },
});
});
});
diff --git a/apps/desktop/src/main/maker-host/pi-host.ts b/apps/desktop/src/main/maker-host/pi-host.ts
index f4d5cad04f..21554269ad 100644
--- a/apps/desktop/src/main/maker-host/pi-host.ts
+++ b/apps/desktop/src/main/maker-host/pi-host.ts
@@ -1344,7 +1344,17 @@ export function buildPiNativeProvidersFromConfigs(
: {}),
...(bundledModel?.cost ? { cost: { ...bundledModel.cost } } : {}),
...(bundledModel?.headers ? { headers: { ...bundledModel.headers } } : {}),
- ...(bundledModel?.compat ? { compat: structuredClone(bundledModel.compat) } : {}),
+ ...(bundledModel?.compat
+ ? { compat: structuredClone(bundledModel.compat) }
+ : !bundledModel && modelApi === 'openai-completions'
+ ? // 未知自定义 Chat Completions 端点保守回落(#3832):火山引擎等
+ // OpenAI 兼容网关只接受 system/assistant/user/tool,而 Pi 的
+ // detectCompat 对陌生端点默认 supportsDeveloperRole=true,会把
+ // system 指令按 role=developer 发出 → 整个模型不可用。system
+ // role 在所有 OpenAI 兼容端点均可用,故无同源 bundled 元数据时
+ // 默认收敛为 system;有 bundled 元数据的端点维持 Pi 原生判定。
+ { compat: { supportsDeveloperRole: false } }
+ : {}),
...(bundledModel?.samplingParams
? { samplingParams: structuredClone(bundledModel.samplingParams) }
: {}),