From 31a54be65d3848326fb014d46e013d6e1333a19a Mon Sep 17 00:00:00 2001 From: Sterne Lee Date: Sun, 29 Sep 2024 21:00:08 +0800 Subject: [PATCH] fix: siliconflow error response --- src/providers/siliconflow/chatComplete.ts | 17 +++++++++++------ src/providers/siliconflow/embed.ts | 11 +++++++---- src/providers/siliconflow/imageGenerate.ts | 11 +++++++---- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/providers/siliconflow/chatComplete.ts b/src/providers/siliconflow/chatComplete.ts index b2708a9d..e9afaf7b 100644 --- a/src/providers/siliconflow/chatComplete.ts +++ b/src/providers/siliconflow/chatComplete.ts @@ -62,26 +62,31 @@ export const SiliconFlowChatCompleteConfig: ProviderConfig = { }; export const SiliconFlowErrorResponseTransform: ( - response: ErrorResponse, + response: { message: string; code: string }, provider: string ) => ErrorResponse = (response, provider) => { return generateErrorResponse( { - ...response.error, + ...response, + type: null, + param: null, }, provider ); }; export const SiliconFlowChatCompleteResponseTransform: ( - response: ChatCompletionResponse | ErrorResponse, + response: ChatCompletionResponse | string, responseStatus: number ) => ChatCompletionResponse | ErrorResponse = (response, responseStatus) => { - if (responseStatus !== 200 && 'error' in response) { - return SiliconFlowErrorResponseTransform(response, SILICONFLOW); + if (responseStatus !== 200 && typeof response === 'string') { + return SiliconFlowErrorResponseTransform( + { message: response, code: String(responseStatus) }, + SILICONFLOW + ); } - return response; + return response as ChatCompletionResponse; }; /** diff --git a/src/providers/siliconflow/embed.ts b/src/providers/siliconflow/embed.ts index 3cc856f4..48b8bce7 100644 --- a/src/providers/siliconflow/embed.ts +++ b/src/providers/siliconflow/embed.ts @@ -23,12 +23,15 @@ export const SiliconFlowEmbedConfig: ProviderConfig = { interface SiliconFlowEmbedResponse extends EmbedResponse {} export const SiliconFlowEmbedResponseTransform: ( - response: SiliconFlowEmbedResponse | ErrorResponse, + response: SiliconFlowEmbedResponse | string, responseStatus: number ) => EmbedResponse | ErrorResponse = (response, responseStatus) => { - if (responseStatus !== 200 && 'error' in response) { - return SiliconFlowErrorResponseTransform(response, SILICONFLOW); + if (responseStatus !== 200 && typeof response === 'string') { + return SiliconFlowErrorResponseTransform( + { message: response, code: String(responseStatus) }, + SILICONFLOW + ); } - return response; + return response as SiliconFlowEmbedResponse; }; diff --git a/src/providers/siliconflow/imageGenerate.ts b/src/providers/siliconflow/imageGenerate.ts index 64af51b5..463385ff 100644 --- a/src/providers/siliconflow/imageGenerate.ts +++ b/src/providers/siliconflow/imageGenerate.ts @@ -36,12 +36,15 @@ interface SiliconFlowImageGenerateResponse extends ImageGenerateResponse { } export const SiliconFlowImageGenerateResponseTransform: ( - response: SiliconFlowImageGenerateResponse | ErrorResponse, + response: SiliconFlowImageGenerateResponse | string, responseStatus: number ) => ImageGenerateResponse | ErrorResponse = (response, responseStatus) => { - if (responseStatus !== 200 && 'error' in response) { - return SiliconFlowErrorResponseTransform(response, SILICONFLOW); + if (responseStatus !== 200 && typeof response === 'string') { + return SiliconFlowErrorResponseTransform( + { message: response, code: String(responseStatus) }, + SILICONFLOW + ); } - return response; + return response as ImageGenerateResponse; };