Skip to content

Commit a2e7116

Browse files
committed
Integration test, minor build fixes, and style
1 parent 4ecc372 commit a2e7116

File tree

3 files changed

+43
-40
lines changed

3 files changed

+43
-40
lines changed

FirebaseVertexAI/Sources/GenerateContentResponse.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ public struct GenerateContentResponse: Sendable {
105105
return nil
106106
}
107107
}
108-
if inlineData.isEmpty {
109-
VertexLog.warning(
110-
code: .generateContentResponseNoInlineData,
111-
"Could not find any inline data parts in the first candidate."
112-
)
113-
}
114108
return inlineData
115109
}
116110

FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ struct GenerateContentIntegrationTests {
149149
let candidate = try #require(response.candidates.first)
150150
let inlineDataPart = try #require(candidate.content.parts
151151
.first { $0 is InlineDataPart } as? InlineDataPart)
152+
let inlineDataPartsViaAccessor = response.inlineDataParts
153+
#expect(inlineDataPartsViaAccessor.count == 1)
154+
let inlineDataPartViaAccessor = try #require(inlineDataPartsViaAccessor.first)
155+
#expect(inlineDataPart == inlineDataPartViaAccessor)
152156
#expect(inlineDataPart.mimeType == "image/png")
153157
#expect(inlineDataPart.data.count > 0)
154158
#if canImport(UIKit)

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ final class GenerativeModelTests: XCTestCase {
15431543
func testGenerateContentResponse_inlineDataParts_success() throws {
15441544
// 1. Create mock parts
15451545
let imageData = Data("sample image data".utf8) // Placeholder data
1546-
let inlineDataPart = InlineDataPart(mimeType: "image/png", data: imageData)
1546+
let inlineDataPart = InlineDataPart(data: imageData, mimeType: "image/png")
15471547
let textPart = TextPart("This is the text part.")
15481548

15491549
// 2. Create ModelContent
@@ -1574,56 +1574,61 @@ final class GenerativeModelTests: XCTestCase {
15741574
XCTAssertEqual(response.text, "This is the text part.")
15751575

15761576
// 7. Assertion for function calls (ensure it's empty)
1577-
XCTAssertTrue(response.functionCalls.isEmpty, "functionCalls should be empty.")
1577+
XCTAssertTrue(response.functionCalls.isEmpty, "functionCalls should be empty.")
15781578
}
15791579

15801580
func testGenerateContentResponse_inlineDataParts_noInlineData() throws {
1581-
// 1. Create mock parts (only text)
1582-
let textPart = TextPart("This is the text part.")
1583-
let funcCallPart = FunctionCallPart(name: "testFunc", args: nil) // Add another part type
1581+
// 1. Create mock parts (only text)
1582+
let textPart = TextPart("This is the text part.")
1583+
let funcCallPart = FunctionCallPart(name: "testFunc", args: [:]) // Add another part type
15841584

1585-
// 2. Create ModelContent
1586-
let modelContent = ModelContent(parts: [textPart, funcCallPart])
1585+
// 2. Create ModelContent
1586+
let modelContent = ModelContent(parts: [textPart, funcCallPart])
15871587

1588-
// 3. Create Candidate
1589-
let candidate = Candidate(
1590-
content: modelContent,
1591-
safetyRatings: [],
1592-
finishReason: .stop,
1593-
citationMetadata: nil
1594-
)
1588+
// 3. Create Candidate
1589+
let candidate = Candidate(
1590+
content: modelContent,
1591+
safetyRatings: [],
1592+
finishReason: .stop,
1593+
citationMetadata: nil
1594+
)
15951595

1596-
// 4. Create GenerateContentResponse
1597-
let response = GenerateContentResponse(candidates: [candidate])
1596+
// 4. Create GenerateContentResponse
1597+
let response = GenerateContentResponse(candidates: [candidate])
15981598

1599-
// 5. Assertions for inlineDataParts
1600-
let inlineParts = response.inlineDataParts
1601-
XCTAssertTrue(inlineParts.isEmpty, "inlineDataParts should be empty.")
1599+
// 5. Assertions for inlineDataParts
1600+
let inlineParts = response.inlineDataParts
1601+
XCTAssertTrue(inlineParts.isEmpty, "inlineDataParts should be empty.")
16021602

1603-
// 6. Assertion for text
1604-
XCTAssertEqual(response.text, "This is the text part.")
1603+
// 6. Assertion for text
1604+
XCTAssertEqual(response.text, "This is the text part.")
16051605

1606-
// 7. Assertion for function calls
1607-
XCTAssertEqual(response.functionCalls.count, 1)
1608-
XCTAssertEqual(response.functionCalls.first?.name, "testFunc")
1606+
// 7. Assertion for function calls
1607+
XCTAssertEqual(response.functionCalls.count, 1)
1608+
XCTAssertEqual(response.functionCalls.first?.name, "testFunc")
16091609
}
16101610

16111611
func testGenerateContentResponse_inlineDataParts_noCandidates() throws {
1612-
// 1. Create GenerateContentResponse with no candidates
1613-
let response = GenerateContentResponse(candidates: [])
1612+
// 1. Create GenerateContentResponse with no candidates
1613+
let response = GenerateContentResponse(candidates: [])
16141614

1615-
// 2. Assertions for inlineDataParts
1616-
let inlineParts = response.inlineDataParts
1617-
XCTAssertTrue(inlineParts.isEmpty, "inlineDataParts should be empty when there are no candidates.")
1615+
// 2. Assertions for inlineDataParts
1616+
let inlineParts = response.inlineDataParts
1617+
XCTAssertTrue(
1618+
inlineParts.isEmpty,
1619+
"inlineDataParts should be empty when there are no candidates."
1620+
)
16181621

1619-
// 3. Assertion for text
1620-
XCTAssertNil(response.text, "Text should be nil when there are no candidates.")
1622+
// 3. Assertion for text
1623+
XCTAssertNil(response.text, "Text should be nil when there are no candidates.")
16211624

1622-
// 4. Assertion for function calls
1623-
XCTAssertTrue(response.functionCalls.isEmpty, "functionCalls should be empty when there are no candidates.")
1625+
// 4. Assertion for function calls
1626+
XCTAssertTrue(
1627+
response.functionCalls.isEmpty,
1628+
"functionCalls should be empty when there are no candidates."
1629+
)
16241630
}
16251631

1626-
16271632
// MARK: - Helpers
16281633

16291634
private func testFirebaseInfo(appCheck: AppCheckInterop? = nil,

0 commit comments

Comments
 (0)