mirror of
https://github.com/alibaba/higress.git
synced 2026-05-25 05:07:26 +08:00
feat(model-mapper): sync model header on remap and disable reroute (#3827)
Signed-off-by: 钰诚 <yucheng.lxr@alibaba-inc.com>
This commit is contained in:
@@ -42,6 +42,7 @@ type Config struct {
|
||||
prefixModelMapping []ModelMapping
|
||||
defaultModel string
|
||||
enableOnPathSuffix []string
|
||||
modelToHeader string
|
||||
}
|
||||
|
||||
func parseConfig(json gjson.Result, config *Config) error {
|
||||
@@ -50,6 +51,11 @@ func parseConfig(json gjson.Result, config *Config) error {
|
||||
config.modelKey = "model"
|
||||
}
|
||||
|
||||
config.modelToHeader = json.Get("modelToHeader").String()
|
||||
if config.modelToHeader == "" {
|
||||
config.modelToHeader = "x-higress-llm-model-final"
|
||||
}
|
||||
|
||||
modelMapping := json.Get("modelMapping")
|
||||
if modelMapping.Exists() && !modelMapping.IsObject() {
|
||||
return errors.New("modelMapping must be an object")
|
||||
@@ -144,6 +150,8 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, config Config) types.Action {
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
// Disable re-route since the plugin may modify some headers related to the chosen route.
|
||||
ctx.DisableReroute()
|
||||
// Prepare for body processing
|
||||
proxywasm.RemoveHttpRequestHeader("content-length")
|
||||
// 100MB buffer limit
|
||||
@@ -182,6 +190,9 @@ func onHttpRequestBody(ctx wrapper.HttpContext, config Config, body []byte) type
|
||||
}
|
||||
}
|
||||
|
||||
// update x-higress-llm-model-final header
|
||||
proxywasm.ReplaceHttpRequestHeader(config.modelToHeader, newModel)
|
||||
log.Debugf("set header %s: %s", config.modelToHeader, newModel)
|
||||
if newModel != "" && newModel != oldModel {
|
||||
newBody, err := sjson.SetBytes(body, config.modelKey, newModel)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user