feat: add Gin HTTP API with SSE streaming chat
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"eino-test/config"
|
||||
"eino-test/internal/rag"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type IndexHandler struct {
|
||||
pipeline *rag.RAGPipeline
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
func NewIndexHandler(pipeline *rag.RAGPipeline, cfg *config.Config) *IndexHandler {
|
||||
return &IndexHandler{pipeline: pipeline, cfg: cfg}
|
||||
}
|
||||
|
||||
func (h *IndexHandler) RebuildIndex(c *gin.Context) {
|
||||
if err := h.pipeline.IndexAllFromDir(c.Request.Context(), h.cfg.DataDir); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "index rebuilt"})
|
||||
}
|
||||
Reference in New Issue
Block a user