Skip to content

Commit 70a88ae

Browse files
authored
Merge pull request RooCodeInc#1392 from eonghk/feature/vertex-credentials-auth
Add credentials auth for Google vertex
2 parents ae7601b + e3ffd13 commit 70a88ae

File tree

5 files changed

+82
-9
lines changed

5 files changed

+82
-9
lines changed

.changeset/tame-carpets-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Add credentials auth for Google vertex

src/api/providers/vertex.ts

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { BaseProvider } from "./base-provider"
1111

1212
import { ANTHROPIC_DEFAULT_MAX_TOKENS } from "./constants"
1313
import { getModelParams, SingleCompletionHandler } from "../"
14+
import { GoogleAuth } from "google-auth-library"
1415

1516
// Types for Vertex SDK
1617

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

123-
this.anthropicClient = new AnthropicVertex({
124-
projectId: this.options.vertexProjectId ?? "not-provided",
125-
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
126-
region: this.options.vertexRegion ?? "us-east5",
127-
})
124+
if (this.options.vertexJsonCredentials) {
125+
this.anthropicClient = new AnthropicVertex({
126+
projectId: this.options.vertexProjectId ?? "not-provided",
127+
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
128+
region: this.options.vertexRegion ?? "us-east5",
129+
googleAuth: new GoogleAuth({
130+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
131+
credentials: JSON.parse(this.options.vertexJsonCredentials),
132+
}),
133+
})
134+
} else if (this.options.vertexKeyFile) {
135+
this.anthropicClient = new AnthropicVertex({
136+
projectId: this.options.vertexProjectId ?? "not-provided",
137+
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
138+
region: this.options.vertexRegion ?? "us-east5",
139+
googleAuth: new GoogleAuth({
140+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
141+
keyFile: this.options.vertexKeyFile,
142+
}),
143+
})
144+
} else {
145+
this.anthropicClient = new AnthropicVertex({
146+
projectId: this.options.vertexProjectId ?? "not-provided",
147+
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
148+
region: this.options.vertexRegion ?? "us-east5",
149+
})
150+
}
128151

129-
this.geminiClient = new VertexAI({
130-
project: this.options.vertexProjectId ?? "not-provided",
131-
location: this.options.vertexRegion ?? "us-east5",
132-
})
152+
if (this.options.vertexJsonCredentials) {
153+
this.geminiClient = new VertexAI({
154+
project: this.options.vertexProjectId ?? "not-provided",
155+
location: this.options.vertexRegion ?? "us-east5",
156+
googleAuthOptions: {
157+
credentials: JSON.parse(this.options.vertexJsonCredentials),
158+
},
159+
})
160+
} else if (this.options.vertexKeyFile) {
161+
this.geminiClient = new VertexAI({
162+
project: this.options.vertexProjectId ?? "not-provided",
163+
location: this.options.vertexRegion ?? "us-east5",
164+
googleAuthOptions: {
165+
keyFile: this.options.vertexKeyFile,
166+
},
167+
})
168+
} else {
169+
this.geminiClient = new VertexAI({
170+
project: this.options.vertexProjectId ?? "not-provided",
171+
location: this.options.vertexRegion ?? "us-east5",
172+
})
173+
}
133174
}
134175

135176
private formatMessageForCache(message: Anthropic.Messages.MessageParam, shouldCache: boolean): VertexMessage {

src/shared/api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export interface ApiHandlerOptions {
3939
awspromptCacheId?: string
4040
awsProfile?: string
4141
awsUseProfile?: boolean
42+
vertexKeyFile?: string
43+
vertexJsonCredentials?: string
4244
vertexProjectId?: string
4345
vertexRegion?: string
4446
openAiBaseUrl?: string
@@ -97,6 +99,8 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [
9799
// "awspromptCacheId", // NOT exist on GlobalStateKey
98100
"awsProfile",
99101
"awsUseProfile",
102+
"vertexKeyFile",
103+
"vertexJsonCredentials",
100104
"vertexProjectId",
101105
"vertexRegion",
102106
"openAiBaseUrl",

src/shared/globalState.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export const GLOBAL_STATE_KEYS = [
2828
"awsUseCrossRegionInference",
2929
"awsProfile",
3030
"awsUseProfile",
31+
"vertexKeyFile",
32+
"vertexJsonCredentials",
3133
"vertexProjectId",
3234
"vertexRegion",
3335
"lastShownAnnouncementId",

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,28 @@ const ApiOptions = ({
565565
2. Install the Google Cloud CLI & configure application default credentials.
566566
</VSCodeLink>
567567
</div>
568+
<div>
569+
<VSCodeLink
570+
href="https://developers.google.com/workspace/guides/create-credentials?hl=en#service-account"
571+
className="text-sm">
572+
3. Or create a service account with credentials.
573+
</VSCodeLink>
574+
</div>
568575
</div>
576+
<VSCodeTextField
577+
value={apiConfiguration?.vertexJsonCredentials || ""}
578+
style={{ width: "100%" }}
579+
onInput={handleInputChange("vertexJsonCredentials")}
580+
placeholder="Enter Credentials JSON...">
581+
<span className="font-medium">Google Cloud Credentials</span>
582+
</VSCodeTextField>
583+
<VSCodeTextField
584+
value={apiConfiguration?.vertexKeyFile || ""}
585+
style={{ width: "100%" }}
586+
onInput={handleInputChange("vertexKeyFile")}
587+
placeholder="Enter Key File Path...">
588+
<span className="font-medium">Google Cloud Key File Path</span>
589+
</VSCodeTextField>
569590
<VSCodeTextField
570591
value={apiConfiguration?.vertexProjectId || ""}
571592
onInput={handleInputChange("vertexProjectId")}

0 commit comments

Comments
 (0)