{"id":13455282,"url":"https://github.com/xqdoo00o/chatgpt-web","last_synced_at":"2025-03-24T08:31:54.118Z","repository":{"id":138126526,"uuid":"609579036","full_name":"xqdoo00o/chatgpt-web","owner":"xqdoo00o","description":"Pure Javascript ChatGPT demo based on OpenAI API","archived":false,"fork":false,"pushed_at":"2024-06-18T15:22:22.000Z","size":1180,"stargazers_count":970,"open_issues_count":18,"forks_count":365,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-08-01T08:14:27.696Z","etag":null,"topics":["caddy","chatgpt","html5","javascript","markdown","nginx","openai"],"latest_commit_sha":null,"homepage":"https://xqdoo00o.github.io/chatgpt-web/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xqdoo00o.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-03-04T15:53:35.000Z","updated_at":"2024-08-01T07:17:12.000Z","dependencies_parsed_at":"2023-09-28T11:26:28.514Z","dependency_job_id":"c721c4fe-043e-493f-babb-85e3330d49ef","html_url":"https://github.com/xqdoo00o/chatgpt-web","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xqdoo00o%2Fchatgpt-web","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xqdoo00o%2Fchatgpt-web/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xqdoo00o%2Fchatgpt-web/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xqdoo00o%2Fchatgpt-web/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xqdoo00o","download_url":"https://codeload.github.com/xqdoo00o/chatgpt-web/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221947491,"owners_count":16906133,"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":["caddy","chatgpt","html5","javascript","markdown","nginx","openai"],"created_at":"2024-07-31T08:01:03.358Z","updated_at":"2025-03-24T08:31:54.096Z","avatar_url":"https://github.com/xqdoo00o.png","language":"HTML","funding_links":[],"categories":["HTML","Openai"],"sub_categories":[],"readme":"# chatgpt-web\nPure Javascript ChatGPT demo based on OpenAI API \n\n纯JS实现的ChatGPT项目，基于OpenAI API\n\n部署一个HTML文件即可使用。\n\n支持复制/更新/刷新会话，语音输入，朗读等功能，以及众多[自定义选项](#自定义选项)。\n\n支持搜索会话，深色模式，自定义头像，快捷键，多语言，[环境变量](#环境变量)，[PWA应用](#pwa应用)，API额度显示等。\n\n支持[加密HTML文件](#加密html文件)。\n\n参考项目: \n[markdown-it](https://github.com/markdown-it/markdown-it), \n[highlight.js](https://github.com/highlightjs/highlight.js), \n[github-markdown-css](https://github.com/sindresorhus/github-markdown-css), \n[chatgpt-html](https://github.com/slippersheepig/chatgpt-html), \n[markdown-it-copy](https://github.com/ReAlign/markdown-it-copy), \n[markdown-it-texmath](https://github.com/goessner/markdown-it-texmath), \n[awesome-chatgpt-prompts-zh](https://github.com/PlexPt/awesome-chatgpt-prompts-zh)\n\n![示例](https://raw.githubusercontent.com/xqdoo00o/chatgpt-web/main/example.png)\n\n## Demo\n\n[在线预览](https://xqdoo00o.github.io/chatgpt-web/) （使用需配置OpenAI接口和API密钥）\n\n## 使用方法\n### **注意：部署反代接口请注意OpenAI的[支持地区](https://platform.openai.com/docs/supported-countries)，部署在不支持地区的服务器可能导致封号！最好配置https，公网以http方式明文传输API key非常不安全！**\n___\n- **仅部署HTML**\n\n    使用任意http server部署index.html。打开网页设置，填写API密钥，填写OpenAI接口，当本地\n\n    - 可正常访问`api.openai.com`，填写`https://api.openai.com/`\n\n    - 不可正常访问`api.openai.com`，填写其反代地址（可使用[Cloudflare Worker](https://github.com/xqdoo00o/openai-proxy)等反代），注意：反代接口响应需添加跨域Header `Access-Control-Allow-Origin`\n\n    - OpenAI接口也可以在[环境变量](#环境变量)中单独配置。\n- **同时部署HTML和OpenAI反代接口**\n\n    **注意：服务器需正常访问官方api接口，可统一所有api接口为一个自定义密钥**\n    - 使用nginx，示例配置如下\n\n        ```\n        server {\n            listen      80;\n            server_name example.com;\n            #开启openai接口的gzip压缩，大量重复文本的压缩率高，节省服务端流量\n            gzip on;\n            gzip_min_length 1k;\n            gzip_types text/event-stream;\n\n            #统一所有api接口为一个自定义密钥\n            set $custom_key \"sk-12345678\";\n            set $openai_key \"sk-xxxxxx\";\n            set $deepseek_key \"sk-xxxxxx\";\n            set $gemini_key \"xxx-xxx\";\n            set $claude_key \"sk-ant-xxx\";\n\n            #DeepSeek, 网页端需单独设置DeepSeek接口为deepseek\n            location ^~ /deepseek {\n                if ($http_authorization != \"Bearer ${custom_key}\") {\n                    return 401;\n                }\n                proxy_pass https://api.deepseek.com/;\n                proxy_set_header Host api.deepseek.com;\n                proxy_ssl_name api.deepseek.com;\n                proxy_ssl_server_name on;\n                proxy_set_header Authorization \"Bearer ${deepseek_key}\";\n                proxy_buffering off;\n            }\n\n            #Gemini\n            location ^~ /v1/models {\n                if ($arg_key != $custom_key) {\n                    return 401;\n                }\n                proxy_pass https://generativelanguage.googleapis.com$uri?alt=sse\u0026key=$gemini_key;\n                proxy_buffering off;\n            }\n\n            #Claude\n            location ^~ /v1/messages {\n                if ($http_x_api_key != $custom_key) {\n                    return 401;\n                }\n                proxy_pass https://api.anthropic.com/v1/messages;\n                proxy_set_header Host api.anthropic.com;\n                proxy_ssl_name api.anthropic.com;\n                proxy_ssl_server_name on;\n                proxy_set_header X-Api-Key $claude_key;\n                proxy_buffering off;\n            }\n\n            #Openai\n            location ^~ /v1 {\n                if ($http_authorization != \"Bearer ${custom_key}\") {\n                    return 401;\n                }\n                proxy_pass https://api.openai.com/v1;\n                proxy_set_header Host api.openai.com;\n                proxy_ssl_name api.openai.com;\n                proxy_ssl_server_name on;\n                proxy_set_header Authorization \"Bearer ${openai_key}\";\n                proxy_buffering off;\n            }\n\n            location / {\n                alias /usr/share/nginx/html/;\n                index index.html;\n            }\n        }\n        ```\n        如服务器无法正常访问`api.openai.com`，可配合socat反代和http代理使用，proxy_pass配置改成\n        ```\n        proxy_pass https://127.0.0.1:8443/v1;\n        ```\n        并打开socat\n        ```\n        socat TCP4-LISTEN:8443,reuseaddr,fork PROXY:http代理地址:api.openai.com:443,proxyport=http代理端口\n        ```\n    - 使用Caddy，可以自动生产HTTPS证书，示例配置如下\n\n        ```\n        yourdomain.example.com {\n            reverse_proxy /v1/* https://api.openai.com {\n                header_up Host api.openai.com\n                header_up Authorization \"{http.request.header.Authorization}\"\n                header_up Authorization \"Bearer sk-your-token\"\n            }\n\n            file_server / {\n                root /var/wwwroot/chatgpt-web\n                index index.html\n            }\n        }\n        ```\n        **Caddy 2.6.5及之后版本支持https_proxy和http_proxy环境变量，如服务器无法正常访问`api.openai.com`，可先设置代理环境变量**\n\n## 环境变量\nOpenAI接口和密钥可以单独在环境变量文件中配置。\n\n新建环境变量文件`env.js`到index.html同目录下，示例如下。\n```\nenvAPIEndpoint=\"https://api.openai.com/\"\nenvAPIKey=\"sk-your-token\"\n```\n\n## PWA应用\n部署文件[icon.png](https://raw.githubusercontent.com/xqdoo00o/chatgpt-web/main/icon.png)，[manifest.json](https://raw.githubusercontent.com/xqdoo00o/chatgpt-web/main/manifest.json)，[sw.js](https://raw.githubusercontent.com/xqdoo00o/chatgpt-web/main/sw.js)到index.html同目录下，即可支持PWA应用。\n\n**注意：如果重命名index.html使用，则sw.js文件中`./index.html`也需修改。**\n\n**部署PWA应用后，更新html文件需同步更新sw.js，不然无法更新成功。**\n\n## 自定义选项\n\n- 左边栏支持，搜索会话，新建/重命名/删除(会话/文件夹)，中英双语，浅色/深色/自动主题模式，导出/导入/重置会话和设置数据，快捷键，显示API额度，显示本地存储。\n\n- 可选GPT模型，默认gpt-3.5，当前使用gpt-4模型需通过OpenAI的表单申请，或使用[ChatGPT-to-API](https://github.com/xqdoo00o/ChatGPT-to-API)模拟网页ChatGPT为API使用（使用gpt-4需Plus账户）。\n\n- 可选OpenAI接口地址，使用nginx或caddy部署反代后可以不设置。\n\n- 可选API密钥，默认不设置，**如需网页设置自定义API密钥使用，反代接口最好配置https，公网以http方式明文传输API key极易被中间人截获。**\n\n- 可选用户头像，可修改为任意图片地址。\n\n- 可选系统角色，默认不开启，有四个预设角色，并动态加载[awesome-chatgpt-prompts-zh](https://github.com/PlexPt/awesome-chatgpt-prompts-zh)或[awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts)中的角色。\n\n- 可选角色性格，默认灵活创新，对应接口文档的top_p参数。\n\n- 可选回答质量，默认平衡，对应接口文档的temperature参数。\n\n- 修改打字机速度，默认较快，值越大速度越快。\n\n- 可选连续会话上下文信息限制，默认25条，对话中包含上下文信息，会导致api费用增加。设置为0条则关闭连续会话。\n\n- 允许长回复，默认关闭，**开启后可能导致api费用增加，并丢失全部上下文，对于一些要发送`继续`才完整的回复，不用发`继续`了。**\n\n- 选择语音，默认Bing语音，支持Azure语音和系统语音，可分开设置提问语音和回答语音。\n\n- 音量，默认最大。\n\n- 语速，默认正常。\n\n- 音调，默认正常。\n\n- 允许连续朗读，默认开启，连续郎读到所有对话结束。\n\n- 允许自动朗读，默认关闭，自动朗读新的回答。**iOS需打开设置-自动播放视频预览，Mac上Safari需打开此网站的设置-允许全部自动播放**\n\n- 支持语音输入，默认识别为普通话，可长按语音按钮修改识别语言选项。**语音识别必需条件：使用chrome内核系浏览器 + https网页或本地网页，允许网页的麦克风权限，并已安装麦克风设备。** \n\n- 自动发送关键词，默认为空，识别到关键词后自动发送。\n\n- 自动停止关键词，默认为空，识别到关键词后自动停止识别。\n\n- 自动发送延迟时间，默认为0秒，即不自动发送。不为0秒时，表示识别到内容后，自动发送延迟的时间。\n\n- 保持监听，默认关闭，保持麦克风一直处于监听状态，除非识别报错或手动关闭识别。\n\n## 加密HTML文件\n\n使用[加密网页](https://xqdoo00o.github.io/chatgpt-web/encrypt.html)可加密index.html文件。\n\n- 密码，打开加密HTML的密码。\n\n- 是否压缩，默认允许，较大HTML可减少加密后文件体积。\n\n- 允许记住密码，默认允许，是否允许前端记住密码。\n\n- 记住密码有效期，默认永不过期，过期后需重新输入密码。\n\n- 拷贝index.html内容到要加密的HTML文本框，点击生成按钮后，即可下载加密HTML，并替换index.html使用。\n\n**注意：该方式仅加密前端HTML，不加密OpenAI反代接口。**\n\n**可取消OpenAI反代接口的默认API密钥，打开[index.html代码](https://github.com/xqdoo00o/chatgpt-web/blob/main/index.html#L2840)，此行结尾添加代码`value=\"sk-xxx\"`，则默认使用该密钥**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxqdoo00o%2Fchatgpt-web","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxqdoo00o%2Fchatgpt-web","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxqdoo00o%2Fchatgpt-web/lists"}