• Stars
    star
    695
  • Rank 65,093 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cloudflare Worker 代理请求 ChatGPT API,支持 Stream 流式输出

cloudflare-proxy

好多调用 ChatGPT 的客户端都是直接使用的 api.openai.com,这个接口很显然是访问不通的,好在有些良心作者还提供了一个自定义 API 域名的入口,在 Cloudflare Worker 上写了一个简单的代理,用起来顺手多了,省得我一直在本机挂全局代理。—— Barret李靖

代理请求到 ChatGPT API,代码部署步骤:

  1. 注册并登录到 Cloudflare 账户
  2. 创建一个新的 Cloudflare Worker
  3. cloudflare-worker.js 复制并粘贴到 Cloudflare Worker 编辑器中
  4. 保存并部署 Cloudflare Worker
  5. 在 Worker 详情页 -> Trigger -> Custom Domains 中为这个 Worker 添加一个自定义域名

为啥需要第五步?因为直接使用 Cloudflare 的域名,依然无法访问。

使用说明

ChatGPT 的 API 默认是非流式输出的,如果想让他变成流式输出,需要将 payload.stream 设置为 true,大部分的客户端都已经加上了这个参数。

const response = await fetch(fetchAPI, payload);
if (body && body.stream !== true) {
const results = await response.json();
return new Response(JSON.stringify(results), {
status: response.status,
headers: {
"Content-Type": "application/json",
},
});
} else {
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: response.headers,
});

License

MIT

More Repositories

1

performance-column

🚅 性能专栏(Performance Column)
1,202
star
2

online-markdown

A online markdown converter specially for Wechat Public formatting.
JavaScript
868
star
3

autoconfig-mac-vimrc

autoconfig mac vimrc with bundle
Vim Script
514
star
4

blogChat

Chat room source code for Barret Lee's Personal Blog.
HTML
498
star
5

kindleBookMaker

Kindle Book Maker with KindleGen, Make Book from RSS/single URL/directory and so on.
JavaScript
393
star
6

algorithms

All algorithms writing with javascript in the book 'Algorithms Fourth Edition'.
JavaScript
331
star
7

snippets

Code Snippets
JavaScript
316
star
8

daily-algorithms

算法,每日练习
JavaScript
227
star
9

blog

Blog & Blog System
HTML
177
star
10

SuperMarker

An automatic marking tool better than mark man.
JavaScript
150
star
11

chatgpt-text-to-midjourney-image

Optimize the prompt using ChatGPT, then send it to Replicate to create an image.
JavaScript
131
star
12

javascript-multiple-download

JavaScript多文件下载
JavaScript
95
star
13

lazyload

Lazyload images or lazy execute scripts. (图片脚本懒加载)
HTML
91
star
14

autocreate-ca

autocreate cetificate authority
Shell
63
star
15

babel-plugin-ast

使用 babel 进行 AST 分析和处理
JavaScript
45
star
16

myPromise

promise
JavaScript
42
star
17

proxyer

一键完成 VPS 裸机的代理程序安装(含证书)
Shell
41
star
18

translation-plan

翻译计划
36
star
19

Node-Daily-Practice

每天写个小程序。
30
star
20

alfred-workflow-paste-image-to-file

Paste image to file from clipboard to desktop
AppleScript
25
star
21

node-debug

Node Debug Demo
HTML
22
star
22

MiniQuery

MiniQuery,寥寥几行代码,实现一个简单的元素选择器,兼容低版本 IE。
JavaScript
19
star
23

h5crash

H5 容器 Crash 问题研究
HTML
17
star
24

performance

Javascript Performace Tester
JavaScript
14
star
25

ddns

将本机的外网 ip 推到 DNSPod
PHP
11
star
26

hexo-search-plugin-snippets

一些辅助 `hexo-generator-search` 插件的代码片段,博客右上角看效果 ---->
JavaScript
11
star
27

duoshuo-migrate-to-disqus

将多说评论迁移到disqus,nodejs程序
JavaScript
10
star
28

dive-into-node-stream

Dive Into Node Stream
JavaScript
9
star
29

debugging-in-vscode-tutorial

Demostration of Debugging in vscode.
HTML
8
star
30

xss-filter-bypass

xss-filter-bypass
JavaScript
8
star
31

Micro-Share

微分享
HTML
4
star
32

node-legacy-debug

Node Legacy Demo
JavaScript
3
star
33

git-rebase

Git Rebase Demo
HTML
2
star
34

weibo

weibo list
2
star
35

pocket

pocket list
2
star
36

parser-learning

编程语言实现模式
JavaScript
1
star
37

Rime-config

Rime Config
Shell
1
star
38

dht

dht
JavaScript
1
star
39

gitbook-plugin-tbobook

JavaScript
1
star
40

slides

小胡子哥的演讲
JavaScript
1
star
41

3d-demo

Collection of 3D Demo
1
star
42

base64-utf8-transfer

base64 for utf8 character
JavaScript
1
star
43

hexo-lazyload-image-enhance

a hexo plugin which is used to have all images support lazyload, with the help of this functionality, it will improve lots of the loading proformance.
JavaScript
1
star
44

ppt

1
star
45

skylarblog

blog for skylar
JavaScript
1
star