Files
langchain-go/backend/handlers/agent.go
T

91 lines
2.0 KiB
Go
Raw Normal View History

2026-03-23 13:44:45 +08:00
package handle
import (
"agent/agent"
2026-03-27 19:30:04 +08:00
"agent/response_struct"
2026-03-23 13:44:45 +08:00
"context"
2026-03-24 22:15:30 +08:00
"fmt"
"sync"
2026-03-23 13:44:45 +08:00
"github.com/tmc/langchaingo/llms"
)
var files = []string{
".\\prompt\\card.txt",
".\\prompt\\guodegang.txt",
".\\prompt\\mermaid.txt",
".\\prompt\\quiz.txt",
".\\prompt\\scenario.txt",
}
2026-03-27 19:30:04 +08:00
func GetCard(llm llms.Model, ctx context.Context, topic string) (response response_struct.Card) {
2026-03-23 13:44:45 +08:00
file := files[0]
2026-03-27 19:30:04 +08:00
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Card{})
2026-03-23 13:44:45 +08:00
return
}
2026-03-27 19:30:04 +08:00
func GetGuodegang(llm llms.Model, ctx context.Context, topic string) (response response_struct.Guodegang) {
2026-03-23 13:44:45 +08:00
file := files[1]
2026-03-27 19:30:04 +08:00
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Guodegang{})
2026-03-23 13:44:45 +08:00
return
}
2026-03-27 19:30:04 +08:00
func GetMermaid(llm llms.Model, ctx context.Context, topic string) (response response_struct.Mermaid) {
2026-03-23 13:44:45 +08:00
file := files[2]
2026-03-27 19:30:04 +08:00
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Mermaid{})
2026-03-23 13:44:45 +08:00
return
}
2026-03-27 19:30:04 +08:00
func GetQuiz(llm llms.Model, ctx context.Context, topic string) (response response_struct.Quiz) {
2026-03-23 13:44:45 +08:00
file := files[3]
2026-03-27 19:30:04 +08:00
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Quiz{})
2026-03-23 13:44:45 +08:00
return
}
2026-03-27 19:30:04 +08:00
func GetScenario(llm llms.Model, ctx context.Context, topic string) (response response_struct.Scenario) {
2026-03-23 13:44:45 +08:00
file := files[4]
2026-03-27 19:30:04 +08:00
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Scenario{})
2026-03-23 13:44:45 +08:00
return
}
2026-03-24 22:15:30 +08:00
2026-03-27 19:30:04 +08:00
func GetAll(llm llms.Model, ctx context.Context, topic string) (response *response_struct.AllStruct) {
2026-03-24 22:15:30 +08:00
var wg sync.WaitGroup
wg.Add(len(files))
go func() {
defer wg.Done()
2026-03-27 19:30:04 +08:00
response.CardStruct = GetCard(llm, ctx, topic)
2026-03-24 22:15:30 +08:00
}()
go func() {
defer wg.Done()
2026-03-27 19:30:04 +08:00
response.GuodegangStruct = GetGuodegang(llm, ctx, topic)
2026-03-24 22:15:30 +08:00
}()
go func() {
defer wg.Done()
2026-03-27 19:30:04 +08:00
response.MermaidStruct = GetMermaid(llm, ctx, topic)
2026-03-24 22:15:30 +08:00
}()
go func() {
defer wg.Done()
2026-03-27 19:30:04 +08:00
response.QuizStruct = GetQuiz(llm, ctx, topic)
2026-03-24 22:15:30 +08:00
}()
go func() {
defer wg.Done()
2026-03-27 19:30:04 +08:00
response.ScenarioStruct = GetScenario(llm, ctx, topic)
2026-03-24 22:15:30 +08:00
}()
wg.Wait()
2026-03-27 19:30:04 +08:00
2026-03-24 22:15:30 +08:00
fmt.Println("======== All responses received ========")
return response
}