feat: add Gin HTTP API with SSE streaming chat

This commit is contained in:
2026-05-05 11:37:19 +08:00
parent a25de092b1
commit 6bbe013170
8 changed files with 377 additions and 10 deletions
+42
View File
@@ -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
}