✨Feat: 增添结构体解析函数
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package response_struct
|
||||
|
||||
type AllStruct struct {
|
||||
CardStruct Card `json:"card"`
|
||||
GuodegangStruct Guodegang `json:"guodegang"`
|
||||
MermaidStruct Mermaid `json:"mermaid"`
|
||||
QuizStruct Quiz `json:"quiz"`
|
||||
ScenarioStruct Scenario `json:"scenario"`
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package response_struct
|
||||
|
||||
// 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,6 @@
|
||||
package response_struct
|
||||
|
||||
type Guodegang struct {
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package response_struct
|
||||
|
||||
type Mermaid struct {
|
||||
Type string `json:"type"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package response_struct
|
||||
|
||||
type Quiz struct {
|
||||
Questions []Question `json:"questions"`
|
||||
}
|
||||
|
||||
type Question struct {
|
||||
Question string `json:"question"`
|
||||
Options []string `json:"options"`
|
||||
Answer string `json:"answer"`
|
||||
Explanation string `json:"explanation"`
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package response_struct
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func TestGuodegang(t *testing.T) {
|
||||
definedGuodegang, err := outputparser.NewDefined(Guodegang{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
output := definedGuodegang.GetFormatInstructions()
|
||||
t.Log(output)
|
||||
}
|
||||
|
||||
func TestMermaid(t *testing.T) {
|
||||
definedMermaid, err := outputparser.NewDefined(Mermaid{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
output := definedMermaid.GetFormatInstructions()
|
||||
t.Log(output)
|
||||
}
|
||||
|
||||
func TestQuiz(t *testing.T) {
|
||||
definedQuiz, err := outputparser.NewDefined(Quiz{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
output := definedQuiz.GetFormatInstructions()
|
||||
t.Log(output)
|
||||
}
|
||||
|
||||
func TestScenario(t *testing.T) {
|
||||
definedScenario, err := outputparser.NewDefined(Scenario{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
output := definedScenario.GetFormatInstructions()
|
||||
t.Log(output)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package response_struct
|
||||
|
||||
type ScenarioResponse struct {
|
||||
Scenarios []Scenario `json:"scenarios"`
|
||||
}
|
||||
|
||||
type Scenario struct {
|
||||
Name string `json:"name"`
|
||||
Background string `json:"background"`
|
||||
Solution string `json:"solution"`
|
||||
CodeExample string `json:"code_example"`
|
||||
CoreProblemSolved string `json:"core_problem_solved"`
|
||||
KeyConsiderations []string `json:"key_considerations"`
|
||||
}
|
||||
Reference in New Issue
Block a user