Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generative-ai-swift tests in Vertex AI #12585

Merged
merged 4 commits into from
Mar 19, 2024
Merged

Conversation

andrewheard
Copy link
Contributor

@andrewheard andrewheard commented Mar 19, 2024

  • Added an SPM test target and xcscheme named FirebaseVertexAIUnit
  • Updated existing tests for Vertex AI
  • Removed unused JSON payloads
  • Updated CI workflow to run unit tests

#no-changelog

@andrewheard andrewheard marked this pull request as ready for review March 19, 2024 18:24
Copy link
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Feel free to defer any of my comments to future PRs.

apiKey: "API_KEY",
generationConfig: config, // Optional
safetySettings: filters // Optional
// TODO: Change `genAI` to `_` when safetySettings and generationConfig are added to public API.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's preventing them from being added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll just need to check those parameters (and requestOptions) when determining if it's the same instance in VertexAIComponent:

// MARK: - VertexAIProvider conformance
func vertexAI(location: String, modelResourceName: String) -> VertexAI {
os_unfair_lock_lock(&instancesLock)
// Unlock before the function returns.
defer { os_unfair_lock_unlock(&instancesLock) }
if let instance = instances[modelResourceName] {
return instance
}
let newInstance = VertexAI(app: app, location: location, modelResourceName: modelResourceName)
instances[modelResourceName] = newInstance
return newInstance
}

Note: Those parameters are currently all structs so I can't use them with @objc in their current form (might be able to use the [String:Any] trick that Morgan mentioned).

FirebaseVertexAI/Tests/Unit/ChatTests.swift Show resolved Hide resolved
} catch let GenerateContentError.internalError(error as RPCError) {
XCTAssertEqual(error.httpResponseCode, 400)
XCTAssertEqual(error.status, .invalidArgument)
XCTAssertEqual(error.message, "API key not valid. Please pass a valid API key.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can Vertex have an invalid API key? Shouldn't there be a message about a GoogleService-Info.plist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only happen if the API key in the GoogleService-Info.plist is invalid (e.g., if the key was revoked after the app was shipped). The message/code/status checked here are the ones returned by the backend. I don't think we have specific error cases for revoked/invalid API keys in our other SDKs (everything would be broken in that scenario), which was why I removed the case that was in https://github.com/google/generative-ai-swift/blob/48a0c2f11935a17132492583d4aad51c5a407bcb/Sources/GoogleAI/GenerateContentError.swift#L32-L33 but we could bring it back.

@andrewheard andrewheard merged commit c68e1e3 into vertex-ai Mar 19, 2024
52 checks passed
@andrewheard andrewheard deleted the ah/vertex-ai-tests branch March 19, 2024 20:59
paulb777 pushed a commit that referenced this pull request Apr 2, 2024
@firebase firebase locked and limited conversation to collaborators Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants