{"id":25859564,"url":"https://github.com/zhengjie9510/openai-proxy","last_synced_at":"2025-03-01T21:01:37.256Z","repository":{"id":167787781,"uuid":"622407986","full_name":"zhengjie9510/openai-proxy","owner":"zhengjie9510","description":"通过代理访问openai api服务。","archived":false,"fork":false,"pushed_at":"2023-11-21T07:19:02.000Z","size":3,"stargazers_count":31,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-11-21T08:29:07.811Z","etag":null,"topics":["chatgpt","docker","nginx","openai","proxy"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhengjie9510.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-02T02:36:31.000Z","updated_at":"2023-11-20T05:13:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"925eabd0-1382-4d3e-99b5-624a23ae6e36","html_url":"https://github.com/zhengjie9510/openai-proxy","commit_stats":null,"previous_names":["zhengjie9510/openai-proxy"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengjie9510%2Fopenai-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengjie9510%2Fopenai-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengjie9510%2Fopenai-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengjie9510%2Fopenai-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhengjie9510","download_url":"https://codeload.github.com/zhengjie9510/openai-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241424420,"owners_count":19960749,"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":["chatgpt","docker","nginx","openai","proxy"],"created_at":"2025-03-01T21:01:36.290Z","updated_at":"2025-03-01T21:01:37.245Z","avatar_url":"https://github.com/zhengjie9510.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"## 1、准备工作\n\n在开始之前，我们需要准备一些东西：\n* Docker：这是一个用于容器化应用程序的开源平台。  \n\n## 2、准备Nginx配置文件\n完整的配置文件见**nginx.conf**，其核心部分如下：\n```conf\nserver {\n    listen 80;  # 监听80端口，用于HTTP请求\n    location / {\n        proxy_pass  https://api.openai.com/;  # 反向代理到https://api.openai.com/这个地址\n        proxy_ssl_server_name on;  # 开启代理SSL服务器名称验证，确保SSL连接的安全性\n        proxy_set_header Host api.openai.com;  # 设置代理请求头中的Host字段为api.openai.com\n        chunked_transfer_encoding off;  # 禁用分块编码传输，避免可能的代理问题\n        proxy_buffering off;  # 禁用代理缓存，避免数据传输延迟\n        proxy_cache off;  # 禁用代理缓存，确保实时获取最新的数据\n        #proxy_set_header X-Forwarded-For $remote_addr;  # 将客户端真实IP添加到代理请求头中的X-Forwarded-For字段中，用于记录客户端真实IP\n    }\n}\n```\n\n## 3、启动服务\n\n### 3.1、docker run\n```\ndocker run -itd -p 80:80 -v $PWD/nginx.conf:/etc/nginx/nginx.conf --name my-nginx nginx\n```\n\n### 3.2、docker compose up\n```\ndocker compose up -d\n```\n\n## 4、应用\n```python\n# Note: you need to be using OpenAI Python v0.27.0 for the code below to work\nimport openai\nopenai.api_key = api_key\nopenai.api_base = \"your_proxy_url\" # 代理地址,如“http://www.test.com/v1”\nopenai.ChatCompletion.create(\n  model=\"gpt-3.5-turbo\",\n  messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Who won the world series in 2020?\"},\n        {\"role\": \"assistant\", \"content\": \"The Los Angeles Dodgers won the World Series in 2020.\"},\n        {\"role\": \"user\", \"content\": \"Where was it played?\"}\n    ]\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhengjie9510%2Fopenai-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhengjie9510%2Fopenai-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhengjie9510%2Fopenai-proxy/lists"}