✨Feat: 补充API接口
This commit is contained in:
@@ -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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
handle "agent/handlers"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@@ -50,6 +51,41 @@ func main() {
|
|||||||
"message": "pong",
|
"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()
|
route.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user