-
Notifications
You must be signed in to change notification settings - Fork 179
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
Add Files API #102
Add Files API #102
Conversation
🦋 Changeset detectedLatest commit: 12332d2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 Christina! Looks great!
Added a few comments
mimeType: fileMetadata.mimeType, | ||
}; | ||
uploadMetadata.displayName = fileMetadata.displayName; | ||
uploadMetadata.name = fileMetadata.name; |
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.
nit: Do we want to set the name
and the displayName
at initialization?
const uploadMetadata: FileMetadata = {
mimeType: fileMetadata.mimeType,
displayName:...
};
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.
Done, that is a bit cleaner.
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! We can now remove line 76, 77. and 78-80, right?
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.
Done
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.
LGTM! Thank you.
mimeType: fileMetadata.mimeType, | ||
}; | ||
uploadMetadata.displayName = fileMetadata.displayName; | ||
uploadMetadata.name = fileMetadata.name; |
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! We can now remove line 76, 77. and 78-80, right?
Add file upload API.
GoogleAIFileManager
class with 4 methods:mimeType
, and optionalname
anddisplayName
. Returns full File metadata including name, mimeType, created time, etc (invents a random name if not provided)This is a separate class outside of
GoogleGenerativeAI
and needs to be imported from a subpackage@google/generative-ai/files
. The rationale is that this is meant for Node users only, for security reasons. Also it usesfs
, which will break web builds. Making it a subpackage helps web users avoid importing this code.This means that when instantiating
GoogleAIFileManager
, the user needs to provide the API key to the constructor, even if they've already provided it toGoogleGenerativeAI
. These are essentially two separate tools, one for file management, and one for inference and interaction with the model.The upload content type is multipart, which allows sending JSON metadata as well as the binary blob in the same request. Future improvements may include also offering a resumable upload type (perhaps a separate method). The code for generating the multipart content was taken from the Firebase Storage JS SDK's implementation of multipart upload.
Reference (internal):