Files
ai-agent/internal/controllers/dashboard/knowledge_retrieve_controller.go
T
mlogclub 62416baabc Refactor API endpoints to use /api/dashboard instead of /api/console
- Updated all relevant API functions in agent.ts, company.ts, customer-contact.ts, customer.ts, dashboard.ts, ticket-config.ts, and ticket.ts to point to the new /api/dashboard paths.
- Ensured that all request methods and payload structures remain unchanged to maintain existing functionality.
2026-04-15 17:12:30 +08:00

86 lines
2.3 KiB
Go

package dashboard
import (
"context"
"cs-agent/internal/ai/rag"
"cs-agent/internal/pkg/constants"
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type KnowledgeRetrieveController struct {
Ctx iris.Context
}
func (c *KnowledgeRetrieveController) PostDebugSearch() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionKnowledgeDocumentView); err != nil {
return web.JsonError(err)
}
req := request.KnowledgeSearchRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
resp, err := rag.Answer.DebugSearch(context.Background(), req)
if err != nil {
return web.JsonError(err)
}
return web.JsonData(resp)
}
func (c *KnowledgeRetrieveController) PostDebugAnswer() *web.JsonResult {
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionKnowledgeDocumentView)
if err != nil {
return web.JsonError(err)
}
req := request.KnowledgeAnswerRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
resp, err := rag.Answer.DebugAnswer(context.Background(), req, operator)
if err != nil {
return web.JsonError(err)
}
return web.JsonData(resp)
}
func (c *KnowledgeRetrieveController) PostBuild() *web.JsonResult {
req := struct {
DocumentID int64 `json:"documentId"`
FAQID int64 `json:"faqId"`
}{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
if req.DocumentID > 0 {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionKnowledgeDocumentUpdate); err != nil {
return web.JsonError(err)
}
if err := rag.Answer.BuildDocumentIndex(context.Background(), req.DocumentID); err != nil {
return web.JsonError(err)
}
return web.JsonSuccess()
}
if req.FAQID > 0 {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionKnowledgeFAQUpdate); err != nil {
return web.JsonError(err)
}
if err := rag.Index.IndexFAQByID(context.Background(), req.FAQID); err != nil {
return web.JsonError(err)
}
return web.JsonSuccess()
}
return web.JsonErrorMsg("documentId或faqId不能为空")
}