From 8b3ffda24f55b474bce82d8f7a6504a14af0488c Mon Sep 17 00:00:00 2001 From: "yu.deng" Date: Thu, 21 Nov 2024 17:23:23 +0800 Subject: [PATCH] feat: allow cover api-version when use ai-proxy azure provider --- .../extensions/ai-proxy/provider/azure.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/azure.go b/plugins/wasm-go/extensions/ai-proxy/provider/azure.go index 1a79908d4e..b09cdd0951 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/azure.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/azure.go @@ -69,7 +69,22 @@ func (m *azureProvider) OnRequestBody(ctx wrapper.HttpContext, apiName ApiName, } func (m *azureProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header, log wrapper.Log) { - util.OverwriteRequestPathHeader(headers, m.serviceUrl.RequestURI()) + u, e := url.Parse(ctx.Path()) + if e == nil { + customApiVersion := u.Query().Get("api-version") + if customApiVersion == "" { + util.OverwriteRequestPathHeader(headers, m.serviceUrl.RequestURI()) + } else { + q := m.serviceUrl.Query() + q.Set("api-version", customApiVersion) + newUrl := *m.serviceUrl + newUrl.RawQuery = q.Encode() + util.OverwriteRequestPathHeader(headers, newUrl.RequestURI()) + } + } else { + log.Errorf("failed to parse request path: %v", e) + util.OverwriteRequestPathHeader(headers, m.serviceUrl.RequestURI()) + } util.OverwriteRequestHostHeader(headers, m.serviceUrl.Host) util.OverwriteRequestAuthorizationHeader(headers, "api-key "+m.config.GetApiTokenInUse(ctx)) headers.Del("Content-Length")