无服务器部署ChatGPT聊天界面
使用Cloudflare部署Ai聊天前端界面,无需置备服务器,只要一个可以接入cloudflare的域名即可。
代码摘自开源项目
功能介绍
支持基于gpt-3.5-turbo模型的对话 支持批量查询api到期时间和剩余额度
安装步骤
将代码部署到Cloudflare的worker平台(其他支持worker的平台也可)
代码语言:javascript代码运行次数:0运行复制/**
* @auther Rehiy
* @url
*/
const GITHUB_URL = '';
async function github_proxy(request) {
const url = new URL(request.url);
let backend = GITHUB_URL + url.pathname;
if (url.pathname.endsWith('/')) {
backend += 'index.html';
}
const res = await fetch(backend, {
method: request.method,
headers: {
'User-Agent': request.headers.get('User-Agent'),
},
});
const headers = new Headers();
headers.set('Content-Type', file_type(backend));
headers.set('Cache-Control', 'public, max-age=86400');
return new Response(res.body, {
status: res.status,
headers,
});
}
function file_type(url) {
const ext = url.split('?').shift().split('.').pop();
const mines = {
'json': 'application/json',
'js': 'application/javascript',
'css': 'text/css',
'xml': 'text/xml',
'html': 'text/html',
'webm': 'video/webm',
'mp3': 'audio/mpeg',
'mp4': 'video/mp4',
'webp': 'image/webp',
'gif': 'image/gif',
'png': 'image/png',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'svg': 'image/svg+xml',
'ico': 'image/x-icon',
};
return mines[ext] || 'text/plain';
}
// esmodule
export default {
async fetch(request, env) {
return github_proxy(request);
}
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2023-07-06,如有侵权请联系 cloudcommunity@tencent 删除chatgpt部署服务器域名开源发布者:admin,转转请注明出处:http://www.yc00.com/web/1755045129a5232410.html
评论列表(0条)