diff --git a/handle/handle.go b/handle/handle.go deleted file mode 100644 index 45b37a8..0000000 --- a/handle/handle.go +++ /dev/null @@ -1,22 +0,0 @@ -package handle - -import "agent/agent" - -var files = []string{ - ".\\prompt\\card.txt", - ".\\prompt\\guodegang.txt", - ".\\prompt\\mermaid.txt", - ".\\prompt\\quiz.txt", - ".\\prompt\\scenario.txt", -} - -func handle() { - - for _, file := range files { - go func(f string) { - - agent.CallWithAgent(llm, ctx, "文件", f) - }(file) - } - -} diff --git a/handlers/agent.go b/handlers/agent.go new file mode 100644 index 0000000..b9ccfef --- /dev/null +++ b/handlers/agent.go @@ -0,0 +1,46 @@ +package handle + +import ( + "agent/agent" + "context" + + "github.com/tmc/langchaingo/llms" +) + +var files = []string{ + ".\\prompt\\card.txt", + ".\\prompt\\guodegang.txt", + ".\\prompt\\mermaid.txt", + ".\\prompt\\quiz.txt", + ".\\prompt\\scenario.txt", +} + +func GetCard(llm llms.Model, ctx context.Context, topic string) (response string) { + file := files[0] + response = agent.CallWithAgent(llm, ctx, topic, file) + return +} + +func GetGuodegang(llm llms.Model, ctx context.Context, topic string) (response string) { + file := files[1] + response = agent.CallWithAgent(llm, ctx, topic, file) + return +} + +func GetMermaid(llm llms.Model, ctx context.Context, topic string) (response string) { + file := files[2] + response = agent.CallWithAgent(llm, ctx, topic, file) + return +} + +func GetQuiz(llm llms.Model, ctx context.Context, topic string) (response string) { + file := files[3] + response = agent.CallWithAgent(llm, ctx, topic, file) + return +} + +func GetScenario(llm llms.Model, ctx context.Context, topic string) (response string) { + file := files[4] + response = agent.CallWithAgent(llm, ctx, topic, file) + return +} diff --git a/main.go b/main.go index 608e5bc..d5f2cf2 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + handle "agent/handlers" "context" "fmt" "log" @@ -50,6 +51,41 @@ func main() { "message": "pong", }) }) + route.GET("/agent/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) { + 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) { + 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) { + 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) { + topic := c.Param("topic") + message := handle.GetScenario(llm, ctx, topic) + c.JSON(200, gin.H{ + "message": message, + }) + }) route.Run() }