Skip to content

Commit

Permalink
fix: siliconflow error response
Browse files Browse the repository at this point in the history
  • Loading branch information
sternelee committed Sep 29, 2024
1 parent 9d74cf4 commit 31a54be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
17 changes: 11 additions & 6 deletions src/providers/siliconflow/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down
11 changes: 7 additions & 4 deletions src/providers/siliconflow/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
11 changes: 7 additions & 4 deletions src/providers/siliconflow/imageGenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 31a54be

Please sign in to comment.