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:
zat366
2026-05-25 14:34:45 +08:00
committed by GitHub
parent 8a0f8a8208
commit 632c6ca655
2 changed files with 10 additions and 4 deletions

View File

@@ -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 ""

View File

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