mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: handle global region correctly for Vertex AI Claude models
- Add custom baseURL for global region to use aiplatform.googleapis.com - Prevents incorrect hostname construction (global-aiplatform.googleapis.com) - Add comprehensive test coverage for global region scenarios Fixes #8571
This commit is contained in:
parent
eeaafef786
commit
e0fd25ae42
2 changed files with 58 additions and 1 deletions
|
|
@ -62,8 +62,58 @@ describe("VertexHandler", () => {
|
|||
expect(AnthropicVertex).toHaveBeenCalledWith({
|
||||
projectId: "test-project",
|
||||
region: "us-central1",
|
||||
baseURL: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it("should use custom baseURL for global region", () => {
|
||||
handler = new AnthropicVertexHandler({
|
||||
apiModelId: "claude-3-5-sonnet-v2@20241022",
|
||||
vertexProjectId: "test-project",
|
||||
vertexRegion: "global",
|
||||
})
|
||||
|
||||
expect(AnthropicVertex).toHaveBeenCalledWith({
|
||||
projectId: "test-project",
|
||||
region: "global",
|
||||
baseURL: "https://aiplatform.googleapis.com/v1",
|
||||
})
|
||||
})
|
||||
|
||||
it("should use custom baseURL for global region with JSON credentials", () => {
|
||||
const mockCredentials = JSON.stringify({ type: "service_account", project_id: "test" })
|
||||
handler = new AnthropicVertexHandler({
|
||||
apiModelId: "claude-3-5-sonnet-v2@20241022",
|
||||
vertexProjectId: "test-project",
|
||||
vertexRegion: "global",
|
||||
vertexJsonCredentials: mockCredentials,
|
||||
})
|
||||
|
||||
expect(AnthropicVertex).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
projectId: "test-project",
|
||||
region: "global",
|
||||
baseURL: "https://aiplatform.googleapis.com/v1",
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it("should use custom baseURL for global region with key file", () => {
|
||||
handler = new AnthropicVertexHandler({
|
||||
apiModelId: "claude-3-5-sonnet-v2@20241022",
|
||||
vertexProjectId: "test-project",
|
||||
vertexRegion: "global",
|
||||
vertexKeyFile: "/path/to/keyfile.json",
|
||||
})
|
||||
|
||||
expect(AnthropicVertex).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
projectId: "test-project",
|
||||
region: "global",
|
||||
baseURL: "https://aiplatform.googleapis.com/v1",
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("createMessage", () => {
|
||||
|
|
|
|||
|
|
@ -34,10 +34,16 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
|
|||
const projectId = this.options.vertexProjectId ?? "not-provided"
|
||||
const region = this.options.vertexRegion ?? "us-east5"
|
||||
|
||||
// For the "global" region, we need to use a custom base URL
|
||||
// The default would be "global-aiplatform.googleapis.com" which is incorrect
|
||||
// The correct endpoint for global is "aiplatform.googleapis.com"
|
||||
const baseURL = region === "global" ? `https://aiplatform.googleapis.com/v1` : undefined // Let the SDK use its default for other regions
|
||||
|
||||
if (this.options.vertexJsonCredentials) {
|
||||
this.client = new AnthropicVertex({
|
||||
projectId,
|
||||
region,
|
||||
baseURL,
|
||||
googleAuth: new GoogleAuth({
|
||||
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
||||
credentials: safeJsonParse<JWTInput>(this.options.vertexJsonCredentials, undefined),
|
||||
|
|
@ -47,13 +53,14 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
|
|||
this.client = new AnthropicVertex({
|
||||
projectId,
|
||||
region,
|
||||
baseURL,
|
||||
googleAuth: new GoogleAuth({
|
||||
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
||||
keyFile: this.options.vertexKeyFile,
|
||||
}),
|
||||
})
|
||||
} else {
|
||||
this.client = new AnthropicVertex({ projectId, region })
|
||||
this.client = new AnthropicVertex({ projectId, region, baseURL })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue