swoole+h5搭建一个流式代理请求chatgpt及千问api接口笔记
大家都知道,国内无法直接访问chatgpt的接口,只能通过代理,而且即使直接能访问,也不能把key等信息放到h5网页中,还是需要搭建一个后端api的代理,key隐藏在后端,将大模型的api流式结果通过http流式转发给h5网页,今天我们来讲讲如何通过swoole实现代理。
首先是h5网页
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" /> <title>BFW NEW PAGE</title> </head> <body> <script type="module"> const response = await fetch(`用swoole搭建的http服务url地址`, { method: 'POST', headers: { 'content-type': 'application/json', } }); ...
点击查看剩余70%
网友评论