openai-api-proxy
可以部署到docker和雲函數的OpenAI API代理Simple proxy for OpenAi api via a one-line docker command
? 如果你懶得自己搭建,那麼可以試試國內可以訪問、可以微信充值的第三方OpenAI API服務:API2D.com,支持Chat醬、OpenCat、NextWeb、VSCode插件。
- 騰訊雲函數部署教程騰訊雲函數從4月25日起已經全地域支持SSE,推薦使用
- 簡體中文使用說明
- 《如何快速開發一個OpenAI/GPT應用:國內開發者筆記》
? 已經支持SSE,可以實時返回內容
以下英文由GPT翻譯。 The following English was translated by GPT.
️ This is the server-side of the proxy, not the client-side. It needs to be deployed to a network environment that can access the openai api.
Features
- Supports SSE streaming output
- Built-in text moderation (requires Tencent Cloud KEY configuration)
- ? SSE streaming output supports text moderation, that's how powerful it is.
NodeJS Deployment
You can deploy ./app.js to any environment that supports nodejs 14+, such as cloud functions and edge computing platforms.
- Copy app.js and package.json to the directory
- Install dependencies with yarn install
- Start the service with node app.js
Docker Deployment
docker run -p 9000:9000 easychen/ai.level06.com:latest
The proxy address is http://${IP}:9000
Available Environment Variables
- PORT: Service port
- PROXY_KEY: Proxy access key, used to restrict access
- TIMEOUT: Request timeout, default 30 seconds
- TENCENT_CLOUD_SID: Tencent Cloud secret_id
- TENCENT_CLOUD_SKEY: Tencent Cloud secret_key
- TENCENT_CLOUD_AP: Tencent Cloud region (eg ap-singapore Singapore)
API Usage
- Change the domain/IP (with port number) of the openai request address in the original project (eg https://api.openai.com) to the domain/IP of this proxy.
- If PROXY_KEY is set, add
:<PROXY_KEY>
after the openai key. If not set, no modification is required. - moderation: true enables moderation, false disables moderation
- moderation_level: high interrupts all sentences whose moderation result is not Pass, low only interrupts sentences whose moderation result is Block.
Notes
- Only supports GET and POST methods, not file-related interfaces.
SSE is not currently supported, so stream-related options need to be turned off Now supported.
Client-side Usage Example
Using https://www.npmjs.com/package/chatgpt
as an example:
chatApi = new gpt . ChatGPTAPI ( {
apiKey : 'sk.....:<proxy_key_here>' ,
apiBaseUrl : "http://localhost:9001/v1" , // Replace with proxy domain/IP
} ) ;
Acknowledgements
- SSE reference to chatgpt-api project related code