Skip to content

Commit

Permalink
更新V0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
fatwang2 committed Mar 17, 2024
1 parent 55dab17 commit 637fbe0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: fatwang2
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
.vercel
.env
.env
wrangler.toml
.wrangler
1 change: 1 addition & 0 deletions README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<a href="https://www.buymeacoffee.com/fatwang2" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

# Version Updates
- V0.1.9, 20240318, optimized the handling of streams in openai.js for faster speed, recommend updating; fixed the audio issue in the server deployment version; added a sponsored button on Github.
- V0.1.8, 20240305, support search1api search service, update Gemini version search variable configuration, open news search capability, add risk statement
- V0.1.7, 20240224, Gemini version supports streaming output and is compatible with vision model
- V0.1.6, 20240221, Supports Gemini model, can be temporarily configured through Cloudflare worker method
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<a href="https://www.buymeacoffee.com/fatwang2" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

# 版本更新
- V0.1.9,20240318,优化openai.js对流式的处理方式,速度更快,建议更新;修复服务器部署版本的语音问题;增加Github赞助按钮
- V0.1.8,20240305,支持search1api搜索服务,更新Gemini版本搜索变量配置,开放新闻搜索能力,增加风险声明
- V0.1.7,20240224,Gemini版本支持流式输出,且兼容vision model
- V0.1.6,20240221,支持Gemini模型,暂时可通过cloudflare worker的方式配置
Expand Down
48 changes: 28 additions & 20 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,36 @@ module.exports = async (req, res) => {

// 创建服务器
const server = http.createServer((req, res) => {
// 只对 POST 请求读取请求体
if (req.method === 'POST') {
let data = '';
req.on('data', chunk => {
data += chunk;
});
req.on('end', () => {
try {
req.body = JSON.parse(data);
} catch (error) {
res.statusCode = 400;
res.end('Invalid JSON');
return;
}
processRequest(req, res);
});
} else {
// GET 和其他类型的请求直接处理
if (req.method === "POST") {
let body = []; // 使用数组来收集数据块
req.on("data", chunk => {
body.push(chunk); // 收集数据块
});
req.on("end", () => {
// 将数据块组合成完整的数据
const combinedData = Buffer.concat(body);
// 如果请求是音频,直接使用二进制数据
if (!req.url.startsWith("/v1/audio/")) {
try {
// 尝试解析JSON
req.body = JSON.parse(combinedData.toString());
} catch (error) {
res.statusCode = 400;
console.error("Invalid JSON:", error);
res.end("Invalid JSON");
return;
}
} else {
// 对于音频请求,直接使用二进制数据
req.body = combinedData;
}
processRequest(req, res);
});
} else {
// GET 和其他类型的请求直接处理
processRequest(req, res);
}
});

});
function processRequest(req, res) {
(async () => {
try {
Expand Down

0 comments on commit 637fbe0

Please sign in to comment.