✨Feat: 增添结构体解析函数

This commit is contained in:
hhs
2026-03-27 19:30:04 +08:00
parent 4b9670967f
commit 18040d00c4
11 changed files with 179 additions and 37 deletions
+19 -17
View File
@@ -2,6 +2,7 @@ package handle
import (
"agent/agent"
"agent/response_struct"
"context"
"fmt"
@@ -18,38 +19,38 @@ var files = []string{
".\\prompt\\scenario.txt",
}
func GetCard(llm llms.Model, ctx context.Context, topic string) (response string) {
func GetCard(llm llms.Model, ctx context.Context, topic string) (response response_struct.Card) {
file := files[0]
response = agent.CallWithAgent(llm, ctx, topic, file)
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Card{})
return
}
func GetGuodegang(llm llms.Model, ctx context.Context, topic string) (response string) {
func GetGuodegang(llm llms.Model, ctx context.Context, topic string) (response response_struct.Guodegang) {
file := files[1]
response = agent.CallWithAgent(llm, ctx, topic, file)
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Guodegang{})
return
}
func GetMermaid(llm llms.Model, ctx context.Context, topic string) (response string) {
func GetMermaid(llm llms.Model, ctx context.Context, topic string) (response response_struct.Mermaid) {
file := files[2]
response = agent.CallWithAgent(llm, ctx, topic, file)
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Mermaid{})
return
}
func GetQuiz(llm llms.Model, ctx context.Context, topic string) (response string) {
func GetQuiz(llm llms.Model, ctx context.Context, topic string) (response response_struct.Quiz) {
file := files[3]
response = agent.CallWithAgent(llm, ctx, topic, file)
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Quiz{})
return
}
func GetScenario(llm llms.Model, ctx context.Context, topic string) (response string) {
func GetScenario(llm llms.Model, ctx context.Context, topic string) (response response_struct.Scenario) {
file := files[4]
response = agent.CallWithAgent(llm, ctx, topic, file)
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Scenario{})
return
}
func GetAll(llm llms.Model, ctx context.Context, topic string) (response map[string]string) {
response = make(map[string]string)
func GetAll(llm llms.Model, ctx context.Context, topic string) (response *response_struct.AllStruct) {
var wg sync.WaitGroup
@@ -57,30 +58,31 @@ func GetAll(llm llms.Model, ctx context.Context, topic string) (response map[str
go func() {
defer wg.Done()
response["card"] = GetCard(llm, ctx, topic)
response.CardStruct = GetCard(llm, ctx, topic)
}()
go func() {
defer wg.Done()
response["guodegang"] = GetGuodegang(llm, ctx, topic)
response.GuodegangStruct = GetGuodegang(llm, ctx, topic)
}()
go func() {
defer wg.Done()
response["mermaid"] = GetMermaid(llm, ctx, topic)
response.MermaidStruct = GetMermaid(llm, ctx, topic)
}()
go func() {
defer wg.Done()
response["quiz"] = GetQuiz(llm, ctx, topic)
response.QuizStruct = GetQuiz(llm, ctx, topic)
}()
go func() {
defer wg.Done()
response["scenario"] = GetScenario(llm, ctx, topic)
response.ScenarioStruct = GetScenario(llm, ctx, topic)
}()
wg.Wait()
fmt.Println("======== All responses received ========")