Skip to content

Commit 613c60f

Browse files
authored
Switch from Google AI Studio -> Vertex (#738)
Vertex is where we have all of our Google credits. We have to use the older mode (`05-06`) because the latest one is not supported in vertex yet. I also increased the output token limit to match what we are using for sonnet 4.
1 parent 6e7f3fb commit 613c60f

File tree

3 files changed

+150
-5
lines changed

3 files changed

+150
-5
lines changed

app/lib/.server/llm/provider.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
33
import { createAnthropic } from '@ai-sdk/anthropic';
44
import { createXai } from '@ai-sdk/xai';
55
import { createGoogleGenerativeAI } from '@ai-sdk/google';
6+
import { createVertex } from '@ai-sdk/google-vertex';
67
import { createOpenAI } from '@ai-sdk/openai';
78
import { awsCredentialsProvider } from '@vercel/functions/oidc';
89
import { captureException } from '@sentry/remix';
@@ -68,13 +69,32 @@ export function getProvider(
6869
switch (modelProvider) {
6970
case 'Google': {
7071
model = modelForProvider(modelProvider, modelChoice);
71-
const google = createGoogleGenerativeAI({
72-
apiKey: userApiKey || getEnv('GOOGLE_API_KEY'),
73-
fetch: userApiKey ? userKeyApiFetch('Google') : fetch,
74-
});
72+
let google;
73+
if (userApiKey) {
74+
google = createGoogleGenerativeAI({
75+
apiKey: userApiKey || getEnv('GOOGLE_API_KEY'),
76+
fetch: userApiKey ? userKeyApiFetch('Google') : fetch,
77+
});
78+
} else {
79+
const credentials = JSON.parse(getEnv('GOOGLE_VERTEX_CREDENTIALS_JSON')!);
80+
google = createVertex({
81+
project: credentials.project_id,
82+
// Use global endpoint for higher availability
83+
baseURL: `https://aiplatform.googleapis.com/v1/projects/${credentials.project_id}/locations/global/publishers/google`,
84+
location: 'global',
85+
googleAuthOptions: {
86+
credentials: {
87+
client_email: credentials.client_email,
88+
private_key_id: credentials.private_key_id,
89+
private_key: credentials.private_key,
90+
},
91+
},
92+
fetch,
93+
});
94+
}
7595
provider = {
7696
model: google(model),
77-
maxTokens: 20000,
97+
maxTokens: 24576,
7898
};
7999
break;
80100
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@ai-sdk/amazon-bedrock": "^2.2.9",
3535
"@ai-sdk/anthropic": "^1.2.12",
3636
"@ai-sdk/google": "^1.2.11",
37+
"@ai-sdk/google-vertex": "^2.2.24",
3738
"@ai-sdk/openai": "^1.3.6",
3839
"@ai-sdk/react": "^1.2.5",
3940
"@ai-sdk/xai": "^1.2.13",

pnpm-lock.yaml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)