Skip to content

Commit 86f06be

Browse files
committed
Simplify generateContentThinkingFunctionCalling test
1 parent 323e33b commit 86f06be

File tree

1 file changed

+13
-46
lines changed

1 file changed

+13
-46
lines changed

FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,6 @@ struct GenerateContentIntegrationTests {
253253
)
254254
func generateContentThinkingFunctionCalling(_ config: InstanceConfig, modelName: String,
255255
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-
)
261256
let getTemperatureDeclaration = FunctionDeclaration(
262257
name: "getTemperature",
263258
description: "Returns the current temperature in Celsius for the specified location",
@@ -276,80 +271,52 @@ struct GenerateContentIntegrationTests {
276271
thinkingConfig: thinkingConfig
277272
),
278273
safetySettings: safetySettings,
279-
tools: [.functionDeclarations([currentLocationDeclaration, getTemperatureDeclaration])],
274+
tools: [.functionDeclarations([getTemperatureDeclaration])],
280275
systemInstruction: ModelContent(parts: """
281276
You are a weather bot that specializes in reporting outdoor temperatures in Celsius.
282277
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.
288279
289280
Always respond in the format:
290281
- Location: City, Province/State, Country
291282
- Temperature: #C
292283
""")
293284
)
294285
let chat = model.startChat()
295-
let prompt = "What is the current temperature?"
286+
let prompt = "What is the current temperature in Waterloo, Ontario, Canada?"
296287

297288
let response = try await chat.sendMessage(prompt)
298289

299-
var thoughtSignatureCount = 0
300290
#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)
322292
try #require(temperatureFunctionCall.name == getTemperatureDeclaration.name)
323293
#expect(temperatureFunctionCall.args == [
324294
"city": .string("Waterloo"),
325295
"region": .string("Ontario"),
326296
"country": .string("Canada"),
327297
])
328298
#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)
331304
}
332305

333306
let temperatureFunctionResponse = FunctionResponsePart(
334-
name: locationFunctionCall.name,
307+
name: temperatureFunctionCall.name,
335308
response: [
336309
"temperature": .number(25),
337310
"units": .string("Celsius"),
338311
]
339312
)
340313

341-
let response3 = try await chat.sendMessage(temperatureFunctionResponse)
314+
let response2 = try await chat.sendMessage(temperatureFunctionResponse)
342315

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)
345318
#expect(finalText.contains("Waterloo"))
346319
#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-
}
353320
}
354321

355322
@Test(arguments: [

0 commit comments

Comments
 (0)