Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-carpets-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"roo-cline": patch
---

Add credentials auth for Google vertex
59 changes: 50 additions & 9 deletions src/api/providers/vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BaseProvider } from "./base-provider"

import { ANTHROPIC_DEFAULT_MAX_TOKENS } from "./constants"
import { getModelParams, SingleCompletionHandler } from "../"
import { GoogleAuth } from "google-auth-library"

// Types for Vertex SDK

Expand Down Expand Up @@ -120,16 +121,56 @@ export class VertexHandler extends BaseProvider implements SingleCompletionHandl
throw new Error(`Unknown model ID: ${this.options.apiModelId}`)
}

this.anthropicClient = new AnthropicVertex({
projectId: this.options.vertexProjectId ?? "not-provided",
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
region: this.options.vertexRegion ?? "us-east5",
})
if (this.options.vertexJsonCredentials) {
this.anthropicClient = new AnthropicVertex({
projectId: this.options.vertexProjectId ?? "not-provided",
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
region: this.options.vertexRegion ?? "us-east5",
googleAuth: new GoogleAuth({
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
credentials: JSON.parse(this.options.vertexJsonCredentials),
}),
})
} else if (this.options.vertexKeyFile) {
this.anthropicClient = new AnthropicVertex({
projectId: this.options.vertexProjectId ?? "not-provided",
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
region: this.options.vertexRegion ?? "us-east5",
googleAuth: new GoogleAuth({
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
keyFile: this.options.vertexKeyFile,
}),
})
} else {
this.anthropicClient = new AnthropicVertex({
projectId: this.options.vertexProjectId ?? "not-provided",
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
region: this.options.vertexRegion ?? "us-east5",
})
}

this.geminiClient = new VertexAI({
project: this.options.vertexProjectId ?? "not-provided",
location: this.options.vertexRegion ?? "us-east5",
})
if (this.options.vertexJsonCredentials) {
this.geminiClient = new VertexAI({
project: this.options.vertexProjectId ?? "not-provided",
location: this.options.vertexRegion ?? "us-east5",
googleAuthOptions: {
credentials: JSON.parse(this.options.vertexJsonCredentials),
},
})
} else if (this.options.vertexKeyFile) {
this.geminiClient = new VertexAI({
project: this.options.vertexProjectId ?? "not-provided",
location: this.options.vertexRegion ?? "us-east5",
googleAuthOptions: {
keyFile: this.options.vertexKeyFile,
},
})
} else {
this.geminiClient = new VertexAI({
project: this.options.vertexProjectId ?? "not-provided",
location: this.options.vertexRegion ?? "us-east5",
})
}
}

private formatMessageForCache(message: Anthropic.Messages.MessageParam, shouldCache: boolean): VertexMessage {
Expand Down
4 changes: 4 additions & 0 deletions src/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export interface ApiHandlerOptions {
awspromptCacheId?: string
awsProfile?: string
awsUseProfile?: boolean
vertexKeyFile?: string
vertexJsonCredentials?: string
vertexProjectId?: string
vertexRegion?: string
openAiBaseUrl?: string
Expand Down Expand Up @@ -97,6 +99,8 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [
// "awspromptCacheId", // NOT exist on GlobalStateKey
"awsProfile",
"awsUseProfile",
"vertexKeyFile",
"vertexJsonCredentials",
"vertexProjectId",
"vertexRegion",
"openAiBaseUrl",
Expand Down
2 changes: 2 additions & 0 deletions src/shared/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const GLOBAL_STATE_KEYS = [
"awsUseCrossRegionInference",
"awsProfile",
"awsUseProfile",
"vertexKeyFile",
"vertexJsonCredentials",
"vertexProjectId",
"vertexRegion",
"lastShownAnnouncementId",
Expand Down
21 changes: 21 additions & 0 deletions webview-ui/src/components/settings/ApiOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,28 @@ const ApiOptions = ({
2. Install the Google Cloud CLI & configure application default credentials.
</VSCodeLink>
</div>
<div>
<VSCodeLink
href="https://developers.google.com/workspace/guides/create-credentials?hl=en#service-account"
className="text-sm">
3. Or create a service account with credentials.
</VSCodeLink>
</div>
</div>
<VSCodeTextField
value={apiConfiguration?.vertexJsonCredentials || ""}
style={{ width: "100%" }}
onInput={handleInputChange("vertexJsonCredentials")}
placeholder="Enter Credentials JSON...">
<span className="font-medium">Google Cloud Credentials</span>
</VSCodeTextField>
<VSCodeTextField
value={apiConfiguration?.vertexKeyFile || ""}
style={{ width: "100%" }}
onInput={handleInputChange("vertexKeyFile")}
placeholder="Enter Key File Path...">
<span className="font-medium">Google Cloud Key File Path</span>
</VSCodeTextField>
<VSCodeTextField
value={apiConfiguration?.vertexProjectId || ""}
onInput={handleInputChange("vertexProjectId")}
Expand Down
Loading