feat(provider): 优化 Azure multipart 处理 || feat(provider): Optimize Azure multipart processing (#3651)

This commit is contained in:
woody
2026-03-30 13:45:41 +08:00
committed by GitHub
parent 83461887dc
commit 889ea67013
6 changed files with 756 additions and 4 deletions

View File

@@ -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()