From f923ec93394fef16245a83b1bed3a365afa9cc66 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Wed, 14 May 2025 11:32:04 -0400 Subject: [PATCH 1/2] [Firebase AI] Update Gemma candidate token count integration tests --- .../GenerateContentIntegrationTests.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift b/FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift index b90f937b480..048364951a7 100644 --- a/FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift +++ b/FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift @@ -75,21 +75,25 @@ struct GenerateContentIntegrationTests { let usageMetadata = try #require(response.usageMetadata) #expect(usageMetadata.promptTokenCount.isEqual(to: 13, accuracy: tokenCountAccuracy)) - #expect(usageMetadata.candidatesTokenCount.isEqual(to: 3, accuracy: tokenCountAccuracy)) - #expect(usageMetadata.totalTokenCount.isEqual(to: 16, accuracy: tokenCountAccuracy)) #expect(usageMetadata.promptTokensDetails.count == 1) let promptTokensDetails = try #require(usageMetadata.promptTokensDetails.first) #expect(promptTokensDetails.modality == .text) #expect(promptTokensDetails.tokenCount == usageMetadata.promptTokenCount) - // The field `candidatesTokensDetails` is not included when using Gemma models. - if modelName == ModelNames.gemma3_4B { + // The fields `candidatesTokenCount` and `candidatesTokensDetails` are not included when using + // Gemma models. + if modelName.hasPrefix("gemma") { + #expect(usageMetadata.candidatesTokenCount == 0) #expect(usageMetadata.candidatesTokensDetails.isEmpty) } else { + #expect(usageMetadata.candidatesTokenCount.isEqual(to: 3, accuracy: tokenCountAccuracy)) #expect(usageMetadata.candidatesTokensDetails.count == 1) let candidatesTokensDetails = try #require(usageMetadata.candidatesTokensDetails.first) #expect(candidatesTokensDetails.modality == .text) #expect(candidatesTokensDetails.tokenCount == usageMetadata.candidatesTokenCount) } + #expect(usageMetadata.totalTokenCount > 0) + #expect(usageMetadata.totalTokenCount == + (usageMetadata.promptTokenCount + usageMetadata.candidatesTokenCount)) } @Test( From dfd6685e6c150860433b7c85b616764a6142bdbe Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Wed, 14 May 2025 11:45:29 -0400 Subject: [PATCH 2/2] Fix formatting --- .../Tests/Integration/GenerateContentIntegrationTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift b/FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift index 048364951a7..608c28b4833 100644 --- a/FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift +++ b/FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift @@ -93,7 +93,7 @@ struct GenerateContentIntegrationTests { } #expect(usageMetadata.totalTokenCount > 0) #expect(usageMetadata.totalTokenCount == - (usageMetadata.promptTokenCount + usageMetadata.candidatesTokenCount)) + (usageMetadata.promptTokenCount + usageMetadata.candidatesTokenCount)) } @Test(