diff --git a/README.md b/README.md index 323562e..f6f3f53 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/package.json b/package.json index a58b635..c5aa53e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5d22b4..955b03a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ dependencies: '@google/generative-ai': specifier: ^0.21.0 version: 0.21.0 + '@types/async-retry': + specifier: ^1.4.9 + version: 1.4.9 async-retry: specifier: ^1.3.3 version: 1.3.3 @@ -1975,6 +1978,12 @@ packages: resolution: {integrity: sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==} dev: false + /@types/async-retry@1.4.9: + resolution: {integrity: sha512-s1ciZQJzRh3708X/m3vPExr5KJlzlZJvXsKpbtE2luqNcbROr64qU+3KpJsYHqWMeaxI839OvXf9PrUSw1Xtyg==} + dependencies: + '@types/retry': 0.12.5 + dev: false + /@types/cacheable-request@6.0.3: resolution: {integrity: sha512-IQ3EbTzGxIigb1I3qPZc1rWJnH0BmSKv5QYTalEwweFvyBDLSAe24zP0le/hyi7ecGfZVlIVAg4BZqb8WBwKqw==} dependencies: @@ -2029,6 +2038,10 @@ packages: '@types/node': 22.10.1 dev: true + /@types/retry@0.12.5: + resolution: {integrity: sha512-3xSjTp3v03X/lSQLkczaN9UIEwJMoMCA1+Nb5HfbJEQWogdeQIyVtTvxPXDQjZ5zws8rFQfVfRdz03ARihPJgw==} + dev: false + /@types/triple-beam@1.3.5: resolution: {integrity: sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==} dev: true diff --git a/src/v1/chat/completions.ts b/src/v1/chat/completions.ts index de32b87..4280ef7 100644 --- a/src/v1/chat/completions.ts +++ b/src/v1/chat/completions.ts @@ -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; // 触发重试 } @@ -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(); }, });