|
3 | 3 | * Copyright 2025 Google LLC |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | | -import {shouldAppendAfcHistory, shouldDisableAfc} from '../../src/_afc.js'; |
| 6 | +import { |
| 7 | + findAfcIncompatibleToolIndexes, |
| 8 | + shouldAppendAfcHistory, |
| 9 | + shouldDisableAfc, |
| 10 | +} from '../../src/_afc.js'; |
7 | 11 | import * as types from '../../src/types.js'; |
8 | 12 |
|
9 | 13 | const callableTool: types.CallableTool = { |
@@ -155,3 +159,189 @@ describe('afc_test', () => { |
155 | 159 | expect(shouldAppendAfcHistory(config)).toBeFalse(); |
156 | 160 | }); |
157 | 161 | }); |
| 162 | + |
| 163 | +describe('findAfcIncompatibleToolIndexes', () => { |
| 164 | + it('should return empty list when there is no config', () => { |
| 165 | + expect(findAfcIncompatibleToolIndexes(undefined)).toEqual([]); |
| 166 | + }); |
| 167 | + it('should return empty list when there is no tools', () => { |
| 168 | + const params: types.GenerateContentParameters = { |
| 169 | + model: 'gemini-2.0-flash', |
| 170 | + contents: 'why is the sky blue?', |
| 171 | + config: {}, |
| 172 | + }; |
| 173 | + expect(findAfcIncompatibleToolIndexes(params)).toEqual([]); |
| 174 | + }); |
| 175 | + it('should return empty list when there are no functiondeclaration filed in the tools', () => { |
| 176 | + const params: types.GenerateContentParameters = { |
| 177 | + model: 'gemini-2.0-flash', |
| 178 | + contents: 'why is the sky blue?', |
| 179 | + config: { |
| 180 | + tools: [{} as types.Tool], |
| 181 | + }, |
| 182 | + }; |
| 183 | + expect(findAfcIncompatibleToolIndexes(params)).toEqual([]); |
| 184 | + }); |
| 185 | + it('should return empty list when there are no function declarations', () => { |
| 186 | + const params: types.GenerateContentParameters = { |
| 187 | + model: 'gemini-2.0-flash', |
| 188 | + contents: 'why is the sky blue?', |
| 189 | + config: { |
| 190 | + tools: [{functionDeclarations: []} as types.Tool], |
| 191 | + }, |
| 192 | + }; |
| 193 | + expect(findAfcIncompatibleToolIndexes(params)).toEqual([]); |
| 194 | + }); |
| 195 | + it('should return empty list when there function declarations is undefined', () => { |
| 196 | + const params: types.GenerateContentParameters = { |
| 197 | + model: 'gemini-2.0-flash', |
| 198 | + contents: 'why is the sky blue?', |
| 199 | + config: { |
| 200 | + tools: [{functionDeclarations: undefined} as types.Tool], |
| 201 | + }, |
| 202 | + }; |
| 203 | + expect(findAfcIncompatibleToolIndexes(params)).toEqual([]); |
| 204 | + }); |
| 205 | + it('should return empty list when there are no incompatible tools', () => { |
| 206 | + const params: types.GenerateContentParameters = { |
| 207 | + model: 'gemini-2.0-flash', |
| 208 | + contents: 'why is the sky blue?', |
| 209 | + config: { |
| 210 | + tools: [ |
| 211 | + callableTool, |
| 212 | + { |
| 213 | + retrieval: { |
| 214 | + disableAttribution: true, |
| 215 | + }, |
| 216 | + }, |
| 217 | + { |
| 218 | + googleSearch: {}, |
| 219 | + }, |
| 220 | + { |
| 221 | + googleSearchRetrieval: {}, |
| 222 | + }, |
| 223 | + { |
| 224 | + enterpriseWebSearch: {}, |
| 225 | + }, |
| 226 | + { |
| 227 | + googleMaps: {}, |
| 228 | + }, |
| 229 | + { |
| 230 | + urlContext: {}, |
| 231 | + }, |
| 232 | + { |
| 233 | + computerUse: {}, |
| 234 | + }, |
| 235 | + { |
| 236 | + codeExecution: {}, |
| 237 | + }, |
| 238 | + ], |
| 239 | + }, |
| 240 | + }; |
| 241 | + expect(findAfcIncompatibleToolIndexes(params)).toEqual([]); |
| 242 | + }); |
| 243 | + it('should return correct indexes when there are only one incompatible tools', () => { |
| 244 | + const params: types.GenerateContentParameters = { |
| 245 | + model: 'gemini-2.0-flash', |
| 246 | + contents: 'why is the sky blue?', |
| 247 | + config: { |
| 248 | + tools: [ |
| 249 | + callableTool, |
| 250 | + { |
| 251 | + retrieval: { |
| 252 | + disableAttribution: true, |
| 253 | + }, |
| 254 | + }, |
| 255 | + { |
| 256 | + googleSearch: {}, |
| 257 | + }, |
| 258 | + { |
| 259 | + googleSearchRetrieval: {}, |
| 260 | + }, |
| 261 | + { |
| 262 | + functionDeclarations: [ |
| 263 | + { |
| 264 | + name: 'test_function_1', |
| 265 | + }, |
| 266 | + ], |
| 267 | + }, |
| 268 | + { |
| 269 | + enterpriseWebSearch: {}, |
| 270 | + }, |
| 271 | + { |
| 272 | + googleMaps: {}, |
| 273 | + }, |
| 274 | + { |
| 275 | + urlContext: {}, |
| 276 | + }, |
| 277 | + { |
| 278 | + computerUse: {}, |
| 279 | + }, |
| 280 | + { |
| 281 | + codeExecution: {}, |
| 282 | + }, |
| 283 | + ], |
| 284 | + }, |
| 285 | + }; |
| 286 | + expect(findAfcIncompatibleToolIndexes(params)).toEqual([4]); |
| 287 | + }); |
| 288 | + it('should return correct indexes when there are incompatible tools', () => { |
| 289 | + const params: types.GenerateContentParameters = { |
| 290 | + model: 'gemini-2.0-flash', |
| 291 | + contents: 'why is the sky blue?', |
| 292 | + config: { |
| 293 | + tools: [ |
| 294 | + callableTool, |
| 295 | + { |
| 296 | + retrieval: { |
| 297 | + disableAttribution: true, |
| 298 | + }, |
| 299 | + }, |
| 300 | + { |
| 301 | + googleSearch: {}, |
| 302 | + }, |
| 303 | + { |
| 304 | + googleSearchRetrieval: {}, |
| 305 | + }, |
| 306 | + { |
| 307 | + functionDeclarations: [ |
| 308 | + { |
| 309 | + name: 'test_function_1', |
| 310 | + }, |
| 311 | + ], |
| 312 | + }, |
| 313 | + { |
| 314 | + enterpriseWebSearch: {}, |
| 315 | + }, |
| 316 | + { |
| 317 | + googleMaps: {}, |
| 318 | + }, |
| 319 | + { |
| 320 | + urlContext: {}, |
| 321 | + }, |
| 322 | + { |
| 323 | + computerUse: {}, |
| 324 | + }, |
| 325 | + { |
| 326 | + codeExecution: {}, |
| 327 | + }, |
| 328 | + { |
| 329 | + functionDeclarations: [ |
| 330 | + { |
| 331 | + name: 'test_function_2', |
| 332 | + }, |
| 333 | + ], |
| 334 | + }, |
| 335 | + { |
| 336 | + functionDeclarations: [ |
| 337 | + { |
| 338 | + name: 'test_function_3', |
| 339 | + }, |
| 340 | + ], |
| 341 | + }, |
| 342 | + ], |
| 343 | + }, |
| 344 | + }; |
| 345 | + expect(findAfcIncompatibleToolIndexes(params)).toEqual([4, 10, 11]); |
| 346 | + }); |
| 347 | +}); |
0 commit comments