From fc36a9b88cd76bf61e6fa9fc2b6873a794b56ff1 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Mon, 23 Sep 2024 18:27:59 -0400 Subject: [PATCH 1/3] [Vertex AI] Rename `CitationMetadata.citationSources` to `citations` --- FirebaseVertexAI/Sources/GenerateContentResponse.swift | 2 +- FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FirebaseVertexAI/Sources/GenerateContentResponse.swift b/FirebaseVertexAI/Sources/GenerateContentResponse.swift index d1aeb58bd56..735f9bf77e1 100644 --- a/FirebaseVertexAI/Sources/GenerateContentResponse.swift +++ b/FirebaseVertexAI/Sources/GenerateContentResponse.swift @@ -113,7 +113,7 @@ public struct CandidateResponse: Sendable { @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) public struct CitationMetadata: Sendable { /// A list of individual cited sources and the parts of the content to which they apply. - public let citationSources: [Citation] + public let citations: [Citation] } /// A struct describing a source attribution. diff --git a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift index b01d62b90f0..0c66effb9ac 100644 --- a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift +++ b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift @@ -113,20 +113,20 @@ final class GenerativeModelTests: XCTestCase { XCTAssertEqual(candidate.content.parts.count, 1) XCTAssertEqual(response.text, "Some information cited from an external source") let citationMetadata = try XCTUnwrap(candidate.citationMetadata) - XCTAssertEqual(citationMetadata.citationSources.count, 3) - let citationSource1 = try XCTUnwrap(citationMetadata.citationSources[0]) + XCTAssertEqual(citationMetadata.citations.count, 3) + let citationSource1 = try XCTUnwrap(citationMetadata.citations[0]) XCTAssertEqual(citationSource1.uri, "https://www.example.com/some-citation-1") XCTAssertEqual(citationSource1.startIndex, 0) XCTAssertEqual(citationSource1.endIndex, 128) XCTAssertNil(citationSource1.title) XCTAssertNil(citationSource1.license) - let citationSource2 = try XCTUnwrap(citationMetadata.citationSources[1]) + let citationSource2 = try XCTUnwrap(citationMetadata.citations[1]) XCTAssertEqual(citationSource2.title, "some-citation-2") XCTAssertEqual(citationSource2.startIndex, 130) XCTAssertEqual(citationSource2.endIndex, 265) XCTAssertNil(citationSource2.uri) XCTAssertNil(citationSource2.license) - let citationSource3 = try XCTUnwrap(citationMetadata.citationSources[2]) + let citationSource3 = try XCTUnwrap(citationMetadata.citations[2]) XCTAssertEqual(citationSource3.uri, "https://www.example.com/some-citation-3") XCTAssertEqual(citationSource3.startIndex, 272) XCTAssertEqual(citationSource3.endIndex, 431) @@ -947,7 +947,7 @@ final class GenerativeModelTests: XCTestCase { responses.append(content) XCTAssertNotNil(content.text) let candidate = try XCTUnwrap(content.candidates.first) - if let sources = candidate.citationMetadata?.citationSources { + if let sources = candidate.citationMetadata?.citations { citations.append(contentsOf: sources) } } From 66f12ba24fb6f94d4855fbd5e9e6beaab5c13462 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Mon, 23 Sep 2024 18:31:07 -0400 Subject: [PATCH 2/3] Fix `CitationMetadata` `Decodable` implementation --- FirebaseVertexAI/Sources/GenerateContentResponse.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/FirebaseVertexAI/Sources/GenerateContentResponse.swift b/FirebaseVertexAI/Sources/GenerateContentResponse.swift index 735f9bf77e1..31566889a0c 100644 --- a/FirebaseVertexAI/Sources/GenerateContentResponse.swift +++ b/FirebaseVertexAI/Sources/GenerateContentResponse.swift @@ -290,11 +290,7 @@ extension CandidateResponse: Decodable { } @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) -extension CitationMetadata: Decodable { - enum CodingKeys: String, CodingKey { - case citationSources = "citations" - } -} +extension CitationMetadata: Decodable {} @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) extension Citation: Decodable { From 8aec581c9c2c604ebf616ebd88ac8c2d0fe349b5 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Mon, 23 Sep 2024 18:33:26 -0400 Subject: [PATCH 3/3] Add CHANGELOG entry --- FirebaseVertexAI/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index a7f96d5512f..0286d0e0e74 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -7,6 +7,8 @@ - [changed] **Breaking Change**: The `unspecified` case has been removed from the `FinishReason`, `PromptFeedback` and `HarmProbability` enums; this scenario is now handled by the existing `unknown` case. (#13699) +- [changed] **Breaking Change**: The property `citationSources` of + `CitationMetadata` has been renamed to `citations`. (#13702) # 11.3.0 - [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)