From 0e3f2e77f012eb2741ec80efed990845978609eb Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Sat, 12 Jul 2025 11:01:49 +0800 Subject: [PATCH] 'commit' --- dsLightRag/T3_MatchKP.py | 44 +++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/dsLightRag/T3_MatchKP.py b/dsLightRag/T3_MatchKP.py index 8cbcedce..34dc6acd 100644 --- a/dsLightRag/T3_MatchKP.py +++ b/dsLightRag/T3_MatchKP.py @@ -1,8 +1,9 @@ -from Util.MySQLUtil import init_mysql_pool from openai import OpenAI from Config.Config import LLM_API_KEY, LLM_BASE_URL, LLM_MODEL_NAME import asyncio +from Util.PostgreSQLUtil import init_postgres_pool + class QuestionMatcher: def __init__(self): @@ -29,30 +30,27 @@ class QuestionMatcher: async def main(): - mysql_pool = await init_mysql_pool() + pg_pool = await init_postgres_pool() matcher = QuestionMatcher() - async with mysql_pool.acquire() as conn: - await conn.ping() - async with conn.cursor() as cur: - await cur.execute("SELECT id, title,is_leaf FROM knowledge_points where is_leaf=1") - knowledge_points = await cur.fetchall() - - questions = [ - "小明有3个苹果,又买了5个,现在有多少个苹果?", - "一个长方形的长是5cm,宽是3cm,面积是多少?", - "小明的学校在小明家的东南方向150米处,他每天中午都回家吃饭,请问小明在上学和放学的路上一天一共走了多少米?", - "兰兰家在学校的南面500米处,方方家在兰兰家北面200米处,请问学校在方方家什么方向的多少米处?", - "小强的家门面向东,放学回家后站在门前,面向家门,他的前后左右分别是什么方向?", - "小明和小立背对背站立,小明向北走150米,小立向南走120米,两人相距多远?", - "1500棵树苗平均分给5个班种植,每个班又将树苗平均分给5个小组,每个小组分得多少棵树苗?", - "粮店运来120吨大米,第一天卖出总数的一半,第二天卖出剩下的一半,粮店还剩大米多少吨?" - ] - - for question in questions: - match_result = await matcher.match_question_to_knowledge(question, knowledge_points) - print(f"题目: {question}") - print(f"匹配结果: {match_result}") + async with pg_pool.acquire() as conn: + # 执行查询 + knowledge_points = await conn.fetch('SELECT id, title,is_leaf FROM knowledge_points where is_leaf=1') + questions = [ + "小明有3个苹果,又买了5个,现在有多少个苹果?", + "一个长方形的长是5cm,宽是3cm,面积是多少?", + "小明的学校在小明家的东南方向150米处,他每天中午都回家吃饭,请问小明在上学和放学的路上一天一共走了多少米?", + "兰兰家在学校的南面500米处,方方家在兰兰家北面200米处,请问学校在方方家什么方向的多少米处?", + "小强的家门面向东,放学回家后站在门前,面向家门,他的前后左右分别是什么方向?", + "小明和小立背对背站立,小明向北走150米,小立向南走120米,两人相距多远?", + "1500棵树苗平均分给5个班种植,每个班又将树苗平均分给5个小组,每个小组分得多少棵树苗?", + "粮店运来120吨大米,第一天卖出总数的一半,第二天卖出剩下的一半,粮店还剩大米多少吨?" + ] + + for question in questions: + match_result = await matcher.match_question_to_knowledge(question, knowledge_points) + print(f"题目: {question}") + print(f"匹配结果: {match_result}") if __name__ == '__main__':