Skip to content

Commit

Permalink
Add public API tests for GenerateContentResponse (google-gemini#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored and G.Dev.Ssomsak committed Jun 21, 2024
1 parent d4ef430 commit a70783c
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 a70783c

Please sign in to comment.