优化test页面

This commit is contained in:
luke 2025-07-04 00:05:15 +08:00
parent 57db5e4369
commit 92ce1bf574
4 changed files with 57 additions and 39 deletions

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "渠道应用开发部知识库", "name": "渠道应用开发部知识库",
"version": "2.0.13", "version": "2.0.14",
"description": "通过关键词快速搜索内部文档", "description": "通过关键词快速搜索内部文档",
"permissions": ["storage"], "permissions": ["storage"],
"host_permissions": [ "host_permissions": [

View File

@ -8,6 +8,11 @@
<h3>SSE 结果:</h3> <h3>SSE 结果:</h3>
<pre id="output"></pre> <pre id="output"></pre>
<script src="../scripts/config.js"></script>
<script src="../scripts/utils.js"></script>
<script src="../scripts/auth.js"></script>
<script src="../scripts/llm.js"></script>
<script src="../scripts/popup.js"></script>
<script src="../scripts/test.js"></script> <script src="../scripts/test.js"></script>
</body> </body>
</html> </html>

View File

@ -17,4 +17,6 @@
| 2025.06.23 | V2.0.11 | Luke.Ye | 准备做llm接口迁移 | | 2025.06.23 | V2.0.11 | Luke.Ye | 准备做llm接口迁移 |
| 2025.06.24 | V2.0.12 | Luke.Ye | 添加测试页面 | | 2025.06.24 | V2.0.12 | Luke.Ye | 添加测试页面 |
| 2025.06.28 | V2.0.13 | Luke.Ye | 优化分页展示 | | 2025.06.28 | V2.0.13 | Luke.Ye | 优化分页展示 |
| 2025.07.03 | V2.0.14 | Luke.Ye | test页面逻辑优化 |

View File

@ -1,13 +1,24 @@
document.addEventListener("DOMContentLoaded", async () => {
const output = document.getElementById("output"); const output = document.getElementById("output");
fetch("http://localhost:18081/api/v1/llm/demo", { llmToken = await getLLMToken();
const auth = await loadUserToken();
if (!auth) {
handleLogout(auth);
}
const userToken = auth.token;
const url = "http://app-test.wisdompulse.cn/api/v1/llm/ask";
const question = "请背诵王勃的《滕王阁序》,开头是'豫章故郡,洪都新府'这句,并基于这篇文章写一个小故事"
const body = { llmToken, question };
fetch(url, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Authorization": `${userToken}`,
"Accept": "text/event-stream", "Accept": "text/event-stream",
"Authorization": "Bearer test" "Content-Type": "application/json"
}, },
body: JSON.stringify({}) body: JSON.stringify(body)
}).then(response => { }).then(response => {
const reader = response.body.getReader(); const reader = response.body.getReader();
const decoder = new TextDecoder("utf-8"); const decoder = new TextDecoder("utf-8");
@ -32,7 +43,7 @@ fetch("http://localhost:18081/api/v1/llm/demo", {
const jsonStr = line.substring(5).trim(); const jsonStr = line.substring(5).trim();
try { try {
const data = JSON.parse(jsonStr); const data = JSON.parse(jsonStr);
output.textContent += `收到:${data.content || '[无内容]'}\n`; output.textContent += `${data.textResponse || '[无内容]'}`;
} catch (e) { } catch (e) {
output.textContent += `解析失败:${jsonStr}\n`; output.textContent += `解析失败:${jsonStr}\n`;
} }
@ -45,4 +56,4 @@ fetch("http://localhost:18081/api/v1/llm/demo", {
read(); read();
}); });
});