Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
qiayue
php-openai-gpt-stream-chat-api-webui
Repository navigation
Code
Issues
1
(1)
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
php-openai-gpt-stream-chat-api-webui
/
cloudflare.worker.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
33 lines (27 loc) · 1.48 KB
main
Breadcrumbs
php-openai-gpt-stream-chat-api-webui
/
cloudflare.worker.js
Copy path
Top
File metadata and controls
Code
Blame
33 lines (27 loc) · 1.48 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
感谢@赖嘉伟Gary https://github.com/paicha 提供 Worker 代码
用途:
使用此方式,不需要购买海外服务器,替换 /class/Class.ChatGPT.php 中的 api.openai.com 域名后,直接将本项目开源代码部署到国内服务器即可使用。
使用方法:
1、在 CloudFlare 添加一个域名,注意只能填一级域名,不能填子域名,所以可以新注册一个便宜域名专门做这个事情;
2、添加域名后,在域名注册商处把域名的 dns 设为 CloudFlare 的 dns 地址;
3、等待域名生效,大概需要十几分钟到一个小时不等;
4、添加一个 Worker ,把以下代码复制到进去;
5、点击 Worker 的 Trigger 界面,设置自定义域名,选择第一步添加的域名;
6、等全部生效后,就可以用你的自定义域名替换 /class/Class.ChatGPT.php 中的 api.openai.com 域名。
*/
async
function
handleRequest
(
request
)
{
const
url
=
new
URL
(
request
.
url
)
const
fetchAPI
=
request
.
url
.
replace
(
url
.
host
,
'api.openai.com'
)
// 添加跨域处理
const
corsHeaders
=
{
'Access-Control-Allow-Origin'
:
'*'
,
'Access-Control-Allow-Methods'
:
'OPTIONS'
,
'Access-Control-Allow-Headers'
:
'*'
,
}
;
if
(
request
.
method
===
'OPTIONS'
)
return
new
Response
(
null
,
{
headers
:
corsHeaders
}
)
;
return
fetch
(
fetchAPI
,
{
headers
:
request
.
headers
,
method
:
request
.
method
,
body
:
request
.
body
}
)
}
addEventListener
(
"fetch"
,
(
event
)
=>
{
event
.
respondWith
(
handleRequest
(
event
.
request
)
)
}
)
You can’t perform that action at this time.