From 3406032f25f10886b1ed4979e1c6afaed21c4e6a Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Wed, 16 Jul 2025 15:33:09 +0800 Subject: [PATCH 1/3] 'commit' --- dsLightRag/Start.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dsLightRag/Start.py b/dsLightRag/Start.py index 576c7231..6ce31f51 100644 --- a/dsLightRag/Start.py +++ b/dsLightRag/Start.py @@ -36,6 +36,10 @@ app = FastAPI(lifespan=lifespan) # 挂载静态文件目录 app.mount("/static", StaticFiles(directory="Static"), name="static") +# 访问根的跳转 +@app.get("/") +async def redirect_to_ai(): + return fastapi.responses.RedirectResponse(url="/static/ai.html") @app.post("/api/rag") async def rag(request: fastapi.Request): From e5e1d3d51f5456bd4226f8bc92da88d45d2050e5 Mon Sep 17 00:00:00 2001 From: "Kalman.CHENG" <123204464@qq.com> Date: Wed, 16 Jul 2025 15:47:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=95=99=E8=82=B2=E5=9E=82=E7=9B=B4?= =?UTF-8?q?=E9=A2=86=E5=9F=9F=E5=A4=A7=E6=A8=A1=E5=9E=8B=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=20modify=20by=20Kalman.CHENG=20=E2=98=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/TeachingModelController.py | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/dsAiTeachingModel/api/controller/TeachingModelController.py b/dsAiTeachingModel/api/controller/TeachingModelController.py index ec7ec3fb..ac84ca29 100644 --- a/dsAiTeachingModel/api/controller/TeachingModelController.py +++ b/dsAiTeachingModel/api/controller/TeachingModelController.py @@ -77,4 +77,39 @@ async def get_question(request: Request): select_question_sql: str = f"SELECT * FROM t_ai_teaching_model_question WHERE is_deleted = 0 and bureau_id = '{bureau_id}' AND theme_id = {theme_id} AND question_type = {question_type} {person_sql}" print(select_question_sql) page = await get_page_data_by_sql(select_question_sql, page_number, page_size) - return {"success": True, "message": "查询成功!", "data": page} \ No newline at end of file + return {"success": True, "message": "查询成功!", "data": page} + + + +# 【TeachingModel-5】提问 +@router.post("/sendQuestion") +async def send_question(request: Request): + # 获取参数 + bureau_id = await get_request_str_param(request, "bureau_id", True, True) + person_id = await get_request_str_param(request, "person_id", True, True) + theme_id = await get_request_num_param(request, "theme_id", True, True, None) + question = await get_request_str_param(request, "question_type", True, True) + + theme_object = await find_by_id("t_ai_teaching_model_theme", "id", theme_id) + if theme_object is None: + return {"success": False, "message": "主题不存在!"} + + # 保存个人历史问题 + param = {} + param["stage_id"] = int(theme_object["stage_id"]) + param["subject_id"] = int(theme_object["subject_id"]) + param["theme_id"] = theme_id + param["question"] = question + param["question_type"] = 2 + param["question_person_id"] = person_id + param["person_id"] = person_id + param["bureau_id"] = bureau_id + question_id = await insert("t_ai_teaching_model_question", param) + + # 处理theme的调用次数 + + + + # 向rag提问 + + From a45677716f93b91c210f14acea688fbe7159a17f Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Wed, 16 Jul 2025 16:19:31 +0800 Subject: [PATCH 3/3] 'commit' --- dsLightRag/Start.py | 65 ++++++++++++++++++--------------- dsLightRag/Util/LightRagUtil.py | 4 +- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/dsLightRag/Start.py b/dsLightRag/Start.py index 6ce31f51..f3651ae3 100644 --- a/dsLightRag/Start.py +++ b/dsLightRag/Start.py @@ -36,17 +36,18 @@ app = FastAPI(lifespan=lifespan) # 挂载静态文件目录 app.mount("/static", StaticFiles(directory="Static"), name="static") + # 访问根的跳转 @app.get("/") async def redirect_to_ai(): return fastapi.responses.RedirectResponse(url="/static/ai.html") + @app.post("/api/rag") async def rag(request: fastapi.Request): data = await request.json() - logger.info(f"Received request: {data}") workspace = data.get("topic", "ShiJi") # Chinese, Math ,ShiJi 默认是少年读史记 - mode = data.get("mode", "hybrid") # 默认为hybrid模式 + logger.info("工作空间:" + workspace) # 查询的问题 query = data.get("query") @@ -108,9 +109,7 @@ async def rag(request: fastapi.Request): rag = await initialize_pg_rag(WORKING_DIR=WORKING_DIR, workspace=workspace) resp = await rag.aquery( query=query, - param=QueryParam(mode=mode, stream=True, user_prompt=user_prompt)) - # hybrid naive - + param=QueryParam(mode="hybrid", stream=True, user_prompt=user_prompt)) async for chunk in resp: if not chunk: continue @@ -184,15 +183,15 @@ async def get_tree_data(): async with pg_pool.acquire() as conn: # 执行查询 rows = await conn.fetch(""" - SELECT id, - title, - parent_id, - is_leaf, - prerequisite, - related - FROM knowledge_points - ORDER BY parent_id, id - """) + SELECT id, + title, + parent_id, + is_leaf, + prerequisite, + related + FROM knowledge_points + ORDER BY parent_id, id + """) # 构建节点映射 nodes = {} for row in rows: @@ -249,10 +248,10 @@ async def update_knowledge(request: fastapi.Request): async with pg_pool.acquire() as conn: if update_type == 'prerequisite': await conn.execute(""" - UPDATE knowledge_points - SET prerequisite = $1 - WHERE id = $2 - """, + UPDATE knowledge_points + SET prerequisite = $1 + WHERE id = $2 + """, json.dumps( [{"id": p["id"], "title": p["title"]} for p in knowledge], ensure_ascii=False @@ -260,10 +259,10 @@ async def update_knowledge(request: fastapi.Request): node_id) else: # related knowledge await conn.execute(""" - UPDATE knowledge_points - SET related = $1 - WHERE id = $2 - """, + UPDATE knowledge_points + SET related = $1 + WHERE id = $2 + """, json.dumps( [{"id": p["id"], "title": p["title"]} for p in knowledge], ensure_ascii=False @@ -310,10 +309,11 @@ async def get_sources(page: int = 1, limit: int = 10): offset = (page - 1) * limit rows = await conn.fetch( """ - SELECT id, account_id,account_name, created_at - FROM t_wechat_source - ORDER BY created_at DESC - LIMIT $1 OFFSET $2 + SELECT id, account_id, account_name, created_at + FROM t_wechat_source + ORDER BY created_at DESC + LIMIT $1 + OFFSET $2 """, limit, offset ) @@ -352,11 +352,16 @@ async def get_articles(page: int = 1, limit: int = 10): offset = (page - 1) * limit rows = await conn.fetch( """ - SELECT a.id, a.title, a.source as name, - a.publish_time, a.collection_time,a.url + SELECT a.id, + a.title, + a.source as name, + a.publish_time, + a.collection_time, + a.url FROM t_wechat_articles a - ORDER BY a.collection_time DESC - LIMIT $1 OFFSET $2 + ORDER BY a.collection_time DESC + LIMIT $1 + OFFSET $2 """, limit, offset ) diff --git a/dsLightRag/Util/LightRagUtil.py b/dsLightRag/Util/LightRagUtil.py index 9e42b8d7..b1f78cd2 100644 --- a/dsLightRag/Util/LightRagUtil.py +++ b/dsLightRag/Util/LightRagUtil.py @@ -152,14 +152,14 @@ os.environ["POSTGRES_PASSWORD"] = POSTGRES_PASSWORD os.environ["POSTGRES_DATABASE"] = POSTGRES_DATABASE -async def initialize_pg_rag(WORKING_DIR, workspace='default'): +async def initialize_pg_rag(WORKING_DIR, workspace): rag = LightRAG( working_dir=WORKING_DIR, llm_model_func=llm_model_func, llm_model_name=LLM_MODEL_NAME, llm_model_max_async=4, llm_model_max_token_size=32768, - enable_llm_cache_for_entity_extract=True, + enable_llm_cache_for_entity_extract=False, # 这里黄海修改了一下,不知道是不是有用 embedding_func=EmbeddingFunc( embedding_dim=EMBED_DIM, max_token_size=EMBED_MAX_TOKEN_SIZE,