Compare commits

...
2 Commits
Author SHA1 Message Date
wonder c60140f1da ✅Test: 测试结构体解析器 2026-03-25 21:37:40 +08:00
wonder 0a5f30b328 ✨Feat: 定义card结构体 2026-03-25 21:36:49 +08:00
2 changed files with 84 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
package agent
// Card 是顶层结构体,包含所有关于 Go map 的笔记内容
type Card struct {
Summary string `json:"summary"`
KeyPoints KeyPoints `json:"key_points"`
CommonMisconceptions CommonMisconceptions `json:"common_misconceptions"`
BestPractices BestPractices `json:"best_practices"`
Mnemonic Mnemonic `json:"mnemonic"`
}
// KeyPoints 包含关键要点部分
type KeyPoints struct {
Header string `json:"header"`
Items []KeyPointItem `json:"items"`
}
// KeyPointItem 是关键要点的单个条目
type KeyPointItem struct {
Point string `json:"point"`
Description string `json:"description"`
}
// CommonMisconceptions 包含常见误区部分
type CommonMisconceptions struct {
Header string `json:"header"`
Items []MisconceptionItem `json:"items"`
}
// MisconceptionItem 是常见误区的单个条目
type MisconceptionItem struct {
ID string `json:"id"`
Title string `json:"title"`
Detail string `json:"detail"`
Fix string `json:"fix"`
}
// BestPractices 包含最佳实践部分
type BestPractices struct {
Header string `json:"header"`
Items []PracticeItem `json:"items"`
}
// PracticeItem 是最佳实践的单个条目
type PracticeItem struct {
ID string `json:"id"`
Title string `json:"title"`
Detail string `json:"detail"`
CorrectExample string `json:"correct_example,omitempty"` // 可能不存在于某些条目
IncorrectExample string `json:"incorrect_example,omitempty"` // 可能不存在于某些条目
}
// Mnemonic 包含记忆口诀部分
type Mnemonic struct {
Header string `json:"header"`
Content string `json:"content"`
}
// 使用示例:
// var card Card
// err := json.Unmarshal(data, &card)
// 或
// wrapper := struct {
// Card Card `json:"card"`
// }{}
// err := json.Unmarshal(data, &wrapper)
@@ -0,0 +1,18 @@
package agent
import (
"testing"
"github.com/tmc/langchaingo/outputparser"
)
func TestCard(t *testing.T) {
definedCard, err := outputparser.NewDefined(Card{})
if err != nil {
t.Fatalf("%v", err)
}
output := definedCard.GetFormatInstructions()
t.Log(output)
}