feat: 实现ChatGPT Codex路由器的核心功能
- 添加完整的项目基础结构,包括配置、类型定义和常量 - 实现OAuth认证流程和令牌管理 - 开发请求转换和响应处理逻辑 - 添加SSE流处理和ChatCompletions API转换 - 实现模型映射和提示指令系统 - 包含Docker部署配置和快速启动文档 - 添加自动登录功能和测试脚本
This commit is contained in:
57
test-longer-response.js
Normal file
57
test-longer-response.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const response = await fetch("http://localhost:3000/v1/chat/completions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: "gpt-5.2",
|
||||
messages: [
|
||||
{ role: "user", content: "What is 2+2? Answer in one sentence." },
|
||||
],
|
||||
stream: true,
|
||||
}),
|
||||
});
|
||||
|
||||
console.log("Status:", response.status);
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = "";
|
||||
let count = 0;
|
||||
let fullContent = "";
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
const lines = buffer.split("\n");
|
||||
buffer = lines.pop() || "";
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.startsWith("data: ")) {
|
||||
count++;
|
||||
const data = line.substring(6);
|
||||
if (data.trim() !== "[DONE]") {
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
if (parsed.choices && parsed.choices[0]) {
|
||||
const delta = parsed.choices[0].delta;
|
||||
if (delta.content) {
|
||||
fullContent += delta.content;
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
`Chunk ${count}: ${JSON.stringify(parsed).substring(0, 150)}`,
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(`Raw chunk ${count}:`, data.substring(0, 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("\n=== Full Content ===");
|
||||
console.log(fullContent);
|
||||
console.log("===================");
|
||||
Reference in New Issue
Block a user