ImageBotApp
This is the image bot using Gemini with Google Apps Script and Google Drive.
AI Summary
ImageBotApp
GAS library for building image bot app using Gemini and Google Drive.
Target Users
Beginner to intermediate GAS developers building image search/processing web apps with Gemini function calling.
Problems Solved
Complex setup for Gemini function calling to semantically search Drive images via corpus and generate responses in GAS web apps.
Script ID
- In GAS Editor: Click "Libraries +" → Paste into "Script ID" field → Click "Look up"
- "ImageBotApp" will appear in the search results
- Select the latest version (highest number) from "Version" dropdown
- Click "Add"
Tags
Main Features
1
Library Ready
Provided as GAS library for direct install or script copy into projects.
2
Auto Scopes
Automatically adds 3 required scopes: external_request, generative-language.retriever, drive.
3
Easy Web App
Deploy as Web App; test image search/upload via browser with doGet to main.
Examples
Main Functions
| Function | Description |
|---|---|
| ImageBotApp.main | Executes main image bot process |
| ImageBotApp.putImageDescriptionsToCorpus | Adds image descriptions from folder to corpus |
Examples
Setup init_
/**
* 初期設定init_
* ・フォルダID設定: const folderId = "###";
* ・コーパス・ドキュメント名設定: const newCorpusName = { name: "corpora/sample-corpus-1", displayName: "sample corpus 1" };
* ・ドキュメント名構築: const newDocumentName = { name: `${newCorpusName.name}/documents/sample-document-1`, displayName: "sample document 1" };
*/
function init_() {
// Please set the folder ID of the folder including images.
const folderId = "###";
const newCorpusName = { name: "corpora/sample-corpus-1", displayName: "sample corpus 1" };
const newDocumentName = { name: `${newCorpusName.name}/documents/sample-document-1`, displayName: "sample document 1" };
return { folderId, newCorpusName, newDocumentName };
}
Build Corpus
/**
* 画像説明をコーパスに追加
* ・init_呼び出し: init_();
* ・ライブラリ関数実行: ImageBotApp.putImageDescriptionsToCorpus(init_());
* ・結果出力: console.log(JSON.stringify(res.map(r => JSON.parse(r.getContentText()))));
*/
function putImageDescriptionsToCorpus() {
const res = ImageBotApp.putImageDescriptionsToCorpus(init_());
console.log(JSON.stringify(res.map(r => JSON.parse(r.getContentText()))));
}
Web App doGet
/**
* Web Appメインエントリ
* ・init_統合: { ...e, ...init_() }
* ・ライブラリmain実行: ImageBotApp.main({ ...e, ...init_() });
*/
const doGet = e => ImageBotApp.main({ ...e, ...init_() });
