Skip to content

Commit ee33dfe

Browse files
authored
Merge branch 'main' into feat/ft-batch-improvements
2 parents 0d1738b + 5d2ac80 commit ee33dfe

File tree

3 files changed

+38
-54
lines changed

3 files changed

+38
-54
lines changed

src/handlers/handlerUtils.ts

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,18 @@ export async function tryTargetsRecursively(
667667
`${currentJsonPath}.targets[${originalIndex}]`,
668668
currentInheritedConfig
669669
);
670-
if (response?.headers.get('x-portkey-gateway-exception') === 'true') {
671-
break;
672-
}
670+
const codes = currentTarget.strategy?.onStatusCodes;
671+
const gatewayException =
672+
response?.headers.get('x-portkey-gateway-exception') === 'true';
673673
if (
674-
response?.ok &&
675-
!currentTarget.strategy?.onStatusCodes?.includes(response?.status)
674+
// If onStatusCodes is provided, and the response status is not in the list
675+
(Array.isArray(codes) && !codes.includes(response?.status)) ||
676+
// If onStatusCodes is not provided, and the response is ok
677+
(!codes && response?.ok) ||
678+
// If the response is a gateway exception
679+
gatewayException
676680
) {
681+
// Skip the fallback
677682
break;
678683
}
679684
}
@@ -790,53 +795,35 @@ export async function tryTargetsRecursively(
790795
// tryPost always returns a Response.
791796
// TypeError will check for all unhandled exceptions.
792797
// GatewayError will check for all handled exceptions which cannot allow the request to proceed.
793-
if (
794-
error instanceof TypeError ||
795-
error instanceof GatewayError ||
796-
!error.response ||
797-
(error.response && !(error.response instanceof Response))
798-
) {
799-
console.error(
800-
'tryTargetsRecursively error: ',
801-
error.message,
802-
error.cause,
803-
error.stack
804-
);
805-
const errorMessage =
806-
error instanceof GatewayError
807-
? error.message
808-
: 'Something went wrong';
809-
response = new Response(
810-
JSON.stringify({
811-
status: 'failure',
812-
message: errorMessage,
813-
}),
814-
{
815-
status: 500,
816-
headers: {
817-
'content-type': 'application/json',
818-
// Add this header so that the fallback loop can be interrupted if its an exception.
819-
'x-portkey-gateway-exception': 'true',
820-
},
821-
}
822-
);
823-
} else {
824-
response = error.response;
825-
if (isHandlingCircuitBreaker) {
826-
await c.get('recordCircuitBreakerFailure')?.(
827-
env(c),
828-
currentInheritedConfig.id,
829-
currentTarget.cbConfig,
830-
currentJsonPath,
831-
response.status
832-
);
798+
console.error(
799+
'tryTargetsRecursively error: ',
800+
error.message,
801+
error.cause,
802+
error.stack
803+
);
804+
const errorMessage =
805+
error instanceof GatewayError
806+
? error.message
807+
: 'Something went wrong';
808+
response = new Response(
809+
JSON.stringify({
810+
status: 'failure',
811+
message: errorMessage,
812+
}),
813+
{
814+
status: 500,
815+
headers: {
816+
'content-type': 'application/json',
817+
// Add this header so that the fallback loop can be interrupted if its an exception.
818+
'x-portkey-gateway-exception': 'true',
819+
},
833820
}
834-
}
821+
);
835822
}
836823
break;
837824
}
838825

839-
return response;
826+
return response!;
840827
}
841828

842829
export function constructConfigFromRequestHeaders(

src/handlers/services/responseService.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ export class ResponseService {
6262

6363
this.updateHeaders(finalMappedResponse, cache.cacheStatus, retryAttempt);
6464

65-
if (!finalMappedResponse.ok) {
66-
const errorObj: any = new Error(await finalMappedResponse.clone().text());
67-
errorObj.status = finalMappedResponse.status;
68-
errorObj.response = finalMappedResponse;
69-
throw errorObj;
70-
}
71-
7265
return {
7366
response: finalMappedResponse,
7467
responseJson,

src/providers/deepseek/chatComplete.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export const DeepSeekChatCompleteConfig: ProviderConfig = {
2727
});
2828
},
2929
},
30+
response_format: {
31+
param: 'response_format',
32+
default: null,
33+
},
3034
max_tokens: {
3135
param: 'max_tokens',
3236
default: 100,

0 commit comments

Comments
 (0)