♻️Refactor: 优化代码结构和调整提示词
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
+6
-13
@@ -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()
|
||||
|
||||
|
||||
@@ -2,22 +2,3 @@
|
||||
1. 结构清晰,重点突出
|
||||
2. 使用emoji图标增强可读性
|
||||
3. 每个部分简洁明了,方便记忆
|
||||
|
||||
输出格式:
|
||||
📌 核心概念:[精确的知识点定义,50字以内]
|
||||
|
||||
🔑 关键要点:
|
||||
- 要点1(具体说明,20字以内)
|
||||
- 要点2(具体说明,20字以内)
|
||||
- 要点3(具体说明,20字以内)
|
||||
- 要点4(具体说明,20字以内)
|
||||
|
||||
⚠️ 常见误区:
|
||||
- 误区1:[说明]
|
||||
- 误区2:[说明]
|
||||
|
||||
✅ 最佳实践:
|
||||
- 实践1:[具体建议]
|
||||
- 实践2:[具体建议]
|
||||
|
||||
🎯 记忆口诀:[朗朗上口的口诀,帮助记忆]
|
||||
|
||||
@@ -4,27 +4,3 @@
|
||||
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
|
||||
|
||||
|
||||
@@ -3,21 +3,3 @@
|
||||
2. 难度分布:5道基础题、5道中级题、5道进阶题
|
||||
3. 每道题都要提供详细的解析说明
|
||||
4. 选项之间要有明显的区别,避免模棱两可
|
||||
|
||||
严格按照JSON格式输出,禁止输出任何多余前缀。
|
||||
输出格式:
|
||||
{
|
||||
"questions": [
|
||||
{
|
||||
"question": "题目文字,准确描述问题",
|
||||
"options": [
|
||||
"A. 选项内容",
|
||||
"B. 选项内容",
|
||||
"C. 选项内容",
|
||||
"D. 选项内容"
|
||||
],
|
||||
"answer": "A",
|
||||
"explanation": "详细解析为什么选这个答案,以及为什么其他选项不对"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -4,36 +4,3 @@
|
||||
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": ["...", "..."]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user