|
@@ -3,6 +3,7 @@ package model
|
|
|
import (
|
|
|
"aiChat/internal/consts"
|
|
|
"aiChat/utility"
|
|
|
+ "aiChat/utility/fsw"
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
@@ -35,6 +36,23 @@ type QuestionReq struct {
|
|
|
Href string `json:"href"` //咨询页面
|
|
|
}
|
|
|
|
|
|
+// ParseHistoryFsw 过滤历史记录敏感词
|
|
|
+func (r *BaseQuestion) ParseHistoryFsw() {
|
|
|
+ var newHistory [][]string
|
|
|
+ for _, h := range r.History {
|
|
|
+ var pass bool = true
|
|
|
+ for _, v := range h {
|
|
|
+ if fsw.Match(v) {
|
|
|
+ pass = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if pass {
|
|
|
+ newHistory = append(newHistory, h)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ r.History = newHistory
|
|
|
+}
|
|
|
+
|
|
|
// GetUsuallyProblem 获取常见问题
|
|
|
func (q *cQuestion) GetUsuallyProblem(ctx context.Context, scenario, limit int) (list []string, err error) {
|
|
|
list = make([]string, 0, limit)
|
|
@@ -77,6 +95,7 @@ func (q *cQuestion) getIsbusinessData(ctx context.Context, code string) (bRes *B
|
|
|
|
|
|
// DetailQuestion 问题处理
|
|
|
func (q *cQuestion) DetailQuestion(ctx context.Context, qRes *QuestionReq) (reply string, from int, err error) {
|
|
|
+ qRes.ParseHistoryFsw()
|
|
|
// 语义服务
|
|
|
sRes, err := ChatGpt.SimpleDo(ctx, qRes)
|
|
|
if err != nil {
|
|
@@ -93,7 +112,7 @@ func (q *cQuestion) DetailQuestion(ctx context.Context, qRes *QuestionReq) (repl
|
|
|
// 校验是否有业务逻辑
|
|
|
matchArr := regExpSmart.FindStringSubmatch(cRes.Response)
|
|
|
if len(matchArr) == 0 {
|
|
|
- return cRes.Response, Answer_ChatGPT, nil
|
|
|
+ return fsw.Repl(cRes.Response), Answer_ChatGPT, nil
|
|
|
}
|
|
|
// 查询业务逻辑
|
|
|
var bRes = &BusinessRes{}
|