-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
:
firebase-ios-sdk/FirebaseVertexAI/Sources/VertexAIComponent.swift
Lines 65 to 79 in aa474f5
// 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).
} 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.") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
FirebaseVertexAIUnit
#no-changelog