mirror of
https://github.com/alibaba/higress.git
synced 2026-05-26 21:57:30 +08:00
fix(ai-proxy): use HasSuffix instead of Contains in claude.GetApiName to prevent sub-path misidentification (#3839)
Signed-off-by: zat366 <authentic.zhao@gmail.com>
This commit is contained in:
@@ -1060,16 +1060,16 @@ func (c *claudeProvider) insertHttpContextMessage(body []byte, content string, o
|
||||
}
|
||||
|
||||
func (c *claudeProvider) GetApiName(path string) ApiName {
|
||||
if strings.Contains(path, PathAnthropicMessages) {
|
||||
if strings.HasSuffix(path, PathAnthropicMessages) {
|
||||
return ApiNameChatCompletion
|
||||
}
|
||||
if strings.Contains(path, PathAnthropicComplete) {
|
||||
if strings.HasSuffix(path, PathAnthropicComplete) {
|
||||
return ApiNameCompletion
|
||||
}
|
||||
if strings.Contains(path, PathOpenAIModels) {
|
||||
if strings.HasSuffix(path, PathOpenAIModels) {
|
||||
return ApiNameModels
|
||||
}
|
||||
if strings.Contains(path, PathOpenAIEmbeddings) {
|
||||
if strings.HasSuffix(path, PathOpenAIEmbeddings) {
|
||||
return ApiNameEmbeddings
|
||||
}
|
||||
return ""
|
||||
|
||||
@@ -572,6 +572,12 @@ func TestClaudeProvider_GetApiName(t *testing.T) {
|
||||
t.Run("unknown_path", func(t *testing.T) {
|
||||
assert.Equal(t, ApiName(""), provider.GetApiName("/unknown"))
|
||||
})
|
||||
|
||||
t.Run("sub_paths_should_not_match", func(t *testing.T) {
|
||||
assert.Equal(t, ApiName(""), provider.GetApiName("/v1/messages/count_tokens"))
|
||||
assert.Equal(t, ApiName(""), provider.GetApiName("/v1/messages/batches"))
|
||||
assert.Equal(t, ApiName(""), provider.GetApiName("/v1/complete/something"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestClaudeProvider_BuildClaudeTextGenRequest_ToolRoleConversion(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user