diff --git a/wwwroot/knowledge_bases_list/create_kb.dspy b/wwwroot/knowledge_bases_list/create_kb.dspy new file mode 100644 index 0000000..8dd90f1 --- /dev/null +++ b/wwwroot/knowledge_bases_list/create_kb.dspy @@ -0,0 +1,18 @@ +ns = params_kw.copy() +db = DBPools() +dbname = get_module_dbname('rag') +async with db.sqlorContext(dbname) as sor: + import uuid + env = request._run_ns + userorgid = await env.get_userorgid() + kb_id = uuid.uuid4().hex[:12] + name = ns.get("name", "") + desc = ns.get("description", "") + engine = ns.get("embedding_engine", "CLIP ViT-H-14") + vdb = ns.get("vdb_collection", name) + await sor.sqlExe( + "INSERT INTO knowledge_bases (id, name, description, org_id, embedding_engine, vdb_collection, doc_count, total_size, chunk_count, status, created_at) " + "VALUES (${id}$, ${name}$, ${desc}$, ${org_id}$, ${engine}$, ${vdb}$, 0, 0, 0, 'active', NOW())", + {"id": kb_id, "name": name, "desc": desc, "org_id": userorgid, "engine": engine, "vdb": vdb}) + return {"status": "SUCCEEDED", "kb_id": kb_id} +return {"error": "failed"} diff --git a/wwwroot/knowledge_bases_list/index.ui b/wwwroot/knowledge_bases_list/index.ui index fe4c960..a8e481b 100644 --- a/wwwroot/knowledge_bases_list/index.ui +++ b/wwwroot/knowledge_bases_list/index.ui @@ -4,23 +4,45 @@ "cheight": 40, "width": "100%", "padding": "16px", - "spacing": "12px" + "spacing": "16px" }, "subwidgets": [ { "widgettype": "HBox", "options": {"width": "100%", "justifyContent": "space-between", "alignItems": "center"}, "subwidgets": [ - {"widgettype": "VBox", "options": {"spacing": "4px"}, "subwidgets": [ - {"widgettype": "Text", "options": {"text": "知识库", "cfontsize": 22, "fontWeight": "bold", "color": "#333"}}, - {"widgettype": "Text", "options": {"text": "点击知识库进入文档管理,支持多级目录和拖拽上传", "cfontsize": 14, "color": "#888"}} - ]}, + {"widgettype": "Text", "options": {"text": "知识库", "cfontsize": 22, "fontWeight": "bold", "color": "#333"}}, {"widgettype": "Button", "options": {"label": "+ 新建知识库", "bgcolor": "#4a90d9", "color": "#fff"}, "binds": [ - {"wid": "self", "event": "click", "actiontype": "urlwidget", "target": "app.rag_main_content", "mode": "replace", + {"wid": "self", "event": "tap", "actiontype": "urlwidget", "target": "app.rag_main_content", "mode": "replace", "options": {"url": "{{entire_url('/knowledge_bases_list/new_kb_form.ui')}}"}} ]} ] }, + { + "widgettype": "VBox", + "options": { + "width": "100%", + "bgcolor": "#f8f9fa", + "padding": "16px", + "css": "card", + "spacing": "8px" + }, + "subwidgets": [ + {"widgettype": "Text", "options": {"text": "💾 存储容量", "cfontsize": 14, "fontWeight": "bold", "color": "#333"}}, + { + "widgettype": "ProgressBar", + "options": { + "value": 15, + "total": 100, + "width": "100%", + "cheight": 1.2, + "bgcolor": "#e0e0e0", + "color": "#4a90d9" + } + }, + {"widgettype": "Text", "options": {"text": "已用 15MB / 总计 100MB · 15%", "cfontsize": 12, "color": "#888"}} + ] + }, { "widgettype": "urlwidget", "options": { diff --git a/wwwroot/knowledge_bases_list/new_kb_form.ui b/wwwroot/knowledge_bases_list/new_kb_form.ui index 732f842..90436a7 100644 --- a/wwwroot/knowledge_bases_list/new_kb_form.ui +++ b/wwwroot/knowledge_bases_list/new_kb_form.ui @@ -1,13 +1,19 @@ { "widgettype": "VBox", - "options": {"spacing": "12px", "padding": "16px"}, + "options": {"spacing": "16px", "padding": "16px"}, "subwidgets": [ - {"widgettype": "Text", "options": {"text": "新建知识库", "cfontsize": 18, "fontWeight": "bold"}}, - {"widgettype": "Text", "options": {"text": "", "cheight": 0.5}}, - {"widgettype": "Text", "options": {"text": "名称"}}, - {"widgettype": "Input", "options": {"id": "kb_name", "width": "100%"}}, - {"widgettype": "Text", "options": {"text": "描述"}}, - {"widgettype": "Input", "options": {"id": "kb_desc", "width": "100%"}}, + {"widgettype": "Text", "options": {"text": "新建知识库", "cfontsize": 20, "fontWeight": "bold"}}, + { + "widgettype": "Form", + "options": { + "fields": [ + {"name": "name", "title": "名称", "type": "str", "uitype": "str", "required": true}, + {"name": "description", "title": "描述", "type": "text", "uitype": "text"}, + {"name": "embedding_engine", "title": "向量引擎", "type": "str", "uitype": "str", "default": "CLIP ViT-H-14"}, + {"name": "vdb_collection", "title": "向量集合名", "type": "str", "uitype": "str"} + ] + } + }, {"widgettype": "Button", "options": {"label": "创建", "bgcolor": "#4a90d9", "color": "#fff"}}, {"widgettype": "Button", "options": {"label": "取消", "bgcolor": "#e0e0e0", "color": "#666"}, "binds": [ {"wid": "self", "event": "tap", "actiontype": "urlwidget", "target": "app.rag_main_content", "mode": "replace",