|
1 | 1 | import { expect, it } from 'vitest'; |
2 | 2 | import { prepareTools } from './google-prepare-tools'; |
| 3 | +import { LanguageModelV3ProviderDefinedTool } from '@ai-sdk/provider'; |
3 | 4 |
|
4 | 5 | it('should return undefined tools and tool_choice when tools are null', () => { |
5 | 6 | const result = prepareTools({ |
@@ -62,10 +63,24 @@ it('should correctly prepare provider-defined tools as array', () => { |
62 | 63 | name: 'url_context', |
63 | 64 | args: {}, |
64 | 65 | }, |
| 66 | + { |
| 67 | + type: 'provider-defined', |
| 68 | + id: 'google.file_search', |
| 69 | + name: 'file_search', |
| 70 | + args: { fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'] }, |
| 71 | + }, |
65 | 72 | ], |
66 | 73 | modelId: 'gemini-2.5-flash', |
67 | 74 | }); |
68 | | - expect(result.tools).toEqual([{ googleSearch: {} }, { urlContext: {} }]); |
| 75 | + expect(result.tools).toEqual([ |
| 76 | + { googleSearch: {} }, |
| 77 | + { urlContext: {} }, |
| 78 | + { |
| 79 | + fileSearch: { |
| 80 | + fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'], |
| 81 | + }, |
| 82 | + }, |
| 83 | + ]); |
69 | 84 | expect(result.toolConfig).toBeUndefined(); |
70 | 85 | expect(result.toolWarnings).toEqual([]); |
71 | 86 | }); |
@@ -116,6 +131,69 @@ it('should add warnings for unsupported tools', () => { |
116 | 131 | `); |
117 | 132 | }); |
118 | 133 |
|
| 134 | +it('should add warnings for file search on unsupported models', () => { |
| 135 | + const tool: LanguageModelV3ProviderDefinedTool = { |
| 136 | + type: 'provider-defined' as const, |
| 137 | + id: 'google.file_search', |
| 138 | + name: 'file_search', |
| 139 | + args: { fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'] }, |
| 140 | + }; |
| 141 | + |
| 142 | + const result = prepareTools({ |
| 143 | + tools: [tool], |
| 144 | + modelId: 'gemini-1.5-flash-8b', |
| 145 | + }); |
| 146 | + |
| 147 | + expect(result.tools).toBeUndefined(); |
| 148 | + expect(result.toolWarnings).toMatchInlineSnapshot(` |
| 149 | + [ |
| 150 | + { |
| 151 | + "details": "The file search tool is only supported with Gemini 2.5 models.", |
| 152 | + "tool": { |
| 153 | + "args": { |
| 154 | + "fileSearchStoreNames": [ |
| 155 | + "projects/foo/fileSearchStores/bar", |
| 156 | + ], |
| 157 | + }, |
| 158 | + "id": "google.file_search", |
| 159 | + "name": "file_search", |
| 160 | + "type": "provider-defined", |
| 161 | + }, |
| 162 | + "type": "unsupported-tool", |
| 163 | + }, |
| 164 | + ] |
| 165 | + `); |
| 166 | +}); |
| 167 | + |
| 168 | +it('should correctly prepare file search tool', () => { |
| 169 | + const result = prepareTools({ |
| 170 | + tools: [ |
| 171 | + { |
| 172 | + type: 'provider-defined', |
| 173 | + id: 'google.file_search', |
| 174 | + name: 'file_search', |
| 175 | + args: { |
| 176 | + fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'], |
| 177 | + metadataFilter: 'author=Robert Graves', |
| 178 | + topK: 5, |
| 179 | + }, |
| 180 | + }, |
| 181 | + ], |
| 182 | + modelId: 'gemini-2.5-pro', |
| 183 | + }); |
| 184 | + |
| 185 | + expect(result.tools).toEqual([ |
| 186 | + { |
| 187 | + fileSearch: { |
| 188 | + fileSearchStoreNames: ['projects/foo/fileSearchStores/bar'], |
| 189 | + metadataFilter: 'author=Robert Graves', |
| 190 | + topK: 5, |
| 191 | + }, |
| 192 | + }, |
| 193 | + ]); |
| 194 | + expect(result.toolWarnings).toEqual([]); |
| 195 | +}); |
| 196 | + |
119 | 197 | it('should handle tool choice "auto"', () => { |
120 | 198 | const result = prepareTools({ |
121 | 199 | tools: [ |
|
0 commit comments