Havoc412 679d30dc7b feat(nlp): 重构 RAG 聊天模式并添加新功能
- 重构 RAG 聊天模式,支持知识、日记和检测等多种模式
- 新增日记和检测模式的实现
- 更新 API 接口和前端交互逻辑,支持新的聊天模式
- 优化 prompts.yml 文件结构,更好地支持不同模式的提示模板
2024-11-20 13:26:31 +08:00

35 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package rag
import (
"catface/app/global/consts"
"catface/app/http/controller/web"
"catface/app/http/validator/core/data_transfer"
"catface/app/utils/response"
"github.com/gin-gonic/gin"
)
// INFO 虽然起名为 Chat但是默认就会去查询 知识库,也就是不作为一般的 LLM-chat 来使用。
type Chat struct {
Query string `form:"query" json:"query" binding:"required"`
Token string `form:"token" json:"token"` // UPDATE 暂时不想启用 user 的 token就先单独处理。
Mode string `form:"mode" json:"mode"`
CatsId string `form:"cats_id" json:"cats_id"` // [日记 || 辨别] 模式下使用的参数。
}
func (c Chat) CheckParams(context *gin.Context) {
if err := context.ShouldBind(&c); err != nil {
response.ValidatorError(context, err)
return
}
extraAddBindDataContext := data_transfer.DataAddContext(c, consts.ValidatorPrefix, context)
if extraAddBindDataContext == nil {
response.ErrorSystem(context, "RAG CHAT 表单验证器json化失败", "")
} else {
(&web.Rag{}).ChatWebSocket(extraAddBindDataContext)
}
}