update search result length limit

This commit is contained in:
Zhang Minghan 2023-08-12 17:33:22 +08:00
parent f2726a06dc
commit d26f97d71f
3 changed files with 11 additions and 4 deletions

View File

@ -39,7 +39,7 @@ func GetChatGPTResponse(message []types.ChatGPTMessage, token int) (string, erro
}
func GetAnonymousResponse(message string) (string, string, error) {
keyword, source := ChatWithWeb([]types.ChatGPTMessage{{Role: "user", Content: message}})
keyword, source := ChatWithWeb([]types.ChatGPTMessage{{Role: "user", Content: message}}, false)
resp, err := GetChatGPTResponse(source, 1000)
return keyword, resp, err
}

View File

@ -63,7 +63,7 @@ func ChatAPI(c *gin.Context) {
return
}
if _, err := instance.AddMessageFromUserForm(message); err == nil {
keyword, segment := ChatWithWeb(instance.GetMessageSegment(12))
keyword, segment := ChatWithWeb(instance.GetMessageSegment(12), true)
_ = conn.WriteMessage(websocket.TextMessage, []byte(utils.ToJson(map[string]interface{}{
"keyword": keyword,
"message": "",

View File

@ -10,12 +10,19 @@ import (
"time"
)
func ChatWithWeb(message []types.ChatGPTMessage) (string, []types.ChatGPTMessage) {
func ChatWithWeb(message []types.ChatGPTMessage, long bool) (string, []types.ChatGPTMessage) {
keyword := strings.TrimSpace(SearchWeb(message))
if len(keyword) == 0 {
return keyword, message
}
data := web.SearchBing(keyword)
if long {
data = data[:6000]
} else {
data = data[:3000]
}
return keyword, utils.Insert(message, 0, types.ChatGPTMessage{
Role: "system",
Content: fmt.Sprintf("你将扮演AI问答助手你的知识库不是截止于2021年9月而是可以实时联网的你可以提供实时联网的知识库。"+
@ -23,7 +30,7 @@ func ChatWithWeb(message []types.ChatGPTMessage) (string, []types.ChatGPTMessage
"当介绍github的用户的时候可以使用code stats分析加入到你回答的末尾中图片格式为 ![User Stats](https://stats.deeptrain.net/user/{username})"+
"当介绍github的仓库的时候可以使用code stats分析加入到你回答的末尾中图片格式为 ![Repo Stats](https://stats.deeptrain.net/repo/{username}/{repo})"+
"当前时间: %s, 实时联网搜索结果:%s",
time.Now().Format("2006-01-02 15:04:05"), web.SearchBing(keyword),
time.Now().Format("2006-01-02 15:04:05"), data,
),
})
}