浏览代码

新增AI记忆能力

tuoling805 1 年之前
父节点
当前提交
9d692a10b8
共有 3 个文件被更改,包括 28 次插入2 次删除
  1. 18 1
      controllers/ai/ai.go
  2. 5 0
      models/aimod/ai.go
  3. 5 1
      services/aiser/ai.go

+ 18 - 1
controllers/ai/ai.go

@@ -85,7 +85,24 @@ func (this *AiController) List() {
 	if chatMode != nil && chatMode.Answer != "" {
 		answer = chatMode.Answer
 	} else {
-		answer, err = aiser.ChatAutoMsg(req.Ask)
+		//获取主题下的所有信息
+		//AiChatTopicId
+		historyList, err := aimod.GetAiChatList(req.AiChatTopicId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取主题历史数据失败!"
+			br.ErrMsg = "获取主题历史数据失败,Err:" + err.Error()
+			return
+		}
+
+		historyChatList := make([]aimod.HistoryChat, 0)
+		for _, v := range historyList {
+			historyChat := new(aimod.HistoryChat)
+			historyChat.Ask = v.Ask
+			historyChat.Answer = v.Answer
+			historyChatList = append(historyChatList, *historyChat)
+		}
+
+		answer, err = aiser.ChatAutoMsg(req.Ask, historyChatList)
 		if err != nil {
 			br.Msg = "获取数据失败!"
 			br.ErrMsg = "获取数据失败,ChatAutoMsg,Err:" + err.Error()

+ 5 - 0
models/aimod/ai.go

@@ -144,3 +144,8 @@ func EditTopic(topicId int, topicName string) (err error) {
 	_, err = o.Raw(sql, topicName, topicId).Exec()
 	return err
 }
+
+type HistoryChat struct {
+	Ask    string
+	Answer string
+}

+ 5 - 1
services/aiser/ai.go

@@ -3,6 +3,7 @@ package aiser
 import (
 	"encoding/json"
 	"errors"
+	"eta/eta_api/models/aimod"
 	"eta/eta_api/utils"
 	"io/ioutil"
 	"net/http"
@@ -10,12 +11,15 @@ import (
 	"time"
 )
 
-func ChatAutoMsg(prompt string) (result string, err error) {
+func ChatAutoMsg(prompt string, historyChatList []aimod.HistoryChat) (result string, err error) {
 	chatUrl := utils.EtaAiUrl + `chat/auto_msg`
 
 	param := make(map[string]interface{})
 	param["Prompt"] = prompt
+	param["HistoryChatList"] = historyChatList
+
 	postData, err := json.Marshal(param)
+
 	if err != nil {
 		return result, err
 	}