From 9b065722bf5358c4d02e08148683ea81e370c360 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Mon, 18 Aug 2025 15:46:09 +0800 Subject: [PATCH] 'commit' --- .../Config/__pycache__/Config.cpython-310.pyc | Bin 1782 -> 1902 bytes dsLightRag/Test/G2_TeachingStudent.py | 75 +++++++++++++++--- .../__pycache__/GoApiUtil.cpython-310.pyc | Bin 2406 -> 2406 bytes 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/dsLightRag/Config/__pycache__/Config.cpython-310.pyc b/dsLightRag/Config/__pycache__/Config.cpython-310.pyc index 986c5b85a98f2d70f87e911ebd94c9200c823bc9..892a7740b3a50eb565d9dbd729de4058975388fe 100644 GIT binary patch delta 179 zcmeyy`;LzlX&CI;reWO@Cf{jegG9OH4Ver$`+N{80 z!DJD|=M^3jAMENJFDF`ALJS0;Tt9G=**I7;u<_Tg3X69Wb#rre-0LAAY|lV1ON=oF=hY& delta 58 zcmaFI_l=h?pO=@50SM;2o|loxF_BM(amhsOr7Xb=n#vm=crr8lX{v9IVzFSFe2UG7 N(QmRiyFU{LGXV5!56=Jq diff --git a/dsLightRag/Test/G2_TeachingStudent.py b/dsLightRag/Test/G2_TeachingStudent.py index 0a4f7c98..739f1f3b 100644 --- a/dsLightRag/Test/G2_TeachingStudent.py +++ b/dsLightRag/Test/G2_TeachingStudent.py @@ -1,18 +1,13 @@ from Config.GoApiConst import MODEL_GPT35, MODEL_GPT4 from Util.GoApiUtil import ModelInteractor +import sys -# 示例使用 -if __name__ == "__main__": - # 创建模型交互器实例 - interactor = ModelInteractor() - - # 使用不同的模型和提示词 - model_name = MODEL_GPT4 - - firstPrompt = """ +def initialize_chat_history(): + """初始化对话历史,包含系统提示""" + system_prompt = """ STRICT RULES Be an approachable-yet-dynamic teacher,who helps the user learn by guiding -them through their studies. + them through their studies. 1.Get to know the user.lf you don't know their goals or grade level,ask the user before diving in.(Keep this lightweight!)If they don't answer,aim for @@ -35,8 +30,62 @@ not alecture. Above all:DO NOT DO THE USER'S WORK FOR THEM. Don't answer homework questions - Help the user find the answer,by working with them collaboratively and building from what they already know. """ + return [{ + "role": "system", + "content": system_prompt + }] - prompt_text = firstPrompt + "下面是问题:讲解一下勾股定理的证明。" +# 示例使用 +if __name__ == "__main__": + # 创建模型交互器实例 + interactor = ModelInteractor() - # 发送流式请求 - interactor.stream_request(model_name, prompt_text) + # 使用不同的模型 + model_name = MODEL_GPT4 + print(f"使用模型: {model_name}") + + # 初始化对话历史 + chat_history = initialize_chat_history() + + # 第一轮问题(可选) + first_question = "讲解一下勾股定理的证明。" + print(f"\n初始问题: {first_question}") + chat_history.append({ + "role": "user", + "content": first_question + }) + + # 发送第一轮请求 + print("\n教师助手:") + response_content = interactor.stream_request(model_name, chat_history) + chat_history.append({ + "role": "assistant", + "content": response_content + }) + + # 多轮对话循环 + print("\n多轮对话已启动。输入 'exit' 或 '退出' 结束对话。") + while True: + # 获取用户输入 + user_input = input("\n你: ") + + # 检查是否退出 + if user_input.lower() in ['exit', '退出']: + print("对话已结束。") + sys.exit(0) + + # 添加用户输入到对话历史 + chat_history.append({ + "role": "user", + "content": user_input + }) + + # 发送请求 + print("\n教师助手:") + response_content = interactor.stream_request(model_name, chat_history) + + # 添加助手回复到对话历史 + chat_history.append({ + "role": "assistant", + "content": response_content + }) diff --git a/dsLightRag/Util/__pycache__/GoApiUtil.cpython-310.pyc b/dsLightRag/Util/__pycache__/GoApiUtil.cpython-310.pyc index f05247a5b448b0b6211fb59681e506c870a8b472..bc90e46d080f95f61d50a556568e9b0d8a5c9298 100644 GIT binary patch delta 20 acmaDR^h}65pO=@50SGj2E!xN(%?SWH(FIfh delta 20 acmaDR^h}65pO=@50SG31n75HTniBv%5(Uiw