Skip to content

Commit

Permalink
[Vertex AI] Rename CandidateResponse to Candidate (#13897)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Oct 15, 2024
1 parent 4ca1413 commit 61f2ee3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
- [changed] **Breaking Change**: The `FunctionCallingConfig` initializer and
`Mode` enum are now internal; use one of the new type methods `auto()`,
`any(allowedFunctionNames:)`, or `none()` to create a config. (#13873)
- [changed] **Breaking Change**: The `CandidateResponse` type is now named
`Candidate`. (#13897)
- [changed] The default request timeout is now 180 seconds instead of the
platform-default value of 60 seconds for a `URLRequest`; this timeout may
still be customized in `RequestOptions`. (#13722)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct ErrorDetailsView: View {
let error = GenerateContentError.responseStoppedEarly(
reason: .maxTokens,
response: GenerateContentResponse(candidates: [
CandidateResponse(content: ModelContent(role: "model", parts:
Candidate(content: ModelContent(role: "model", parts:
"""
A _hypothetical_ model response.
Cillum ex aliqua amet aliquip labore amet eiusmod consectetur reprehenderit sit commodo.
Expand Down Expand Up @@ -212,7 +212,7 @@ struct ErrorDetailsView: View {
#Preview("Prompt Blocked") {
let error = GenerateContentError.promptBlocked(
response: GenerateContentResponse(candidates: [
CandidateResponse(content: ModelContent(role: "model", parts:
Candidate(content: ModelContent(role: "model", parts:
"""
A _hypothetical_ model response.
Cillum ex aliqua amet aliquip labore amet eiusmod consectetur reprehenderit sit commodo.
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sample/ChatSample/Views/ErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct ErrorView: View {
let errorPromptBlocked = GenerateContentError.promptBlocked(
response: GenerateContentResponse(
candidates: [
CandidateResponse(
Candidate(
content: ModelContent(role: "model", parts: [
"""
A _hypothetical_ model response.
Expand Down
10 changes: 5 additions & 5 deletions FirebaseVertexAI/Sources/GenerateContentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct GenerateContentResponse: Sendable {
}

/// A list of candidate response content, ordered from best to worst.
public let candidates: [CandidateResponse]
public let candidates: [Candidate]

/// A value containing the safety ratings for the response, or, if the request was blocked, a
/// reason for blocking the request.
Expand Down Expand Up @@ -82,7 +82,7 @@ public struct GenerateContentResponse: Sendable {
}

/// Initializer for SwiftUI previews or tests.
public init(candidates: [CandidateResponse], promptFeedback: PromptFeedback? = nil,
public init(candidates: [Candidate], promptFeedback: PromptFeedback? = nil,
usageMetadata: UsageMetadata? = nil) {
self.candidates = candidates
self.promptFeedback = promptFeedback
Expand All @@ -93,7 +93,7 @@ public struct GenerateContentResponse: Sendable {
/// A struct representing a possible reply to a content generation prompt. Each content generation
/// prompt may produce multiple candidate responses.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct CandidateResponse: Sendable {
public struct Candidate: Sendable {
/// The response's content.
public let content: ModelContent

Expand Down Expand Up @@ -279,7 +279,7 @@ extension GenerateContentResponse: Decodable {
}

if let candidates = try container.decodeIfPresent(
[CandidateResponse].self,
[Candidate].self,
forKey: .candidates
) {
self.candidates = candidates
Expand Down Expand Up @@ -309,7 +309,7 @@ extension GenerateContentResponse.UsageMetadata: Decodable {
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension CandidateResponse: Decodable {
extension Candidate: Decodable {
enum CodingKeys: CodingKey {
case content
case safetyRatings
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ final class VertexAIAPITests: XCTestCase {
func generateContentResponseAPI() {
let response = GenerateContentResponse(candidates: [])

let _: [CandidateResponse] = response.candidates
let _: [Candidate] = response.candidates
let _: PromptFeedback? = response.promptFeedback

// Usage Metadata
Expand Down

0 comments on commit 61f2ee3

Please sign in to comment.