mirror of
https://github.com/coaidev/coai.git
synced 2025-05-20 05:20:15 +09:00
update web searching feature
This commit is contained in:
parent
f7f467772c
commit
d6c1f3d4a7
14
api/utils.go
14
api/utils.go
@ -29,10 +29,10 @@ func GetRandomKey(apikey string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func StringCleaner(content string) string {
|
func StringCleaner(content string) string {
|
||||||
for _, replacer := range []string{",", "、", ",", "。", ":", ":", ";", ";", "!", "!", "?", "?", "(", ")", "(", ")"} {
|
for _, replacer := range []string{",", "、", ",", "。", ":", ":", ";", ";", "!", "!", "?", "?", "(", ")", "(", ")", "关键字"} {
|
||||||
content = strings.ReplaceAll(content, replacer, " ")
|
content = strings.ReplaceAll(content, replacer, " ")
|
||||||
}
|
}
|
||||||
return content
|
return strings.TrimSpace(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SearchWeb(message []types.ChatGPTMessage) string {
|
func SearchWeb(message []types.ChatGPTMessage) string {
|
||||||
@ -46,14 +46,12 @@ func SearchWeb(message []types.ChatGPTMessage) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
source = utils.GetLatestSegment(source, 3)
|
||||||
keyword, _ := GetChatGPTResponse([]types.ChatGPTMessage{{
|
keyword, _ := GetChatGPTResponse([]types.ChatGPTMessage{{
|
||||||
Role: "system",
|
|
||||||
Content: "在接下来的对话中,不要回答问题,你需要总结接下来的对话中出现的内容," +
|
|
||||||
"然后用关键字和空格分词,输出精简,请不要输出冗余内容," +
|
|
||||||
"不能出现逗号顿号等特殊字符,仅回答出现的关键词。",
|
|
||||||
}, {
|
|
||||||
Role: "user",
|
Role: "user",
|
||||||
Content: strings.Join(source, " "),
|
Content: fmt.Sprintf("你是一个AI助手,我将你用来总结用户输入的内容并输出到bing搜索引擎上,"+
|
||||||
|
"请总结关键字,不要输出其他内容,不能输出特殊字符:\n%s", strings.Join(source, " ")),
|
||||||
}}, 40)
|
}}, 40)
|
||||||
|
|
||||||
return StringCleaner(keyword)
|
return StringCleaner(keyword)
|
||||||
}
|
}
|
||||||
|
@ -64,3 +64,10 @@ func UnmarshalJson[T any](value string) T {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetLatestSegment[T any](arr []T, length int) []T {
|
||||||
|
if length > len(arr) {
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
return arr[len(arr)-length:]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user