mirror of
https://github.com/coaidev/coai.git
synced 2025-05-20 13:30:13 +09:00
update search result length limit
This commit is contained in:
parent
f2726a06dc
commit
d26f97d71f
@ -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
|
||||
}
|
||||
|
@ -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": "",
|
||||
|
11
api/utils.go
11
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分析加入到你回答的末尾中,图片格式为 "+
|
||||
"当介绍github的仓库的时候,可以使用code stats分析加入到你回答的末尾中,图片格式为 "+
|
||||
"当前时间: %s, 实时联网搜索结果:%s",
|
||||
time.Now().Format("2006-01-02 15:04:05"), web.SearchBing(keyword),
|
||||
time.Now().Format("2006-01-02 15:04:05"), data,
|
||||
),
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user