Skip to content

Commit

Permalink
Add public API tests for GenerateContentResponse (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Apr 16, 2024
1 parent 9156ed7 commit fad5c49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerateContentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public struct GenerateContentResponse {
}

/// Initializer for SwiftUI previews or tests.
public init(candidates: [CandidateResponse], promptFeedback: PromptFeedback?) {
public init(candidates: [CandidateResponse], promptFeedback: PromptFeedback? = nil) {
self.candidates = candidates
self.promptFeedback = promptFeedback
}
Expand Down
12 changes: 12 additions & 0 deletions Tests/GoogleAITests/GoogleAITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ final class GoogleGenerativeAITests: XCTestCase {
_ = genAI.startChat(history: [ModelContent(parts: "abc")])
}

// Public API tests for GenerateContentResponse.
func generateContentResponseAPI() {
let response = GenerateContentResponse(candidates: [])

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

// Computed Properties
let _: String? = response.text
let _: [FunctionCall] = response.functionCalls
}

// Result builder alternative

/*
Expand Down

0 comments on commit fad5c49

Please sign in to comment.