Files
eino-test/internal/api/handler_index.go
T

28 lines
618 B
Go

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"})
}