From afc7fee56bd461f90d07c3bb7398617915801ae0 Mon Sep 17 00:00:00 2001 From: wonder Date: Fri, 27 Mar 2026 19:48:22 +0800 Subject: [PATCH] =?UTF-8?q?=20=E2=99=BB=EF=B8=8FRefactor:=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=E5=92=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=8F=90=E7=A4=BA=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/handlers/agent.go | 43 ------------------------------------- backend/main.go | 19 ++++++---------- backend/prompt/card.txt | 21 +----------------- backend/prompt/mermaid.txt | 26 +--------------------- backend/prompt/quiz.txt | 20 +---------------- backend/prompt/scenario.txt | 35 +----------------------------- 6 files changed, 10 insertions(+), 154 deletions(-) diff --git a/backend/handlers/agent.go b/backend/handlers/agent.go index ef9900f..ba236b4 100644 --- a/backend/handlers/agent.go +++ b/backend/handlers/agent.go @@ -4,9 +4,6 @@ import ( "agent/agent" "agent/response_struct" "context" - "fmt" - - "sync" "github.com/tmc/langchaingo/llms" ) @@ -48,43 +45,3 @@ func GetScenario(llm llms.Model, ctx context.Context, topic string) (response re response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Scenario{}) return } - - -func GetAll(llm llms.Model, ctx context.Context, topic string) (response *response_struct.AllStruct) { - - var wg sync.WaitGroup - - wg.Add(len(files)) - - go func() { - defer wg.Done() - response.CardStruct = GetCard(llm, ctx, topic) - }() - - go func() { - defer wg.Done() - response.GuodegangStruct = GetGuodegang(llm, ctx, topic) - }() - - go func() { - defer wg.Done() - response.MermaidStruct = GetMermaid(llm, ctx, topic) - }() - - go func() { - defer wg.Done() - response.QuizStruct = GetQuiz(llm, ctx, topic) - }() - - go func() { - defer wg.Done() - response.ScenarioStruct = GetScenario(llm, ctx, topic) - }() - - wg.Wait() - - - fmt.Println("======== All responses received ========") - - return response -} diff --git a/backend/main.go b/backend/main.go index aeaa867..09efedc 100644 --- a/backend/main.go +++ b/backend/main.go @@ -19,7 +19,7 @@ import ( var ( apiKey string baseUrl string - model = "Pro/zai-org/GLM-4.7" + model = "stepfun-ai/Step-3.5-Flash" ctx context.Context llm llms.Model ) @@ -55,48 +55,41 @@ func main() { "message": "pong", }) }) - route.GET("/agent/card/:topic", func(c *gin.Context) { + route.GET("/card/:topic", func(c *gin.Context) { topic := c.Param("topic") message := handle.GetCard(llm, ctx, topic) c.JSON(200, gin.H{ "message": message, }) }) - route.GET("/agent/guodegang/:topic", func(c *gin.Context) { + route.GET("/guodegang/:topic", func(c *gin.Context) { topic := c.Param("topic") message := handle.GetGuodegang(llm, ctx, topic) c.JSON(200, gin.H{ "message": message, }) }) - route.GET("/agent/mermaid/:topic", func(c *gin.Context) { + route.GET("/mermaid/:topic", func(c *gin.Context) { topic := c.Param("topic") message := handle.GetMermaid(llm, ctx, topic) c.JSON(200, gin.H{ "message": message, }) }) - route.GET("/agent/quiz/:topic", func(c *gin.Context) { + route.GET("/quiz/:topic", func(c *gin.Context) { topic := c.Param("topic") message := handle.GetQuiz(llm, ctx, topic) c.JSON(200, gin.H{ "message": message, }) }) - route.GET("/agent/scenario/:topic", func(c *gin.Context) { + route.GET("/scenario/:topic", func(c *gin.Context) { topic := c.Param("topic") message := handle.GetScenario(llm, ctx, topic) c.JSON(200, gin.H{ "message": message, }) }) - route.GET("/agent/all/:topic", func(c *gin.Context) { - topic := c.Param("topic") - message := handle.GetAll(llm, ctx, topic) - c.JSON(200, gin.H{ - "message": message, - }) - }) route.Run() diff --git a/backend/prompt/card.txt b/backend/prompt/card.txt index 30bce65..45ec60a 100644 --- a/backend/prompt/card.txt +++ b/backend/prompt/card.txt @@ -1,23 +1,4 @@ 为"{{.Knowledge}}"制作知识记忆卡片,帮助用户快速掌握关键知识点,要求: 1. 结构清晰,重点突出 2. 使用emoji图标增强可读性 -3. 每个部分简洁明了,方便记忆 - -输出格式: -📌 核心概念:[精确的知识点定义,50字以内] - -🔑 关键要点: - - 要点1(具体说明,20字以内) - - 要点2(具体说明,20字以内) - - 要点3(具体说明,20字以内) - - 要点4(具体说明,20字以内) - -⚠️ 常见误区: - - 误区1:[说明] - - 误区2:[说明] - -✅ 最佳实践: - - 实践1:[具体建议] - - 实践2:[具体建议] - -🎯 记忆口诀:[朗朗上口的口诀,帮助记忆] +3. 每个部分简洁明了,方便记忆 \ No newline at end of file diff --git a/backend/prompt/mermaid.txt b/backend/prompt/mermaid.txt index 01657d2..680b9e5 100644 --- a/backend/prompt/mermaid.txt +++ b/backend/prompt/mermaid.txt @@ -3,28 +3,4 @@ 2. 严格缩进与换行:使用2个空格缩进,每条关系语句独立成行。 3. 括号与引号成对:所有()、[]、<>、""必须严格配对,无多余空格。 4. 箭头方向明确:使用标准箭头 -->、---、-.-> 等,禁止使用 ->(不完整)或 =>(错误)。 -5. 避免中文直接嵌入:若需中文,确保用双引号包裹(如 A["开始"]),或建议用户使用英文标签。 - -严格按照Mermaid格式输出,禁止输出任何多余前缀。 -输出格式: - -graph TD - Knowledge[Knowledge] - Definition["定义"] - Type["类型"] - Application["应用"] - ML["机器学习"] - DL["深度学习"] - Supervised["监督学习"] - Unsupervised["无监督学习"] - CV["计算机视觉"] - NLP["自然语言处理"] - Knowledge --> Definition - Knowledge --> Type - Knowledge --> Application - Type --> ML - Type --> DL - ML --> Supervised - ML --> Unsupervised - Application --> CV - +5. 避免中文直接嵌入:若需中文,确保用双引号包裹(如 A["开始"]),或建议用户使用英文标签。 \ No newline at end of file diff --git a/backend/prompt/quiz.txt b/backend/prompt/quiz.txt index 71b9aa1..e154d46 100644 --- a/backend/prompt/quiz.txt +++ b/backend/prompt/quiz.txt @@ -2,22 +2,4 @@ 1. 题目类型包括:概念理解、原理分析、应用场景、最佳实践等 2. 难度分布:5道基础题、5道中级题、5道进阶题 3. 每道题都要提供详细的解析说明 -4. 选项之间要有明显的区别,避免模棱两可 - -严格按照JSON格式输出,禁止输出任何多余前缀。 -输出格式: -{ - "questions": [ - { - "question": "题目文字,准确描述问题", - "options": [ - "A. 选项内容", - "B. 选项内容", - "C. 选项内容", - "D. 选项内容" - ], - "answer": "A", - "explanation": "详细解析为什么选这个答案,以及为什么其他选项不对" - } - ] -} +4. 选项之间要有明显的区别,避免模棱两可 \ No newline at end of file diff --git a/backend/prompt/scenario.txt b/backend/prompt/scenario.txt index 487d258..ff76591 100644 --- a/backend/prompt/scenario.txt +++ b/backend/prompt/scenario.txt @@ -3,37 +3,4 @@ 2. 包含完整的问题背景、解决方案、代码示例 3. 代码使用伪代码或简化的实现,注重逻辑清晰 4. 说明使用该知识点解决了什么核心问题 -5. 强调注意事项和最佳实践 - -严格按照JSON格式输出,禁止输出任何多余前缀。 -输出格式: -[ - { - "name": "场景名称(例如:高并发缓存更新)", - "background": "描述实际业务场景和遇到的问题(例如:电商秒杀场景下,库存缓存频繁失效导致数据库压力骤增)", - "solution": "分步骤说明如何使用{{.Knowledge}}解决问题(例如:1. 采用缓存旁路策略;2. 使用分布式锁保证原子性;3. 异步更新缓存)", - "codeExample": "使用伪代码或简化代码展示实现方式(例如:\nfunction updateStock(productId) {\n lock = acquireLock(productId);\n if (lock) {\n dbStock = queryDb(productId);\n cache.set(productId, dbStock);\n releaseLock(lock);\n }\n}", - "coreProblemSolved": "说明使用该知识点解决了什么核心问题(例如:解决了高并发下缓存与数据库一致性,避免缓存击穿)", - "keyConsiderations": [ - "关键点1(例如:锁粒度要细,避免性能瓶颈)", - "关键点2(例如:需设置缓存过期时间作为兜底)", - "关键点3(例如:监控缓存命中率,及时调整策略)" - ] - }, - { - "name": "场景2名称", - "background": "...", - "solution": "...", - "codeExample": "...", - "coreProblemSolved": "...", - "keyConsiderations": ["...", "..."] - }, - { - "name": "场景3名称", - "background": "...", - "solution": "...", - "codeExample": "...", - "coreProblemSolved": "...", - "keyConsiderations": ["...", "..."] - } -] \ No newline at end of file +5. 强调注意事项和最佳实践 \ No newline at end of file