Skip to content

Commit

Permalink
genai: improve file upload doc (#183)
Browse files Browse the repository at this point in the history
For #180.
  • Loading branch information
jba authored Jul 18, 2024
1 parent 4a683d2 commit ae10a3a
Show file tree
Hide file tree
Showing 4 changed files with 3,256 additions and 3,234 deletions.
10 changes: 8 additions & 2 deletions genai/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ types:
fields:
MimeType:
name: MIMEType
doc: |
The IANA standard MIME type of the source data.
If present, this overrides the MIME type specified or inferred
when the file was uploaded.
The supported MIME types are documented on [this page].
[this page]: https://ai.google.dev/gemini-api/docs/prompting_with_media?lang=go#supported_file_formats
FileUri:
name: URI
# TODO(jba): support field doc in protoveneer
# doc: 'The URI returned from UploadFile or GetFile.'
doc: 'The URI returned from UploadFile or GetFile.'

GenerationConfig:
fields:
Expand Down
17 changes: 14 additions & 3 deletions genai/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,27 @@ import (

// UploadFileOptions are options for [Client.UploadFile].
type UploadFileOptions struct {
DisplayName string // a more readable name for the file
MIMEType string // the MIME type of the file; if omitted, it will be inferred
// A more readable name for the file.
DisplayName string

// The IANA standard MIME type of the file. It will be stored with the file as metadata.
// If omitted, the service will try to infer it. You may instead wish to use
// [http.DetectContentType].
// The supported MIME types are documented on [this page].
//
// [this page]: https://ai.google.dev/gemini-api/docs/prompting_with_media?lang=go#supported_file_formats
MIMEType string
}

// UploadFile copies the contents of the given io.Reader to file storage associated
// with the service, and returns information about the resulting file.
//
// The name may be empty, in which case a unique name will be generated.
// The name is a relatively short, unique identifier for the file (rather than a typical
// filename).
// Typically it should be left empty, in which case a unique name will be generated.
// Otherwise, it can contain up to 40 characters that are lowercase
// alphanumeric or dashes (-), not starting or ending with a dash.
// To generate your own unique names, consider a cryptographic hash algorithm like SHA-1.
// The string "files/" is prepended to the name if it does not contain a '/'.
//
// Use the returned file's URI field with a [FileData] Part to use it for generation.
Expand Down
9 changes: 7 additions & 2 deletions genai/generativelanguagepb_veneer.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,14 @@ func (File) fromProto(p *pb.File) *File {

// FileData is URI based data.
type FileData struct {
// Optional. The IANA standard MIME type of the source data.
// The IANA standard MIME type of the source data.
// If present, this overrides the MIME type specified or inferred
// when the file was uploaded.
// The supported MIME types are documented on [this page].
//
// [this page]: https://ai.google.dev/gemini-api/docs/prompting_with_media?lang=go#supported_file_formats
MIMEType string
// Required. URI.
// The URI returned from UploadFile or GetFile.
URI string
}

Expand Down
Loading

0 comments on commit ae10a3a

Please sign in to comment.