app添加工作经历开发

This commit is contained in:
冯辉
2025-10-13 16:01:49 +08:00
parent 3d7cb0c561
commit 3d2c26650c
12 changed files with 840 additions and 74 deletions

View File

@@ -31,13 +31,19 @@ export default function StreamRequest(url, data = {}, onDataReceived, onError, o
const decoder = new TextDecoder("utf-8");
let buffer = "";
let retryCount = 0;
const maxRetries = 3;
while (true) {
const {
done,
value
} = await reader.read();
if (done) break;
if (done) {
console.log("📡 Stream reading completed");
break;
}
buffer += decoder.decode(value, {
stream: true
@@ -45,6 +51,9 @@ export default function StreamRequest(url, data = {}, onDataReceived, onError, o
let lines = buffer.split("\n");
buffer = lines.pop(); // 可能是不完整的 JSON 片段,留待下次解析
console.log(`📦 Processing ${lines.length} lines, buffer length: ${buffer.length}`);
for (let line of lines) {
if (line.startsWith("data: ")) {
const jsonData = line.slice(6).trim();
@@ -55,20 +64,84 @@ export default function StreamRequest(url, data = {}, onDataReceived, onError, o
}
try {
const parsedData = JSON.parse(jsonData);
const content = parsedData?.choices?.[0]?.delta?.content ??
parsedData?.choices?.[0]?.delta?.reasoning_content ??
"";
if (content) {
onDataReceived && onDataReceived(content);
// 检查JSON数据是否完整
if (jsonData && jsonData.trim() && jsonData !== "[DONE]") {
const parsedData = JSON.parse(jsonData);
// 处理标准的choices格式
if (parsedData?.choices?.[0]?.delta?.content) {
const content = parsedData.choices[0].delta.content;
if (content) {
onDataReceived && onDataReceived(content);
}
}
// 处理reasoning_content
else if (parsedData?.choices?.[0]?.delta?.reasoning_content) {
const content = parsedData.choices[0].delta.reasoning_content;
if (content) {
onDataReceived && onDataReceived(content);
}
}
// 处理tool响应
else if (parsedData?.tool?.response) {
const content = parsedData.tool.response;
if (content) {
onDataReceived && onDataReceived(content);
}
}
// 处理其他格式的数据如jobs_array_number, durationSeconds等
else {
console.log("📦 收到非内容数据:", Object.keys(parsedData));
}
}
} catch (e) {
console.error("JSON 解析失败:", e, "原始数据:", jsonData);
console.error("JSON 解析失败:", e.message, "原始数据长度:", jsonData.length, "数据预览:", jsonData.substring(0, 100) + "...");
// 不抛出错误,继续处理下一个数据块
}
}
}
}
// 处理剩余的缓冲区数据
if (buffer.trim()) {
console.log("📦 Processing remaining buffer:", buffer.substring(0, 100) + "...");
const lines = buffer.split("\n");
for (let line of lines) {
if (line.startsWith("data: ")) {
const jsonData = line.slice(6).trim();
if (jsonData && jsonData !== "[DONE]") {
try {
const parsedData = JSON.parse(jsonData);
// 处理标准的choices格式
if (parsedData?.choices?.[0]?.delta?.content) {
const content = parsedData.choices[0].delta.content;
if (content) {
onDataReceived && onDataReceived(content);
}
}
// 处理reasoning_content
else if (parsedData?.choices?.[0]?.delta?.reasoning_content) {
const content = parsedData.choices[0].delta.reasoning_content;
if (content) {
onDataReceived && onDataReceived(content);
}
}
// 处理tool响应
else if (parsedData?.tool?.response) {
const content = parsedData.tool.response;
if (content) {
onDataReceived && onDataReceived(content);
}
}
} catch (e) {
console.warn("处理剩余数据时JSON解析失败:", e.message);
}
}
}
}
}
onComplete && onComplete();
resolve();
} catch (error) {