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
6 changes: 6 additions & 0 deletions .changeset/fuzzy-cherries-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ai-sdk/google-vertex': patch
'@ai-sdk/google': patch
---

Fix adding google search along with url context in vertex ai
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const dummyEmbeddings = [
const testValues = ['test text one', 'test text two'];

const DEFAULT_URL =
'https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/publishers/google/models/textembedding-gecko@001:predict';
'https://us-central1-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/us-central1/publishers/google/models/textembedding-gecko@001:predict';

const CUSTOM_URL =
'https://custom-endpoint.com/models/textembedding-gecko@001:predict';
Expand All @@ -43,7 +43,7 @@ describe('GoogleVertexEmbeddingModel', () => {
project: 'test-project',
headers: () => ({}),
baseURL:
'https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/publishers/google',
'https://us-central1-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/us-central1/publishers/google',
};

const model = new GoogleVertexEmbeddingModel(mockModelId, mockConfig);
Expand Down
14 changes: 7 additions & 7 deletions packages/google-vertex/src/google-vertex-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('google-vertex-provider', () => {
expect.objectContaining({
provider: 'google.vertex.chat',
baseURL:
'https://test-location-aiplatform.googleapis.com/v1/projects/test-project/locations/test-location/publishers/google',
'https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google',
headers: expect.any(Function),
generateId: expect.any(Function),
}),
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('google-vertex-provider', () => {
provider: 'google.vertex.embedding',
headers: expect.any(Function),
baseURL:
'https://test-location-aiplatform.googleapis.com/v1/projects/test-project/locations/test-location/publishers/google',
'https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google',
}),
);
});
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('google-vertex-provider', () => {
expect.objectContaining({
provider: 'google.vertex.image',
baseURL:
'https://test-location-aiplatform.googleapis.com/v1/projects/test-project/locations/test-location/publishers/google',
'https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google',
headers: expect.any(Function),
}),
);
Expand All @@ -172,7 +172,7 @@ describe('google-vertex-provider', () => {
expect.objectContaining({
provider: 'google.vertex.chat',
baseURL:
'https://aiplatform.googleapis.com/v1/projects/test-project/locations/global/publishers/google',
'https://aiplatform.googleapis.com/v1beta1/projects/test-project/locations/global/publishers/google',
headers: expect.any(Function),
generateId: expect.any(Function),
}),
Expand All @@ -192,7 +192,7 @@ describe('google-vertex-provider', () => {
provider: 'google.vertex.embedding',
headers: expect.any(Function),
baseURL:
'https://aiplatform.googleapis.com/v1/projects/test-project/locations/global/publishers/google',
'https://aiplatform.googleapis.com/v1beta1/projects/test-project/locations/global/publishers/google',
}),
);
});
Expand All @@ -209,7 +209,7 @@ describe('google-vertex-provider', () => {
expect.objectContaining({
provider: 'google.vertex.image',
baseURL:
'https://aiplatform.googleapis.com/v1/projects/test-project/locations/global/publishers/google',
'https://aiplatform.googleapis.com/v1beta1/projects/test-project/locations/global/publishers/google',
headers: expect.any(Function),
}),
);
Expand Down Expand Up @@ -239,7 +239,7 @@ describe('google-vertex-provider', () => {
expect.objectContaining({
provider: 'google.vertex.chat',
baseURL:
'https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/publishers/google',
'https://us-central1-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/us-central1/publishers/google',
headers: expect.any(Function),
generateId: expect.any(Function),
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/google-vertex/src/google-vertex-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function createVertex(

return (
withoutTrailingSlash(options.baseURL) ??
`https://${baseHost}/v1/projects/${project}/locations/${region}/publishers/google`
`https://${baseHost}/v1beta1/projects/${project}/locations/${region}/publishers/google`
);
};

Expand Down
44 changes: 24 additions & 20 deletions packages/google/src/google-generative-ai-language-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ describe('doGenerate', () => {
});

const requestBody = await server.calls[0].requestBodyJson;
expect(requestBody.tools).toEqual({ codeExecution: {} });
expect(requestBody.tools).toEqual([{ codeExecution: {} }]);

expect(content).toEqual([
{
Expand Down Expand Up @@ -1119,7 +1119,7 @@ describe('doGenerate', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: { googleSearch: {} },
tools: [{ googleSearch: {} }],
});
});

Expand All @@ -1142,7 +1142,7 @@ describe('doGenerate', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: { googleSearch: {} },
tools: [{ googleSearch: {} }],
});
});

Expand All @@ -1165,7 +1165,7 @@ describe('doGenerate', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: { googleSearchRetrieval: {} },
tools: [{ googleSearchRetrieval: {} }],
});
});

Expand All @@ -1192,14 +1192,16 @@ describe('doGenerate', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: {
googleSearchRetrieval: {
dynamicRetrievalConfig: {
mode: 'MODE_DYNAMIC',
dynamicThreshold: 1,
tools: [
{
googleSearchRetrieval: {
dynamicRetrievalConfig: {
mode: 'MODE_DYNAMIC',
dynamicThreshold: 1,
},
},
},
},
],
});
});
it('should use urlContextTool for gemini-2.0-pro', async () => {
Expand All @@ -1221,7 +1223,7 @@ describe('doGenerate', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: { urlContext: {} },
tools: [{ urlContext: {} }],
});
});
});
Expand Down Expand Up @@ -2170,7 +2172,7 @@ describe('doStream', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: { googleSearch: {} },
tools: [{ googleSearch: {} }],
});
});

Expand All @@ -2196,7 +2198,7 @@ describe('doStream', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: { googleSearch: {} },
tools: [{ googleSearch: {} }],
});
});

Expand All @@ -2221,7 +2223,7 @@ describe('doStream', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: { googleSearchRetrieval: {} },
tools: [{ googleSearchRetrieval: {} }],
});
});

Expand Down Expand Up @@ -2250,14 +2252,16 @@ describe('doStream', () => {
});

expect(await server.calls[0].requestBodyJson).toMatchObject({
tools: {
googleSearchRetrieval: {
dynamicRetrievalConfig: {
mode: 'MODE_DYNAMIC',
dynamicThreshold: 1,
tools: [
{
googleSearchRetrieval: {
dynamicRetrievalConfig: {
mode: 'MODE_DYNAMIC',
dynamicThreshold: 1,
},
},
},
},
],
});
});
});
Expand Down
85 changes: 73 additions & 12 deletions packages/google/src/google-prepare-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ it('should correctly prepare function tools', () => {
expect(result.toolWarnings).toEqual([]);
});

it('should correctly prepare provider-defined tools', () => {
it('should correctly prepare provider-defined tools as array', () => {
const result = prepareTools({
tools: [
{
Expand All @@ -65,10 +65,24 @@ it('should correctly prepare provider-defined tools', () => {
],
modelId: 'gemini-2.5-flash',
});
expect(result.tools).toEqual({
googleSearch: {},
urlContext: {},
expect(result.tools).toEqual([{ googleSearch: {} }, { urlContext: {} }]);
expect(result.toolConfig).toBeUndefined();
expect(result.toolWarnings).toEqual([]);
});

it('should correctly prepare single provider-defined tool', () => {
const result = prepareTools({
tools: [
{
type: 'provider-defined',
id: 'google.google_search',
name: 'google_search',
args: {},
},
],
modelId: 'gemini-2.5-flash',
});
expect(result.tools).toEqual([{ googleSearch: {} }]);
expect(result.toolConfig).toBeUndefined();
expect(result.toolWarnings).toEqual([]);
});
Expand Down Expand Up @@ -205,10 +219,8 @@ it('should warn when mixing function and provider-defined tools', () => {
modelId: 'gemini-2.5-flash',
});

// Should only include provider-defined tools
expect(result.tools).toEqual({
googleSearch: {},
});
// Should only include provider-defined tools as array
expect(result.tools).toEqual([{ googleSearch: {} }]);

// Should have warning about mixed tool types
expect(result.toolWarnings).toEqual([
Expand Down Expand Up @@ -248,10 +260,8 @@ it('should handle tool choice with mixed tools (provider-defined tools only)', (
modelId: 'gemini-2.5-flash',
});

// Should only include provider-defined tools
expect(result.tools).toEqual({
googleSearch: {},
});
// Should only include provider-defined tools as array
expect(result.tools).toEqual([{ googleSearch: {} }]);

// Should apply tool choice to provider-defined tools
expect(result.toolConfig).toEqual(undefined);
Expand All @@ -271,3 +281,54 @@ it('should handle tool choice with mixed tools (provider-defined tools only)', (
},
]);
});

it('should handle latest modelId for provider-defined tools correctly', () => {
const result = prepareTools({
tools: [
{
type: 'provider-defined',
id: 'google.google_search',
name: 'google_search',
args: {},
},
],
modelId: 'gemini-flash-latest',
});
expect(result.tools).toEqual([{ googleSearchRetrieval: {} }]);
expect(result.toolConfig).toBeUndefined();
expect(result.toolWarnings).toEqual([]);
});

it('should handle code execution tool', () => {
const result = prepareTools({
tools: [
{
type: 'provider-defined',
id: 'google.code_execution',
name: 'code_execution',
args: {},
},
],
modelId: 'gemini-2.5-flash',
});
expect(result.tools).toEqual([{ codeExecution: {} }]);
expect(result.toolConfig).toBeUndefined();
expect(result.toolWarnings).toEqual([]);
});

it('should handle url context tool alone', () => {
const result = prepareTools({
tools: [
{
type: 'provider-defined',
id: 'google.url_context',
name: 'url_context',
args: {},
},
],
modelId: 'gemini-2.5-flash',
});
expect(result.tools).toEqual([{ urlContext: {} }]);
expect(result.toolConfig).toBeUndefined();
expect(result.toolWarnings).toEqual([]);
});
Loading
Loading