diff --git a/api/anonymous.go b/api/anonymous.go index d28d951..caf03e2 100644 --- a/api/anonymous.go +++ b/api/anonymous.go @@ -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 } diff --git a/api/chat.go b/api/chat.go index c80ac53..1832302 100644 --- a/api/chat.go +++ b/api/chat.go @@ -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": "", diff --git a/api/utils.go b/api/utils.go index c675024..2de4d40 100644 --- a/api/utils.go +++ b/api/utils.go @@ -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, ), }) }