UPDATE: Chatbot module
All checks were successful
Build and Release / release (push) Successful in 2m13s

This commit is contained in:
2026-05-05 00:09:55 +07:00
parent 1998cf2ec0
commit a8f0597e59
33 changed files with 1042 additions and 65 deletions

View File

@@ -0,0 +1,60 @@
package controllers
import (
"context"
"history-api/internal/dtos/request"
"history-api/internal/dtos/response"
"history-api/internal/services"
"history-api/pkg/validator"
"time"
"github.com/gofiber/fiber/v3"
)
type ChatbotController struct {
chatbotService services.ChatbotService
}
func NewChatbotController(chatbotService services.ChatbotService) *ChatbotController {
return &ChatbotController{
chatbotService: chatbotService,
}
}
// Chat godoc
// @Summary Ask the AI chatbot
// @Description Ask a history question based on project context or global knowledge using RAG
// @Tags Chatbot
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param request body request.ChatbotDto true "Chatbot query"
// @Success 200 {object} response.CommonResponse{data=string} "Successful response with AI answer"
// @Failure 400 {object} response.CommonResponse "Invalid request"
// @Failure 500 {object} response.CommonResponse "Internal server error"
// @Router /chatbot/chat [post]
func (cx *ChatbotController) Chat(c fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dto := &request.ChatbotDto{}
if err := validator.ValidateBodyDto(c, dto); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(response.CommonResponse{
Status: false,
Errors: err,
})
}
answer, err := cx.chatbotService.Chat(ctx, dto.ProjectID, dto.Question)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
Status: false,
Message: err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
Status: true,
Data: answer,
})
}