opt
This commit is contained in:
parent
1b0b291dad
commit
254b2591d2
@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "渠道应用开发部知识库",
|
||||
"version": "2.0.10",
|
||||
"version": "2.0.11",
|
||||
"description": "通过关键词快速搜索内部文档",
|
||||
"permissions": ["storage"],
|
||||
"host_permissions": [
|
||||
|
||||
@ -14,4 +14,5 @@
|
||||
| 2025.06.19 | V2.0.8 | Luke.Ye | 对象存储上传优化,适配后端新接口 |
|
||||
| 2025.06.20 | V2.0.9 | Luke.Ye | 上传记录页面支持删除历史记录(会同时清空对象存储和ES) |
|
||||
| 2025.06.22 | V2.0.10 | Luke.Ye | 搜索结果页分页展示优化 |
|
||||
| 2025.06.23 | V2.0.11 | Luke.Ye | 准备做llm接口迁移 |
|
||||
|
||||
|
||||
@ -367,10 +367,9 @@ async function fetchLLMAnswer(question, container, contentDiv) {
|
||||
if (!question || !question.trim()) return;
|
||||
|
||||
const config = await loadMergedConfig();
|
||||
const llmChatCfg = config.apiConfig.llmChat;
|
||||
const llmToken = await getLLMToken();
|
||||
const workspaceSlug = await getLLMWorkspaceSlug(llmToken);
|
||||
const url = llmChatCfg.url.replace("${workId}", workspaceSlug);
|
||||
const userToken = await loadToken();
|
||||
const url = "http://app-test.wisdompulse.cn/api/v1/llm/ask";
|
||||
|
||||
const userItem = document.createElement("div");
|
||||
userItem.className = "llm-msg-item llm-user";
|
||||
@ -386,14 +385,16 @@ async function fetchLLMAnswer(question, container, contentDiv) {
|
||||
let collectedSources = [];
|
||||
let jumpMap = {};
|
||||
try {
|
||||
const body = {};
|
||||
body[llmChatCfg.requestParams[0].field] = question;
|
||||
body[llmChatCfg.requestParams[1].field] = [];
|
||||
const body = {
|
||||
llmToken,
|
||||
question
|
||||
// 可选扩展参数可追加到 body 中,如 slug/wsName/attachments
|
||||
};
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${llmToken}`,
|
||||
"Authorization": `${userToken}`,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
@ -415,10 +416,22 @@ async function fetchLLMAnswer(question, container, contentDiv) {
|
||||
if (value) {
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
const lines = buffer.split("\n");
|
||||
buffer = lines.pop();
|
||||
buffer = lines.pop(); // 剩下不完整的一行留给下一次
|
||||
|
||||
for (let line of lines) {
|
||||
if (line.startsWith("data: ")) {
|
||||
const chunk = JSON.parse(line.slice(6));
|
||||
const chunkStr = line.slice(6).trim();
|
||||
if (!chunkStr) continue;
|
||||
|
||||
let chunk;
|
||||
try {
|
||||
chunk = JSON.parse(chunkStr);
|
||||
} catch (err) {
|
||||
console.warn("非法 JSON:", chunkStr);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 解析内容片段
|
||||
if (chunk.sources) {
|
||||
for (const s of chunk.sources) {
|
||||
if (!collectedSources.find(x => x.id === s.id)) {
|
||||
@ -442,7 +455,6 @@ async function fetchLLMAnswer(question, container, contentDiv) {
|
||||
answerStr += content;
|
||||
}
|
||||
|
||||
// 渲染 markdown,代码块加复制按钮
|
||||
let html = "";
|
||||
try {
|
||||
html = window.marked ? wrapHtmlWithCopyBtn(marked.parse(answerStr)) : answerStr.replace(/\n/g, "<br>");
|
||||
@ -456,7 +468,6 @@ async function fetchLLMAnswer(question, container, contentDiv) {
|
||||
|
||||
bindAllCopyButtons(msgBox);
|
||||
insertCopyFullAnswerBtn(msgBox, answerStr);
|
||||
|
||||
contentDiv.scrollTop = contentDiv.scrollHeight;
|
||||
}
|
||||
}
|
||||
@ -478,3 +489,4 @@ async function fetchLLMAnswer(question, container, contentDiv) {
|
||||
msgBox.innerHTML += `<span style='color:red;'>LLM异常:${e}</span>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user