Skip to content

Commit

Permalink
feat: improve retry
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed Dec 12, 2024
1 parent a4370dd commit cdf8a43
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/v1/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,18 @@ class ChatCompletionsHandler {
try {
return await operation();
} catch (err: any) {
const is_hit_err = retry_error.some((x) => err instanceof x);
if (is_hit_err === false) {
let need_retry = true;
if (retry_error.some((x) => err instanceof x)) {
need_retry = false;
}
if (
err instanceof GoogleGenerativeAIResponseError &&
err.response.promptFeedback.blockReason
) {
// NOTE: 如果 block 了直接退出不需要retry
need_retry = false;
}
if (need_retry === false) {
bail(err);
if (err) err.bail = true;
}
Expand Down

0 comments on commit cdf8a43

Please sign in to comment.