From 976d246cac711f540ded04b94264238a70264405 Mon Sep 17 00:00:00 2001 From: MyPrototypeWhat Date: Wed, 3 Sep 2025 15:50:47 +0800 Subject: [PATCH] feat: enhance provider configuration and stream text parameters - Added maxRetries option to buildStreamTextParams for improved error handling. - Implemented custom fetch logic for 'cherryin' provider to include signature generation in requests. --- .../aiCore/prepareParams/parameterBuilder.ts | 3 ++- .../src/aiCore/provider/providerConfig.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/aiCore/prepareParams/parameterBuilder.ts b/src/renderer/src/aiCore/prepareParams/parameterBuilder.ts index b54cda5fa5..d72010d03b 100644 --- a/src/renderer/src/aiCore/prepareParams/parameterBuilder.ts +++ b/src/renderer/src/aiCore/prepareParams/parameterBuilder.ts @@ -98,7 +98,8 @@ export async function buildStreamTextParams( headers: options.requestOptions?.headers, providerOptions, tools, - stopWhen: stepCountIs(10) + stopWhen: stepCountIs(10), + maxRetries: 0 } if (assistant.prompt) { params.system = assistant.prompt diff --git a/src/renderer/src/aiCore/provider/providerConfig.ts b/src/renderer/src/aiCore/provider/providerConfig.ts index cdc8621e62..2a0efb21f0 100644 --- a/src/renderer/src/aiCore/provider/providerConfig.ts +++ b/src/renderer/src/aiCore/provider/providerConfig.ts @@ -237,5 +237,23 @@ export async function prepareSpecialProviderConfig( const { token } = await window.api.copilot.getToken(defaultHeaders) config.options.apiKey = token } + if (provider.id === 'cherryin') { + config.options.fetch = async (url, options) => { + // 在这里对最终参数进行签名 + const signature = await window.api.cherryin.generateSignature({ + method: 'POST', + path: '/chat/completions', + query: '', + body: JSON.parse(options.body) + }) + return fetch(url, { + ...options, + headers: { + ...options.headers, + ...signature + } + }) + } + } return config }