Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cli/custom/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const defaultAnalyzeQuestion = "Describe this file in detail."
func attachAnalyze(cmd *cobra.Command) {
cmd.Use = "analyze [question]"
cmd.Short = "Ask questions about images, audio, video, documents, text files, or YouTube URLs (" + defaultTextModel + ")"
cmd.Long = "Ask a question about one or more images, audio files, videos, PDFs, CSV or text\nfiles, or YouTube URLs.\n\nPass each media source separately with --input. files/<id> references use the\nFiles API, and YouTube URLs are passed by URI. The optional question applies to\nall inputs; its default is \"" + defaultAnalyzeQuestion + "\"\nBy default, stdout prints only the model's answer. The request is not stored\nserver-side.\n\n" + inlineLimitNote
cmd.Long = "Ask a question about one or more images, audio files, videos, documents or text\nfiles, or YouTube URLs.\n\nPass each media source separately with --input. files/<id> references use the\nFiles API, and YouTube URLs are passed by URI. The optional question applies to\nall inputs; its default is \"" + defaultAnalyzeQuestion + "\"\nBy default, stdout prints only the model's answer. The request is not stored\nserver-side.\n\n" + inlineLimitNote
cmd.Example = " gemini-api analyze -i report.pdf \"Summarize the key findings\"\n" +
" gemini-api analyze -i photo.jpg\n" +
" gemini-api analyze -i files/abc123 \"List every speaker with timestamps\"\n" +
Expand Down
26 changes: 26 additions & 0 deletions internal/cli/custom/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ func TestDetectMIME(t *testing.T) {
{"clip.mp3", "Audio/WAV", "audio/wav"},
{"scan.TIFF", "", "image/tiff"},
{"clip.mkv", "", "video/x-matroska"},
// Office and OpenDocument types resolve from the built-in table, not the host's mime database.
{"memo.doc", "", "application/msword"},
{"memo.DOCX", "", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
{"memo.dotx", "", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"},
{"memo.odt", "", "application/vnd.oasis.opendocument.text"},
{"deck.ppt", "", "application/vnd.ms-powerpoint"},
{"deck.pptx", "", "application/vnd.openxmlformats-officedocument.presentationml.presentation"},
{"deck.odp", "", "application/vnd.oasis.opendocument.presentation"},
{"sheet.xls", "", "application/vnd.ms-excel"},
{"sheet.xlsx", "", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
{"sheet.ods", "", "application/vnd.oasis.opendocument.spreadsheet"},
{"noext", "", ""},
}
for _, tt := range tests {
Expand All @@ -383,6 +394,8 @@ func TestContentClassOf(t *testing.T) {
{"application/pdf", contentDocument, true},
// CSV is a document by enum even though it is textual.
{"text/csv", contentDocument, true},
{"application/vnd.openxmlformats-officedocument.wordprocessingml.document", contentDocument, true},
{"application/vnd.oasis.opendocument.spreadsheet", contentDocument, true},
{"text/plain", contentText, true},
{"text/x-go", contentText, true},
{"application/json", contentText, true},
Expand Down Expand Up @@ -3238,3 +3251,16 @@ func TestWrapVersionOutputSubstitutesReleaseVersion(t *testing.T) {
})
}
}

// TestRemoteMIMEHintListsOfficeTypes pins that the hint for an uploaded file
// of an unsupported type names every document family the API accepts.
func TestRemoteMIMEHintListsOfficeTypes(t *testing.T) {
err := checkRemoteMIME("text/plain", "input", analyzePolicy)
pe, ok := err.(porcelainError)
if !ok {
t.Fatalf("checkRemoteMIME = %v, want a usage error", err)
}
if hints := strings.Join(pe.hints, "\n"); !strings.Contains(hints, "Office and OpenDocument") {
t.Errorf("hints = %q, want Office and OpenDocument named", hints)
}
}
21 changes: 17 additions & 4 deletions internal/cli/custom/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,19 @@ var mimeByExtension = map[string]string{
".mpeg": "video/mpeg", ".mpg": "video/mpeg", ".flv": "video/x-flv",
".wmv": "video/wmv", ".3gp": "video/3gpp",
".pdf": "application/pdf", ".csv": "text/csv",
".txt": "text/plain", ".md": "text/markdown",
// Office and OpenDocument files, pinned here so detection does not depend
// on the host's mime database (absent in minimal containers).
".doc": "application/msword",
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
".odt": "application/vnd.oasis.opendocument.text",
".ppt": "application/vnd.ms-powerpoint",
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
".odp": "application/vnd.oasis.opendocument.presentation",
".xls": "application/vnd.ms-excel",
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
".ods": "application/vnd.oasis.opendocument.spreadsheet",
".txt": "text/plain", ".md": "text/markdown",
".html": "text/html", ".htm": "text/html", ".xml": "text/xml", ".json": "application/json",
".js": "text/javascript", ".ts": "text/x-typescript",
".py": "text/x-python", ".go": "text/x-go", ".css": "text/css", ".yaml": "text/yaml", ".yml": "text/yaml",
Expand Down Expand Up @@ -142,7 +154,8 @@ var textApplicationMIME = map[string]bool{

// contentClassOf picks the content block for a MIME type and reports whether
// the API accepts that exact type there. The image, audio, video, and document
// blocks each publish a closed mime_type enum (documents are only PDF and CSV);
// blocks each publish a closed mime_type enum (documents are PDF, CSV, and the
// Office and OpenDocument formats);
// every other textual type is sent as a text block, which carries no MIME type.
// Anything else falls to the document block with sendable=false.
func contentClassOf(mimeType string) (class contentClass, sendable bool) {
Expand Down Expand Up @@ -423,7 +436,7 @@ func checkLocalFile(path, mimeOverride, ref string, policy mediaPolicy) (int64,
class, sendable := contentClassOf(mimeType)
if !sendable {
return 0, "", usageError(fmt.Sprintf("%s: MIME type %s is not accepted by the Interactions API", ref, mimeType),
"Supported inputs: images, audio, video, PDF, CSV, and text files; convert the file, or pass --mime-type if the detection is wrong")
"Supported inputs: images, audio, video, PDF, CSV, Office and OpenDocument files, and text files; convert the file, or pass --mime-type if the detection is wrong")
}
if err := policy.checkClass(mimeType, ref); err != nil {
return 0, "", err
Expand Down Expand Up @@ -625,7 +638,7 @@ func checkRemoteMIME(mimeType, ref string, policy mediaPolicy) error {
}
if class, sendable := contentClassOf(mimeType); !sendable || class == contentText {
return usageError(fmt.Sprintf("%s: MIME type %s cannot be referenced by URI in the Interactions API", ref, mimeType),
"Supported uploaded inputs: images, audio, video, PDF, and CSV; pass text files as local paths, or --mime-type if the stored type is wrong")
"Supported uploaded inputs: images, audio, video, PDF, CSV, and Office and OpenDocument files; pass text files as local paths, or --mime-type if the stored type is wrong")
}
return policy.checkClass(mimeType, ref)
}
Expand Down
Loading