mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 12:47:28 +08:00
azure-openai support other type api (#1187)
This commit is contained in:
@@ -55,19 +55,21 @@ func (m *azureProvider) GetProviderType() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *azureProvider) OnRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, log wrapper.Log) (types.Action, error) {
|
func (m *azureProvider) OnRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, log wrapper.Log) (types.Action, error) {
|
||||||
if apiName != ApiNameChatCompletion {
|
|
||||||
return types.ActionContinue, errUnsupportedApiName
|
|
||||||
}
|
|
||||||
_ = util.OverwriteRequestPath(m.serviceUrl.RequestURI())
|
_ = util.OverwriteRequestPath(m.serviceUrl.RequestURI())
|
||||||
_ = util.OverwriteRequestHost(m.serviceUrl.Host)
|
_ = util.OverwriteRequestHost(m.serviceUrl.Host)
|
||||||
_ = proxywasm.ReplaceHttpRequestHeader("api-key", m.config.apiTokens[0])
|
_ = proxywasm.ReplaceHttpRequestHeader("api-key", m.config.apiTokens[0])
|
||||||
|
if apiName == ApiNameChatCompletion {
|
||||||
_ = proxywasm.RemoveHttpRequestHeader("Content-Length")
|
_ = proxywasm.RemoveHttpRequestHeader("Content-Length")
|
||||||
|
} else {
|
||||||
|
ctx.DontReadRequestBody()
|
||||||
|
}
|
||||||
return types.ActionContinue, nil
|
return types.ActionContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *azureProvider) OnRequestBody(ctx wrapper.HttpContext, apiName ApiName, body []byte, log wrapper.Log) (types.Action, error) {
|
func (m *azureProvider) OnRequestBody(ctx wrapper.HttpContext, apiName ApiName, body []byte, log wrapper.Log) (types.Action, error) {
|
||||||
if apiName != ApiNameChatCompletion {
|
if apiName != ApiNameChatCompletion {
|
||||||
return types.ActionContinue, errUnsupportedApiName
|
// We don't need to process the request body for other APIs.
|
||||||
|
return types.ActionContinue, nil
|
||||||
}
|
}
|
||||||
request := &chatCompletionRequest{}
|
request := &chatCompletionRequest{}
|
||||||
if err := decodeChatCompletionRequest(body, request); err != nil {
|
if err := decodeChatCompletionRequest(body, request); err != nil {
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ func (m *openaiProvider) OnRequestHeaders(ctx wrapper.HttpContext, apiName ApiNa
|
|||||||
case ApiNameChatCompletion:
|
case ApiNameChatCompletion:
|
||||||
_ = util.OverwriteRequestPath(defaultOpenaiChatCompletionPath)
|
_ = util.OverwriteRequestPath(defaultOpenaiChatCompletionPath)
|
||||||
case ApiNameEmbeddings:
|
case ApiNameEmbeddings:
|
||||||
|
ctx.DontReadRequestBody()
|
||||||
_ = util.OverwriteRequestPath(defaultOpenaiEmbeddingsPath)
|
_ = util.OverwriteRequestPath(defaultOpenaiEmbeddingsPath)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user