Skip to content

Commit b1314de

Browse files
committed
fix: limit Claude model detection to vertex and bedrock providers only
- Modified getApiProtocol to only detect Claude models by name when provider is vertex or bedrock - Added comprehensive unit tests for getApiProtocol function as requested in PR review - This ensures Claude models are only auto-detected for providers that need it
1 parent 3540561 commit b1314de

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { describe, it, expect } from "vitest"
2+
import { getApiProtocol } from "../provider-settings.js"
3+
4+
describe("getApiProtocol", () => {
5+
describe("Anthropic-style providers", () => {
6+
it("should return 'anthropic' for anthropic provider", () => {
7+
expect(getApiProtocol("anthropic")).toBe("anthropic")
8+
expect(getApiProtocol("anthropic", "gpt-4")).toBe("anthropic")
9+
})
10+
11+
it("should return 'anthropic' for claude-code provider", () => {
12+
expect(getApiProtocol("claude-code")).toBe("anthropic")
13+
expect(getApiProtocol("claude-code", "some-model")).toBe("anthropic")
14+
})
15+
})
16+
17+
describe("Vertex provider with Claude models", () => {
18+
it("should return 'anthropic' for vertex provider with claude models", () => {
19+
expect(getApiProtocol("vertex", "claude-3-opus")).toBe("anthropic")
20+
expect(getApiProtocol("vertex", "Claude-3-Sonnet")).toBe("anthropic")
21+
expect(getApiProtocol("vertex", "CLAUDE-instant")).toBe("anthropic")
22+
expect(getApiProtocol("vertex", "anthropic/claude-3-haiku")).toBe("anthropic")
23+
})
24+
25+
it("should return 'openai' for vertex provider with non-claude models", () => {
26+
expect(getApiProtocol("vertex", "gpt-4")).toBe("openai")
27+
expect(getApiProtocol("vertex", "gemini-pro")).toBe("openai")
28+
expect(getApiProtocol("vertex", "llama-2")).toBe("openai")
29+
})
30+
})
31+
32+
describe("Bedrock provider with Claude models", () => {
33+
it("should return 'anthropic' for bedrock provider with claude models", () => {
34+
expect(getApiProtocol("bedrock", "claude-3-opus")).toBe("anthropic")
35+
expect(getApiProtocol("bedrock", "Claude-3-Sonnet")).toBe("anthropic")
36+
expect(getApiProtocol("bedrock", "CLAUDE-instant")).toBe("anthropic")
37+
expect(getApiProtocol("bedrock", "anthropic.claude-v2")).toBe("anthropic")
38+
})
39+
40+
it("should return 'openai' for bedrock provider with non-claude models", () => {
41+
expect(getApiProtocol("bedrock", "gpt-4")).toBe("openai")
42+
expect(getApiProtocol("bedrock", "titan-text")).toBe("openai")
43+
expect(getApiProtocol("bedrock", "llama-2")).toBe("openai")
44+
})
45+
})
46+
47+
describe("Other providers with Claude models", () => {
48+
it("should return 'openai' for non-vertex/bedrock providers with claude models", () => {
49+
expect(getApiProtocol("openrouter", "claude-3-opus")).toBe("openai")
50+
expect(getApiProtocol("openai", "claude-3-sonnet")).toBe("openai")
51+
expect(getApiProtocol("litellm", "claude-instant")).toBe("openai")
52+
expect(getApiProtocol("ollama", "claude-model")).toBe("openai")
53+
})
54+
})
55+
56+
describe("Edge cases", () => {
57+
it("should return 'openai' when provider is undefined", () => {
58+
expect(getApiProtocol(undefined)).toBe("openai")
59+
expect(getApiProtocol(undefined, "claude-3-opus")).toBe("openai")
60+
})
61+
62+
it("should return 'openai' when model is undefined", () => {
63+
expect(getApiProtocol("openai")).toBe("openai")
64+
expect(getApiProtocol("vertex")).toBe("openai")
65+
expect(getApiProtocol("bedrock")).toBe("openai")
66+
})
67+
68+
it("should handle empty strings", () => {
69+
expect(getApiProtocol("vertex", "")).toBe("openai")
70+
expect(getApiProtocol("bedrock", "")).toBe("openai")
71+
})
72+
73+
it("should be case-insensitive for claude detection", () => {
74+
expect(getApiProtocol("vertex", "CLAUDE-3-OPUS")).toBe("anthropic")
75+
expect(getApiProtocol("bedrock", "claude-3-opus")).toBe("anthropic")
76+
expect(getApiProtocol("vertex", "ClAuDe-InStAnT")).toBe("anthropic")
77+
})
78+
})
79+
})

packages/types/src/provider-settings.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,13 @@ export const getApiProtocol = (provider: ProviderName | undefined, modelId?: str
310310
return "anthropic"
311311
}
312312

313-
// Then check if the model ID contains "claude" (case-insensitive)
314-
if (modelId && modelId.toLowerCase().includes("claude")) {
313+
// For vertex and bedrock providers, check if the model ID contains "claude" (case-insensitive)
314+
if (
315+
provider &&
316+
(provider === "vertex" || provider === "bedrock") &&
317+
modelId &&
318+
modelId.toLowerCase().includes("claude")
319+
) {
315320
return "anthropic"
316321
}
317322

0 commit comments

Comments
 (0)