feat: add Gin HTTP API with SSE streaming chat
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"eino-test/config"
|
||||
"eino-test/internal/rag"
|
||||
|
||||
"github.com/cloudwego/eino/adk"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func NewRouter(cfg *config.Config, pipeline *rag.RAGPipeline, supervisor adk.Agent) *gin.Engine {
|
||||
r := gin.Default()
|
||||
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"*"},
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
||||
AllowCredentials: true,
|
||||
}))
|
||||
|
||||
chatHandler := NewChatHandler(supervisor)
|
||||
noteHandler := NewNoteHandler(pipeline)
|
||||
indexHandler := NewIndexHandler(pipeline, cfg)
|
||||
|
||||
api := r.Group("/api")
|
||||
{
|
||||
api.POST("/chat", chatHandler.Chat)
|
||||
api.GET("/notes", noteHandler.ListNotes)
|
||||
api.GET("/notes/:id", noteHandler.GetNote)
|
||||
api.POST("/notes", noteHandler.CreateNote)
|
||||
api.DELETE("/notes/:id", noteHandler.DeleteNote)
|
||||
api.POST("/index", indexHandler.RebuildIndex)
|
||||
}
|
||||
|
||||
r.Static("/static", "./web/dist")
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.File("./web/dist/index.html")
|
||||
})
|
||||
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user