{"id":20648878,"url":"https://github.com/lenye/chatgpt_reverse_proxy","last_synced_at":"2025-04-16T21:29:57.971Z","repository":{"id":172614305,"uuid":"649510351","full_name":"lenye/chatgpt_reverse_proxy","owner":"lenye","description":"自建 ChatGPT api 反向代理服务，腾讯云函数","archived":false,"fork":false,"pushed_at":"2025-03-08T15:28:55.000Z","size":219,"stargazers_count":26,"open_issues_count":1,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T05:41:34.625Z","etag":null,"topics":["azure-openai","azure-openai-api-proxy","chatgpt","openai","openai-api-proxy","reverse-proxy","tencent-scf"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lenye.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-05T03:14:38.000Z","updated_at":"2025-03-17T08:16:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"19e2b3a5-bc2d-4055-8014-57452ae2bd71","html_url":"https://github.com/lenye/chatgpt_reverse_proxy","commit_stats":null,"previous_names":["lenye/chatgpt_reverse_proxy"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenye%2Fchatgpt_reverse_proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenye%2Fchatgpt_reverse_proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenye%2Fchatgpt_reverse_proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenye%2Fchatgpt_reverse_proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lenye","download_url":"https://codeload.github.com/lenye/chatgpt_reverse_proxy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249279119,"owners_count":21242850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-openai","azure-openai-api-proxy","chatgpt","openai","openai-api-proxy","reverse-proxy","tencent-scf"],"created_at":"2024-11-16T17:11:30.728Z","updated_at":"2025-04-16T21:29:57.957Z","avatar_url":"https://github.com/lenye.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ChatGPT_reverse_proxy\n\nChatGPT_reverse_proxy 是 ai api 反向代理。可以在自建服务器、云函数上使用。\n\n* 默认支持 OpenAI API 反向代理，请求 api 时，直接把接口地址 ( https://api.openai.com ) 替换为反向代理服务的地址。\n* 支持 Azure OpenAI API 反向代理，将 OXY_TARGET 环境变量修改为 Azure OpenAI\n  服务地址示例：https://docs-test-001.openai.azure.com\n   ```markdown\n   Azure 检索密钥和服务地址\n   https://learn.microsoft.com/zh-cn/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line%2Cpython\u0026pivots=programming-language-go\n   ```\n\n## 可用的环境变量\n\n1. OXY_TARGET: 反向代理目标，默认=https://api.openai.com\n2. OXY_PORT: 代理服务端口，默认=9000\n3. OXY_HOP_HEADER_PREFIX: 跳过 http header 前缀，默认为空\n\n## 自托管chatGPT反向代理服务\n\n### 使用二进制发行版\n\n1. 支持的操作系统\n\n    * Windows\n    * Linux\n    * macOS\n    * FreeBSD\n    * OpenBSD\n\n1. 下载 `chatgpt_reverse_proxy` [最新版本 releases](https://github.com/lenye/chatgpt_reverse_proxy/releases)\n\n1. 开始运行它:\n\n   linux\n\n   如需重新定义环境变量\n    ```shell\n    $ export OXY_PORT=9000\n    ```\n   运行反向代理服务\n    ```shell\n    $ ./chatgpt_reverse_proxy\n    ```\n\n1. OpenAI API 端点地址样例：\n\n    ```\n    http://localhost:9000/v1/completions\n    http://localhost:9000/v1/chat/completions\n    ```\n\n### docker\n\n1. 拉取容器映像\n   ```shell\n   $ docker pull ghcr.io/lenye/chatgpt_reverse_proxy\n   ```\n\n1. docker compose\n\n   docker_compose.yml\n    ```yaml\n    services:\n       chatgpt_reverse_proxy:\n          image: ghcr.io/lenye/chatgpt_reverse_proxy:latest\n          restart: unless-stopped\n          ports:\n             - \"9000:9000\"\n          volumes:\n             - /etc/localtime:/etc/localtime:ro\n             - /etc/timezone:/etc/timezone:ro\n          environment:\n             OXY_PORT: \"9000\"\n             OXY_TARGET: \"https://api.openai.com\"\n             OXY_HOP_HEADER_PREFIX: \"\"\n    ```\n   运行反向代理服务\n    ```shell\n    $ docker compose up -d\n    ```\n\n### 在云函数搭建chatGPT反向代理服务\n\n\u003cdetails\u003e\n\u003csummary\u003e腾讯云函数\u003c/summary\u003e\n\n使用腾讯云函数来搭建 chatGPT 反向代理服务。\n\n#### 预设的环境变量\n\n1. OXY_PORT: 9000 （代理服务端口）\n2. OXY_HOP_HEADER_PREFIX: X-SCF （跳过 http header 前缀）\n\n#### ZIP包下载\n\n* 下载地址: https://github.com/lenye/chatgpt_reverse_proxy/releases\n* 文件名: tencentcloud_scf_chatgpt_reverse_proxy_v0.x.x_linux_amd64.zip\n\n#### A. 新建云函数\n\n1. 进入腾讯云函数控制台: https://console.cloud.tencent.com/scf/list?rid=15\u0026ns=default\n2. “云产品” --\u003e “Serverless” --\u003e “云函数”\n3. “函数服务” --\u003e “新建”\n    - 点击 “从头开始”\n    - 基础配置\n        - 函数类型: Web函数\n        - 名称: 随便填；例如：chatGPT\n        - 地域: 选择境外的美国、加拿大等，推荐“硅谷”\n        - 运行环境: Go 1\n        - 时区: Asia/Shanghai(北京时间)\n    - 函数代码\n        - 提交方法: 本地上传zip包\n    - 高级配置\n        - 启动命令: 自定义模板\n    - 环境配置\n        - 内存: 128MB\n        - 执行超时时间: 180 秒\n    - 点击 “完成”\n\n![基础配置.png](docs/new.png)\n\n![高级配置.png](docs/new2.png)\n\n#### B. 函数管理\n\n1. 进入腾讯云函数控制台: https://console.cloud.tencent.com/scf/list?rid=15\u0026ns=default\n2. “函数服务” --\u003e 在函数列表中选择刚刚新建函数“chatGPT”\n3. “函数管理” --\u003e “函数代码”\n    - 访问路径\n\n      复制链接: https://service-xxx-xxx.xxx.apigw.tencentcs.com/release/\n\n![访问路径.png](docs/new3.png)\n\n#### C. chatGPT 反向代理服务，腾讯云函数的地址\n\n访问路径去除 \"/release/\"，得到 chatGPT 反向代理服务，腾讯云函数的地址:\n\nhttps://service-xxx-xxx.xxx.apigw.tencentcs.com\n\n请求 chatGPT api 时，直接把接口地址 ( https://api.openai.com ) 替换为腾讯云函数的地址。\n\n#### d. OpenAI API 端点地址样例：\n\n```\nhttps://service-xxx-xxx.xxx.apigw.tencentcs.com/v1/completions\nhttps://service-xxx-xxx.xxx.apigw.tencentcs.com/v1/chat/completions\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e阿里云函数计算\u003c/summary\u003e\n\n#### 预设的环境变量\n\n1. OXY_PORT: 9000 （代理服务端口）\n2. OXY_HOP_HEADER_PREFIX: X-FC （跳过 http header 前缀）\n\n#### ZIP包下载\n\n* 下载地址: https://github.com/lenye/chatgpt_reverse_proxy/releases\n* 文件名: aliyun_fc_chatgpt_reverse_proxy_v0.x.x_linux_amd64.zip\n\n#### 创建函数\n\n1. 函数计算控制台选择“服务及函数”\n2. 在左上角，选择地域，推荐选择美国\n3. 创建服务\n4. 创建函数方式：使用自定义运行时创建\n5. 请求处理程序类型：处理 HTTP 请求\n6. 运行环境：debian9\n7. 代码上传方式：通过 ZIP 包上传代码\n8. 启动命令：/code/main\n9. 监听端口: 9000\n\nhttps://help.aliyun.com/zh/fc/getting-started/create-a-function-in-the-function-compute-console\n\n\u003c/details\u003e\n\n## 使用样例\n\n### OpenAI\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/sashabaranov/go-openai\"\n)\n\nfunc main() {\n\tcfg := openai.DefaultConfig(os.Getenv(\"OPENAI_API_KEY\"))\n\n\t// 修改 BaseURL 为反向代理服务的地址，当前示例为腾讯云函数的地址，不要忘记\"/v1\"\n\tcfg.BaseURL = \"https://service-xxx-xxx.xxx.apigw.tencentcs.com/v1\"\n\n\tclient := openai.NewClientWithConfig(cfg)\n\n\tctx := context.Background()\n\t// list models\n\tmodels, err := client.ListModels(ctx)\n\tif err != nil {\n\t\tfmt.Printf(\"ListModels error: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\t// print the first model's id\n\tfmt.Println(models.Models[0].ID)\n}\n\n```\n\n#### 其他样例\n\n\u003cdetails\u003e\n\u003csummary\u003epython\u003c/summary\u003e\n\n```python\nimport os\n\nimport openai\n\nopenai.api_key = os.getenv(\"OPENAI_API_KEY\")\n\n# 修改 api_base 为反向代理服务的地址，当前示例为腾讯云函数的地址，不要忘记\"/v1\"\nopenai.api_base = \"https://service-xxx-xxx.xxx.apigw.tencentcs.com/v1\"\n\n# list models\nmodels = openai.Model.list()\n# print the first model's id\nprint(models.data[0].id)\n```\n\n\u003c/details\u003e\n\n## License\n\n`ChatGPT_reverse_proxy` is released under\nthe [Apache 2.0 license](https://github.com/lenye/chatgpt_reverse_proxy/blob/main/LICENSE). \n\n\n## 免责声明\n\n* 本项目提供的代码和功能，作者不保证所有功能正常运作，不保证代码没有错误或缺陷，不保证代码错误或缺陷被及时更正。\n* 使用者在任何情况下均不得将本项目的作者、贡献者或其他相关方与使用者的使用行为联系起来，或要求其对使用者使用本项目所产生的任何损失或损害负责。\n* 使用者在使用本项目的代码和功能时，必须自行研究相关法律法规，并确保其使用行为合法合规。任何因违反法律法规而导致的法律责任和风险，均由使用者自行承担，本项目的作者、贡献者或其他相关方不承担任何法律及连带责任。\n* 基于本项目进行的任何二次开发、修改或编译的程序与原创作者无关，原创作者不承担与二次开发行为或其结果相关的任何责任，使用者应自行对因二次开发可能带来的各种情况负全部责任。\n\n在使用本项目的代码和功能之前，请您认真考虑并接受以上免责声明。如果您对上述声明有任何疑问或不同意，请不要使用本项目的代码和功能。如果您使用了本项目的代码和功能，则视为您已完全理解并接受上述免责声明，并自愿承担使用本项目的一切风险和后果，作者对您使用本项目所产生的任何损失、责任、或风险概不负责。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flenye%2Fchatgpt_reverse_proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flenye%2Fchatgpt_reverse_proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flenye%2Fchatgpt_reverse_proxy/lists"}