@@ -253,11 +253,6 @@ struct GenerateContentIntegrationTests {
253
253
)
254
254
func generateContentThinkingFunctionCalling( _ config: InstanceConfig , modelName: String ,
255
255
thinkingConfig: ThinkingConfig ) async throws {
256
- let currentLocationDeclaration = FunctionDeclaration (
257
- name: " getCurrentLocation " ,
258
- description: " Returns the user's current city, province or state, and country " ,
259
- parameters: [ : ]
260
- )
261
256
let getTemperatureDeclaration = FunctionDeclaration (
262
257
name: " getTemperature " ,
263
258
description: " Returns the current temperature in Celsius for the specified location " ,
@@ -276,80 +271,52 @@ struct GenerateContentIntegrationTests {
276
271
thinkingConfig: thinkingConfig
277
272
) ,
278
273
safetySettings: safetySettings,
279
- tools: [ . functionDeclarations( [ currentLocationDeclaration , getTemperatureDeclaration] ) ] ,
274
+ tools: [ . functionDeclarations( [ getTemperatureDeclaration] ) ] ,
280
275
systemInstruction: ModelContent ( parts: """
281
276
You are a weather bot that specializes in reporting outdoor temperatures in Celsius.
282
277
283
- If not specified, assume that the user is asking for the temperature in their current \
284
- location. Use the `getCurrentLocation` function to determine the user's location. Always use the \
285
- `getTemperature` function to determine the current outdoor temperature in a location. You \
286
- can use the output of the `getCurrentLocation` function as input to the `getTemperature` \
287
- function to get the temperature in the user's location.
278
+ Always use the `getTemperature` function to determine the current temperature in a location.
288
279
289
280
Always respond in the format:
290
281
- Location: City, Province/State, Country
291
282
- Temperature: #C
292
283
""" )
293
284
)
294
285
let chat = model. startChat ( )
295
- let prompt = " What is the current temperature? "
286
+ let prompt = " What is the current temperature in Waterloo, Ontario, Canada ? "
296
287
297
288
let response = try await chat. sendMessage ( prompt)
298
289
299
- var thoughtSignatureCount = 0
300
290
#expect( response. functionCalls. count == 1 )
301
- let locationFunctionCall = try #require( response. functionCalls. first)
302
- try #require( locationFunctionCall. name == currentLocationDeclaration. name)
303
- #expect( locationFunctionCall. args. isEmpty)
304
- #expect( locationFunctionCall. isThought == false )
305
- if locationFunctionCall. thoughtSignature != nil {
306
- thoughtSignatureCount += 1
307
- }
308
-
309
- let locationFunctionResponse = FunctionResponsePart (
310
- name: locationFunctionCall. name,
311
- response: [
312
- " city " : . string( " Waterloo " ) ,
313
- " province " : . string( " Ontario " ) ,
314
- " country " : . string( " Canada " ) ,
315
- ]
316
- )
317
-
318
- let response2 = try await chat. sendMessage ( locationFunctionResponse)
319
-
320
- #expect( response2. functionCalls. count == 1 )
321
- let temperatureFunctionCall = try #require( response2. functionCalls. first)
291
+ let temperatureFunctionCall = try #require( response. functionCalls. first)
322
292
try #require( temperatureFunctionCall. name == getTemperatureDeclaration. name)
323
293
#expect( temperatureFunctionCall. args == [
324
294
" city " : . string( " Waterloo " ) ,
325
295
" region " : . string( " Ontario " ) ,
326
296
" country " : . string( " Canada " ) ,
327
297
] )
328
298
#expect( temperatureFunctionCall. isThought == false )
329
- if temperatureFunctionCall. thoughtSignature != nil {
330
- thoughtSignatureCount += 1
299
+ if let _ = thinkingConfig. includeThoughts, case . googleAI = config. apiConfig. service {
300
+ let thoughtSignature = try #require( temperatureFunctionCall. thoughtSignature)
301
+ #expect( !thoughtSignature. isEmpty)
302
+ } else {
303
+ #expect( temperatureFunctionCall. thoughtSignature == nil )
331
304
}
332
305
333
306
let temperatureFunctionResponse = FunctionResponsePart (
334
- name: locationFunctionCall . name,
307
+ name: temperatureFunctionCall . name,
335
308
response: [
336
309
" temperature " : . number( 25 ) ,
337
310
" units " : . string( " Celsius " ) ,
338
311
]
339
312
)
340
313
341
- let response3 = try await chat. sendMessage ( temperatureFunctionResponse)
314
+ let response2 = try await chat. sendMessage ( temperatureFunctionResponse)
342
315
343
- #expect( response3 . functionCalls. isEmpty)
344
- let finalText = try #require( response3 . text) . trimmingCharacters ( in: . whitespacesAndNewlines)
316
+ #expect( response2 . functionCalls. isEmpty)
317
+ let finalText = try #require( response2 . text) . trimmingCharacters ( in: . whitespacesAndNewlines)
345
318
#expect( finalText. contains ( " Waterloo " ) )
346
319
#expect( finalText. contains ( " 25 " ) )
347
-
348
- if let _ = thinkingConfig. includeThoughts, case . googleAI = config. apiConfig. service {
349
- #expect( thoughtSignatureCount > 0 )
350
- } else {
351
- #expect( thoughtSignatureCount == 0 )
352
- }
353
320
}
354
321
355
322
@Test ( arguments: [
0 commit comments