mirror of
https://github.com/alibaba/higress.git
synced 2026-02-06 23:21:08 +08:00
update ai-prompt-decorator to new plugin wrapper api (#2777)
This commit is contained in:
@@ -18,9 +18,9 @@ func main() {}
|
|||||||
func init() {
|
func init() {
|
||||||
wrapper.SetCtx(
|
wrapper.SetCtx(
|
||||||
"ai-prompt-decorator",
|
"ai-prompt-decorator",
|
||||||
wrapper.ParseConfigBy(parseConfig),
|
wrapper.ParseConfig(parseConfig),
|
||||||
wrapper.ProcessRequestHeadersBy(onHttpRequestHeaders),
|
wrapper.ProcessRequestHeaders(onHttpRequestHeaders),
|
||||||
wrapper.ProcessRequestBodyBy(onHttpRequestBody),
|
wrapper.ProcessRequestBody(onHttpRequestBody),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,11 +34,11 @@ type AIPromptDecoratorConfig struct {
|
|||||||
Append []Message `json:"append"`
|
Append []Message `json:"append"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConfig(jsonConfig gjson.Result, config *AIPromptDecoratorConfig, log log.Log) error {
|
func parseConfig(jsonConfig gjson.Result, config *AIPromptDecoratorConfig) error {
|
||||||
return json.Unmarshal([]byte(jsonConfig.Raw), config)
|
return json.Unmarshal([]byte(jsonConfig.Raw), config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config AIPromptDecoratorConfig, log log.Log) types.Action {
|
func onHttpRequestHeaders(ctx wrapper.HttpContext, config AIPromptDecoratorConfig) types.Action {
|
||||||
ctx.DisableReroute()
|
ctx.DisableReroute()
|
||||||
proxywasm.RemoveHttpRequestHeader("content-length")
|
proxywasm.RemoveHttpRequestHeader("content-length")
|
||||||
return types.ActionContinue
|
return types.ActionContinue
|
||||||
@@ -70,7 +70,7 @@ func decorateGeographicPrompt(entry *Message) (*Message, error) {
|
|||||||
return entry, nil
|
return entry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func onHttpRequestBody(ctx wrapper.HttpContext, config AIPromptDecoratorConfig, body []byte, log log.Log) types.Action {
|
func onHttpRequestBody(ctx wrapper.HttpContext, config AIPromptDecoratorConfig, body []byte) types.Action {
|
||||||
messageJson := `{"messages":[]}`
|
messageJson := `{"messages":[]}`
|
||||||
|
|
||||||
for _, entry := range config.Prepend {
|
for _, entry := range config.Prepend {
|
||||||
|
|||||||
Reference in New Issue
Block a user