- 添加完整的项目基础结构,包括配置、类型定义和常量 - 实现OAuth认证流程和令牌管理 - 开发请求转换和响应处理逻辑 - 添加SSE流处理和ChatCompletions API转换 - 实现模型映射和提示指令系统 - 包含Docker部署配置和快速启动文档 - 添加自动登录功能和测试脚本
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
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: "Say hi in one word" }],
|
|
stream: true,
|
|
}),
|
|
});
|
|
|
|
console.log("Status:", response.status);
|
|
|
|
const reader = response.body.getReader();
|
|
const decoder = new TextDecoder();
|
|
let buffer = "";
|
|
let count = 0;
|
|
|
|
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);
|
|
console.log(
|
|
`Response ${count}:`,
|
|
JSON.stringify(parsed).substring(0, 200),
|
|
);
|
|
} catch (e) {
|
|
console.log(`Raw response ${count}:`, data.substring(0, 100));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|