Skip to content

Commit

Permalink
feat: Added webui management, including file upload, text upload, Q&A…
Browse files Browse the repository at this point in the history
… query, graph database management (can view tags, view knowledge graph based on tags), system status (whether it is good, data storage status, model status, path),request /webui/index.html
  • Loading branch information
18277486571HYB committed Jan 25, 2025
1 parent 207c0e8 commit 3dba406
Show file tree
Hide file tree
Showing 8 changed files with 1,698 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lightrag/api/lightrag_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ async def lifespan(app: FastAPI):
azure_openai_complete_if_cache,
azure_openai_embed,
)
if args.llm_binding_host == "openai-ollama" or args.embedding_binding == "ollama":
from lightrag.llm.openai import openai_complete_if_cache, openai_embed

async def openai_alike_model_complete(
prompt,
Expand Down Expand Up @@ -1380,7 +1382,16 @@ async def clear_documents():
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

# -------------------------------------------------
# query all graph labels
@app.get("/graph/label/list")
async def get_graph_labels():
return await rag.get_graph_labels()

# query all graph
@app.get("/graphs")
async def get_graphs(label: str):
return await rag.get_graps(nodel_label=label, max_depth=100)

# Ollama compatible API endpoints
# -------------------------------------------------
@app.get("/api/version")
Expand Down Expand Up @@ -1751,6 +1762,7 @@ async def get_status():
"working_directory": str(args.working_dir),
"input_directory": str(args.input_dir),
"indexed_files": doc_manager.indexed_files,
"indexed_files_count": len(doc_manager.scan_directory()),
"configuration": {
# LLM configuration binding/host address (if applicable)/model (if applicable)
"llm_binding": args.llm_binding,
Expand All @@ -1761,9 +1773,22 @@ async def get_status():
"embedding_binding_host": args.embedding_binding_host,
"embedding_model": args.embedding_model,
"max_tokens": args.max_tokens,
"kv_storage": KV_STORAGE,
"doc_status_storage": DOC_STATUS_STORAGE,
"graph_storage": GRAPH_STORAGE,
"vector_storage": VECTOR_STORAGE,
},
}

# webui mount /webui/index.html
app.mount(
"/webui",
StaticFiles(
directory=Path(__file__).resolve().parent / "webui" / "static", html=True
),
name="webui_static",
)

# Serve the static files
static_dir = Path(__file__).parent / "static"
static_dir.mkdir(exist_ok=True)
Expand Down
92 changes: 92 additions & 0 deletions lightrag/api/webui/static/css/graph.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* css/lightrag.css */

/* 模态框样式 */
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
z-index: 1000;
}

.modal-content {
background-color: var(--surface);
padding: 1.5rem;
border-radius: 8px;
width: 80%;
max-width: 1200px;
box-shadow: var(--shadow);
}

.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}

.modal-body {
margin-bottom: 1rem;
}

.modal-footer {
text-align: right;
}

.btn-close {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: var(--text-secondary);
}

.btn-close:hover {
color: var(--text-primary);
}

/* 图谱节点样式 */
.node {
cursor: pointer;
fill: var(--primary);
stroke: var(--surface);
stroke-width: 2px;
}

.node:hover {
fill: var(--secondary);
}

.link {
stroke: var(--text-secondary);
stroke-width: 2px;
}

.label {
font-size: 12px;
fill: var(--text-primary);
pointer-events: none;
}

/* 添加边样式 */
.link {
stroke: #999; /* 连线颜色 */
stroke-width: 2px; /* 连线粗细 */
stroke-opacity: 0.6;/* 透明度 */
}
/* 边样式 */
.link {
stroke: #999; /* 边颜色 */
stroke-width: 2px; /* 边粗细 */
stroke-opacity: 0.8; /* 边透明度 */
}

/* 箭头颜色匹配边颜色 */
#arrow path {
fill: #999 !important; /* 覆盖默认颜色 */
}
Loading

0 comments on commit 3dba406

Please sign in to comment.