fix: webui English fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
// lightrag.js
|
// lightrag.js
|
||||||
const API_BASE = 'http://localhost:9621'; // 根据实际API地址修改
|
// Modify according to the actual API address
|
||||||
|
const API_BASE = 'http://localhost:9621';
|
||||||
|
|
||||||
// init
|
// init
|
||||||
function initializeApp() {
|
function initializeApp() {
|
||||||
@@ -7,7 +8,7 @@ function initializeApp() {
|
|||||||
setupQueryHandler();
|
setupQueryHandler();
|
||||||
setupSectionObserver();
|
setupSectionObserver();
|
||||||
updateFileList();
|
updateFileList();
|
||||||
// 文本输入框实时字数统计 textarea count
|
// textarea count
|
||||||
const textArea = document.getElementById('textContent');
|
const textArea = document.getElementById('textContent');
|
||||||
if (textArea) {
|
if (textArea) {
|
||||||
const charCount = document.createElement('div');
|
const charCount = document.createElement('div');
|
||||||
@@ -22,7 +23,7 @@ function initializeApp() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通用请求方法 api request
|
// api request
|
||||||
async function apiRequest(endpoint, method = 'GET', body = null) {
|
async function apiRequest(endpoint, method = 'GET', body = null) {
|
||||||
const options = {
|
const options = {
|
||||||
method,
|
method,
|
||||||
@@ -53,11 +54,11 @@ async function handleTextUpload() {
|
|||||||
const content = document.getElementById('textContent').value.trim();
|
const content = document.getElementById('textContent').value.trim();
|
||||||
const statusDiv = document.getElementById('textUploadStatus');
|
const statusDiv = document.getElementById('textUploadStatus');
|
||||||
|
|
||||||
// 清空状态提示 clear status tip
|
// clear status tip
|
||||||
statusDiv.className = 'status-indicator';
|
statusDiv.className = 'status-indicator';
|
||||||
statusDiv.textContent = '';
|
statusDiv.textContent = '';
|
||||||
|
|
||||||
// 输入验证 input valid
|
// input valid
|
||||||
if (!content) {
|
if (!content) {
|
||||||
showStatus('error', 'TEXT CONTENT NOT NULL', statusDiv);
|
showStatus('error', 'TEXT CONTENT NOT NULL', statusDiv);
|
||||||
return;
|
return;
|
||||||
@@ -66,7 +67,6 @@ async function handleTextUpload() {
|
|||||||
try {
|
try {
|
||||||
showStatus('loading', 'UPLOADING...', statusDiv);
|
showStatus('loading', 'UPLOADING...', statusDiv);
|
||||||
|
|
||||||
//
|
|
||||||
const payload = {
|
const payload = {
|
||||||
text: content,
|
text: content,
|
||||||
...(description && {description})
|
...(description && {description})
|
||||||
@@ -82,17 +82,17 @@ async function handleTextUpload() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
const errorData = await response.json();
|
||||||
throw new Error(errorData.detail || '上传失败');
|
throw new Error(errorData.detail || 'UPLOAD FAILED');
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
showStatus('success', `✅ ${result.message} (文档数: ${result.document_count})`, statusDiv);
|
showStatus('success', `✅ ${result.message} (documents: ${result.document_count})`, statusDiv);
|
||||||
|
|
||||||
|
|
||||||
document.getElementById('textContent').value = '';
|
document.getElementById('textContent').value = '';
|
||||||
|
|
||||||
// 更新文件列表 update file list
|
// update file list
|
||||||
updateFileList();
|
updateFileList();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -105,7 +105,7 @@ function showStatus(type, message, container) {
|
|||||||
container.textContent = message;
|
container.textContent = message;
|
||||||
container.className = `status-indicator ${type}`;
|
container.className = `status-indicator ${type}`;
|
||||||
|
|
||||||
// 自动清除成功状态 auto clear success status
|
//auto clear success status
|
||||||
if (type === 'success') {
|
if (type === 'success') {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
container.textContent = '';
|
container.textContent = '';
|
||||||
@@ -114,13 +114,13 @@ function showStatus(type, message, container) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件上传处理 upload file
|
// upload file
|
||||||
function setupFileUpload() {
|
function setupFileUpload() {
|
||||||
const dropzone = document.getElementById('dropzone');
|
const dropzone = document.getElementById('dropzone');
|
||||||
const fileInput = document.getElementById('fileInput');
|
const fileInput = document.getElementById('fileInput');
|
||||||
|
|
||||||
|
|
||||||
// 拖放事件处理 Drag and drop event handling
|
// Drag and drop event handling
|
||||||
dropzone.addEventListener('dragover', (e) => {
|
dropzone.addEventListener('dragover', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
dropzone.classList.add('active');
|
dropzone.classList.add('active');
|
||||||
@@ -179,7 +179,7 @@ async function updateFileList() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 智能检索处理 Intelligent retrieval processing
|
// Intelligent retrieval processing
|
||||||
function setupQueryHandler() {
|
function setupQueryHandler() {
|
||||||
document.querySelector('#query .btn-primary').addEventListener('click', handleQuery);
|
document.querySelector('#query .btn-primary').addEventListener('click', handleQuery);
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ async function handleQuery() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理流式响应 handle stream api
|
// handle stream api
|
||||||
async function handleStreamingQuery(payload, resultsDiv) {
|
async function handleStreamingQuery(payload, resultsDiv) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE}/query/stream`, {
|
const response = await fetch(`${API_BASE}/query/stream`, {
|
||||||
@@ -238,7 +238,7 @@ async function handleStreamingQuery(payload, resultsDiv) {
|
|||||||
|
|
||||||
buffer += decoder.decode(value, {stream: true});
|
buffer += decoder.decode(value, {stream: true});
|
||||||
|
|
||||||
// 按换行符分割(NDJSON格式要求) Split by line break (NDJSON format requirement)
|
// Split by line break (NDJSON format requirement)
|
||||||
let lineEndIndex;
|
let lineEndIndex;
|
||||||
while ((lineEndIndex = buffer.indexOf('\n')) >= 0) {
|
while ((lineEndIndex = buffer.indexOf('\n')) >= 0) {
|
||||||
const line = buffer.slice(0, lineEndIndex).trim();
|
const line = buffer.slice(0, lineEndIndex).trim();
|
||||||
@@ -267,7 +267,7 @@ async function handleStreamingQuery(payload, resultsDiv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理剩余数据 Process remaining data
|
// Process remaining data
|
||||||
if (buffer.trim()) {
|
if (buffer.trim()) {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(buffer.trim());
|
const data = JSON.parse(buffer.trim());
|
||||||
@@ -285,7 +285,7 @@ async function handleStreamingQuery(payload, resultsDiv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 知识问答处理 Knowledge Q&A Processing
|
// Knowledge Q&A Processing
|
||||||
function setupChatHandler() {
|
function setupChatHandler() {
|
||||||
const sendButton = document.querySelector('#chat button');
|
const sendButton = document.querySelector('#chat button');
|
||||||
const chatInput = document.querySelector('#chat input');
|
const chatInput = document.querySelector('#chat input');
|
||||||
@@ -344,7 +344,7 @@ async function handleChat(chatInput) {
|
|||||||
chatInput.value = '';
|
chatInput.value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 系统状态更新 system status update
|
// system status update
|
||||||
async function updateSystemStatus() {
|
async function updateSystemStatus() {
|
||||||
const statusElements = {
|
const statusElements = {
|
||||||
health: document.getElementById('healthStatus'),
|
health: document.getElementById('healthStatus'),
|
||||||
@@ -365,27 +365,27 @@ async function updateSystemStatus() {
|
|||||||
try {
|
try {
|
||||||
const status = await apiRequest('/health');
|
const status = await apiRequest('/health');
|
||||||
|
|
||||||
// 健康状态 heath status
|
// heath status
|
||||||
statusElements.health.className = 'status-badge';
|
statusElements.health.className = 'status-badge';
|
||||||
statusElements.health.textContent = status.status === 'healthy' ?
|
statusElements.health.textContent = status.status === 'healthy' ?
|
||||||
'✅ Healthy operation in progress' : '⚠️ Service exception';
|
'✅ Healthy operation in progress' : '⚠️ Service exception';
|
||||||
|
|
||||||
// 存储状态(示例逻辑,可根据实际需求修改) kv status
|
// kv status
|
||||||
const progressValue = Math.min(Math.round((status.indexed_files_count / 1000) * 100), 100);
|
const progressValue = Math.min(Math.round((status.indexed_files_count / 1000) * 100), 100);
|
||||||
statusElements.storageProgress.value = progressValue;
|
statusElements.storageProgress.value = progressValue;
|
||||||
statusElements.indexedFiles.textContent = `INDEXED FILES:${status.indexed_files_count}`;
|
statusElements.indexedFiles.textContent = `INDEXED FILES:${status.indexed_files_count}`;
|
||||||
statusElements.storageUsage.textContent = `USE PERCENT:${progressValue}%`;
|
statusElements.storageUsage.textContent = `USE PERCENT:${progressValue}%`;
|
||||||
|
|
||||||
// 模型配置 model state
|
// model state
|
||||||
statusElements.llmModel.textContent = `${status.configuration.llm_model} (${status.configuration.llm_binding})`;
|
statusElements.llmModel.textContent = `${status.configuration.llm_model} (${status.configuration.llm_binding})`;
|
||||||
statusElements.embedModel.textContent = `${status.configuration.embedding_model} (${status.configuration.embedding_binding})`;
|
statusElements.embedModel.textContent = `${status.configuration.embedding_model} (${status.configuration.embedding_binding})`;
|
||||||
statusElements.maxTokens.textContent = status.configuration.max_tokens.toLocaleString();
|
statusElements.maxTokens.textContent = status.configuration.max_tokens.toLocaleString();
|
||||||
|
|
||||||
// 目录信息 dir msg
|
// dir msg
|
||||||
statusElements.workingDir.textContent = status.working_directory;
|
statusElements.workingDir.textContent = status.working_directory;
|
||||||
statusElements.inputDir.textContent = status.input_directory;
|
statusElements.inputDir.textContent = status.input_directory;
|
||||||
|
|
||||||
//存储信息 stack msg
|
// stack msg
|
||||||
statusElements.kv_storage.textContent = status.configuration.kv_storage;
|
statusElements.kv_storage.textContent = status.configuration.kv_storage;
|
||||||
statusElements.doc_status_storage.textContent = status.configuration.doc_status_storage;
|
statusElements.doc_status_storage.textContent = status.configuration.doc_status_storage;
|
||||||
statusElements.graph_storage.textContent = status.configuration.graph_storage;
|
statusElements.graph_storage.textContent = status.configuration.graph_storage;
|
||||||
@@ -401,7 +401,7 @@ async function updateSystemStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 区域切换监听 Area switching monitoring
|
// Area switching monitoring
|
||||||
function setupSectionObserver() {
|
function setupSectionObserver() {
|
||||||
const observer = new MutationObserver(mutations => {
|
const observer = new MutationObserver(mutations => {
|
||||||
mutations.forEach(mutation => {
|
mutations.forEach(mutation => {
|
||||||
@@ -419,7 +419,7 @@ function setupSectionObserver() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示提示信息 Display prompt information
|
// Display prompt information
|
||||||
function showToast(message, type = 'info') {
|
function showToast(message, type = 'info') {
|
||||||
const toast = document.createElement('div');
|
const toast = document.createElement('div');
|
||||||
toast.className = `toast ${type}`;
|
toast.className = `toast ${type}`;
|
||||||
@@ -432,7 +432,7 @@ function showToast(message, type = 'info') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 动态加载标签列表 Dynamically load tag list
|
// Dynamically load tag list
|
||||||
async function loadLabels() {
|
async function loadLabels() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/graph/label/list');
|
const response = await fetch('/graph/label/list');
|
||||||
@@ -445,7 +445,7 @@ async function loadLabels() {
|
|||||||
|
|
||||||
async function loadGraph(label) {
|
async function loadGraph(label) {
|
||||||
try {
|
try {
|
||||||
// 渲染标签列表 render label list
|
// render label list
|
||||||
openGraphModal(label)
|
openGraphModal(label)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('LOADING LABEL FAILED:', error);
|
console.error('LOADING LABEL FAILED:', error);
|
||||||
@@ -460,7 +460,7 @@ async function loadGraph(label) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染标签列表 render graph label list
|
// render graph label list
|
||||||
function renderLabels(labels) {
|
function renderLabels(labels) {
|
||||||
const container = document.getElementById('label-list');
|
const container = document.getElementById('label-list');
|
||||||
container.innerHTML = labels.map(label => `
|
container.innerHTML = labels.map(label => `
|
||||||
|
Reference in New Issue
Block a user