mirror of
https://github.com/alibaba/higress.git
synced 2026-05-26 13:47:27 +08:00
feat(ai-proxy): 修复 openai 配置 openaiCustomUrl 之后, 对不支持 Api 透传路径错误的问题 || feat(ai-proxy): Fixed the issue that the API pass-through path error does not support openaiCustomUrl after openai is configured. (#2364)
Signed-off-by: Xijun Dai <daixijun1990@gmail.com>
This commit is contained in:
@@ -40,6 +40,7 @@ func (m *openaiProviderInitializer) DefaultCapabilities() map[string]string {
|
|||||||
string(ApiNameBatches): PathOpenAIBatches,
|
string(ApiNameBatches): PathOpenAIBatches,
|
||||||
string(ApiNameRetrieveBatch): PathOpenAIRetrieveBatch,
|
string(ApiNameRetrieveBatch): PathOpenAIRetrieveBatch,
|
||||||
string(ApiNameCancelBatch): PathOpenAICancelBatch,
|
string(ApiNameCancelBatch): PathOpenAICancelBatch,
|
||||||
|
string(ApiNameResponses): PathOpenAIResponses,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +48,11 @@ func isDirectPath(path string) bool {
|
|||||||
return strings.HasSuffix(path, "/completions") ||
|
return strings.HasSuffix(path, "/completions") ||
|
||||||
strings.HasSuffix(path, "/embeddings") ||
|
strings.HasSuffix(path, "/embeddings") ||
|
||||||
strings.HasSuffix(path, "/audio/speech") ||
|
strings.HasSuffix(path, "/audio/speech") ||
|
||||||
strings.HasSuffix(path, "/images/generations")
|
strings.HasSuffix(path, "/images/generations") ||
|
||||||
|
strings.HasSuffix(path, "/images/variations") ||
|
||||||
|
strings.HasSuffix(path, "/images/edits") ||
|
||||||
|
strings.HasSuffix(path, "/models") ||
|
||||||
|
strings.HasSuffix(path, "/responses")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *openaiProviderInitializer) CreateProvider(config ProviderConfig) (Provider, error) {
|
func (m *openaiProviderInitializer) CreateProvider(config ProviderConfig) (Provider, error) {
|
||||||
@@ -101,15 +106,14 @@ func (m *openaiProvider) OnRequestHeaders(ctx wrapper.HttpContext, apiName ApiNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *openaiProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header) {
|
func (m *openaiProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header) {
|
||||||
if m.customPath != "" {
|
if m.isDirectCustomPath {
|
||||||
if m.isDirectCustomPath || apiName == "" {
|
util.OverwriteRequestPathHeader(headers, m.customPath)
|
||||||
util.OverwriteRequestPathHeader(headers, m.customPath)
|
}
|
||||||
} else {
|
|
||||||
util.OverwriteRequestPathHeaderByCapability(headers, string(apiName), m.config.capabilities)
|
if apiName != "" {
|
||||||
}
|
|
||||||
} else {
|
|
||||||
util.OverwriteRequestPathHeaderByCapability(headers, string(apiName), m.config.capabilities)
|
util.OverwriteRequestPathHeaderByCapability(headers, string(apiName), m.config.capabilities)
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.customDomain != "" {
|
if m.customDomain != "" {
|
||||||
util.OverwriteRequestHostHeader(headers, m.customDomain)
|
util.OverwriteRequestHostHeader(headers, m.customDomain)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const (
|
|||||||
ApiNameRetrieveBatch ApiName = "openai/v1/retrievebatch"
|
ApiNameRetrieveBatch ApiName = "openai/v1/retrievebatch"
|
||||||
ApiNameCancelBatch ApiName = "openai/v1/cancelbatch"
|
ApiNameCancelBatch ApiName = "openai/v1/cancelbatch"
|
||||||
ApiNameModels ApiName = "openai/v1/models"
|
ApiNameModels ApiName = "openai/v1/models"
|
||||||
|
ApiNameResponses ApiName = "openai/v1/responses"
|
||||||
|
|
||||||
PathOpenAICompletions = "/v1/completions"
|
PathOpenAICompletions = "/v1/completions"
|
||||||
PathOpenAIChatCompletions = "/v1/chat/completions"
|
PathOpenAIChatCompletions = "/v1/chat/completions"
|
||||||
@@ -56,6 +57,7 @@ const (
|
|||||||
PathOpenAIImageEdit = "/v1/images/edits"
|
PathOpenAIImageEdit = "/v1/images/edits"
|
||||||
PathOpenAIImageVariation = "/v1/images/variations"
|
PathOpenAIImageVariation = "/v1/images/variations"
|
||||||
PathOpenAIAudioSpeech = "/v1/audio/speech"
|
PathOpenAIAudioSpeech = "/v1/audio/speech"
|
||||||
|
PathOpenAIResponses = "/v1/responses"
|
||||||
|
|
||||||
// TODO: 以下是一些非标准的API名称,需要进一步确认是否支持
|
// TODO: 以下是一些非标准的API名称,需要进一步确认是否支持
|
||||||
ApiNameCohereV1Rerank ApiName = "cohere/v1/rerank"
|
ApiNameCohereV1Rerank ApiName = "cohere/v1/rerank"
|
||||||
|
|||||||
Reference in New Issue
Block a user