mirror of
https://github.com/alibaba/higress.git
synced 2026-05-26 13:47:27 +08:00
feat(provider): 优化 Azure multipart 处理 || feat(provider): Optimize Azure multipart processing (#3651)
This commit is contained in:
@@ -1264,6 +1264,10 @@ func (c *ProviderConfig) handleRequestHeaders(provider Provider, ctx wrapper.Htt
|
||||
|
||||
// defaultTransformRequestBody 默认的请求体转换方法,只做模型映射,用slog替换模型名称,不用序列化和反序列化,提高性能
|
||||
func (c *ProviderConfig) defaultTransformRequestBody(ctx wrapper.HttpContext, apiName ApiName, body []byte) ([]byte, error) {
|
||||
if contentType, err := proxywasm.GetHttpRequestHeader(util.HeaderContentType); err == nil && isMultipartFormData(contentType) {
|
||||
return c.defaultTransformMultipartRequestBody(ctx, apiName, body, contentType)
|
||||
}
|
||||
|
||||
switch apiName {
|
||||
case ApiNameChatCompletion,
|
||||
ApiNameVideos,
|
||||
@@ -1283,6 +1287,28 @@ func (c *ProviderConfig) defaultTransformRequestBody(ctx wrapper.HttpContext, ap
|
||||
return sjson.SetBytes(body, "model", mappedModel)
|
||||
}
|
||||
|
||||
func (c *ProviderConfig) defaultTransformMultipartRequestBody(ctx wrapper.HttpContext, apiName ApiName, body []byte, contentType string) ([]byte, error) {
|
||||
if apiName != ApiNameImageEdit && apiName != ApiNameImageVariation {
|
||||
return body, nil
|
||||
}
|
||||
|
||||
model, err := extractMultipartModel(body, contentType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.SetContext(ctxKeyOriginalRequestModel, model)
|
||||
|
||||
mappedModel := getMappedModel(model, c.modelMapping)
|
||||
ctx.SetContext(ctxKeyFinalRequestModel, mappedModel)
|
||||
|
||||
if mappedModel == model || (mappedModel == "" && model == "") {
|
||||
return body, nil
|
||||
}
|
||||
|
||||
return rewriteMultipartFormModel(body, contentType, mappedModel)
|
||||
}
|
||||
|
||||
func (c *ProviderConfig) DefaultTransformResponseHeaders(ctx wrapper.HttpContext, headers http.Header) {
|
||||
if c.protocol == protocolOriginal {
|
||||
ctx.DontReadResponseBody()
|
||||
|
||||
Reference in New Issue
Block a user