Skip to content

Commit

Permalink
fix: fix retry
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed Dec 7, 2024
1 parent 38067df commit 9f5f295
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ The server currently supports the following endpoints:
> **Note**: `/v1/completions` is not supported because Gemini models do not support completion functionality, and Google's PaLM model (which does) is likely to be deprecated.

## Roadmap

- [x] v1
- [ ] 支持配置多个 api key ,并且可以轮询、分配权限、重试等调度操作
- [ ] 支持配置和切换代理

## Building the Project

```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@fastify/swagger": "^8.15.0",
"@fastify/swagger-ui": "^2.1.0",
"@google/generative-ai": "^0.21.0",
"@types/async-retry": "^1.4.9",
"async-retry": "^1.3.3",
"commander": "^12.1.0",
"dotenv": "^16.4.5",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/v1/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class ChatCompletionsHandler {
const is_hit_err = retry_error.some((x) => err instanceof x);
if (is_hit_err === false) {
bail(err);
if (err) err.bail = true;
}
throw err; // 触发重试
}
Expand Down Expand Up @@ -519,7 +520,12 @@ const chatCompletionsRoute: FastifyPluginAsync = async (app) => {
url: "/v1/chat/completions",
schema: { body: CHAT_COMPLETION_SCHEMA },
handler: async (req, reply) => {
const handler = new ChatCompletionsHandler(app, req.body, req, reply);
const handler = new ChatCompletionsHandler(
app,
req.body as any,
req,
reply
);
await handler.processRequest();
},
});
Expand Down

0 comments on commit 9f5f295

Please sign in to comment.