AI-search plugin supports controlling through the web_search_options parameter. (#1893)

This commit is contained in:
澄潭
2025-03-14 21:52:33 +08:00
committed by GitHub
parent 26bfdd45ff
commit 5e7e20ff7e
3 changed files with 51 additions and 1 deletions

View File

@@ -55,6 +55,7 @@ type Config struct {
defaultLanguage string
needReference bool
searchRewrite *SearchRewrite
defaultEnable bool
}
const (
@@ -86,6 +87,10 @@ func main() {
}
func parseConfig(json gjson.Result, config *Config, log wrapper.Log) error {
config.defaultEnable = true // Default to true if not specified
if json.Get("defaultEnable").Exists() {
config.defaultEnable = json.Get("defaultEnable").Bool()
}
config.needReference = json.Get("needReference").Bool()
if config.needReference {
config.referenceFormat = json.Get("referenceFormat").String()
@@ -254,6 +259,17 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, config Config, log wrapper.Lo
}
func onHttpRequestBody(ctx wrapper.HttpContext, config Config, body []byte, log wrapper.Log) types.Action {
// Check if plugin should be enabled based on config and request
if !config.defaultEnable {
// When defaultEnable is false, we need to check if web_search_options exists in the request
webSearchOptions := gjson.GetBytes(body, "web_search_options")
if !webSearchOptions.Exists() {
log.Debugf("Plugin disabled by config and no web_search_options in request")
return types.ActionContinue
}
log.Debugf("Plugin enabled by web_search_options in request")
}
var queryIndex int
var query string
messages := gjson.GetBytes(body, "messages").Array()