Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Gemini APIを使ってみよう@potatotips#86
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
umsys
February 07, 2024
Programming
4.8k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Gemini APIを使ってみよう@potatotips#86
umsys
February 07, 2024
More Decks by umsys
See All by umsys
Jetpack Composeの スクロールパフォーマンス改善を検証した話
umsys
0
760
ZOZOTOWNアプリでのフルCompos実装取り組み事例
umsys
0
1.4k
Other Decks in Programming
See All in Programming
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
440
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
150
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
Next.js: The final boss of Web Performance
guaca
0
260
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
500
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
YesSQL, Process and Tooling at Scale
rocio
174
15k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
360
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
My Coaching Mixtape
mlcsv
0
360
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Building the Perfect Custom Keyboard
takai
2
910
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Transcript
Gemini APIを使ってみよう 2024/02/07 potatotips#86 内山雅由(@umsys_)
自己紹介 株式会社ZOZO X: @umsys_ Bluesky: @umsys.bsky.social GitHub: https://github.com/umsys
内山 雅由 • 車の運転とゲームとハリネズミが大好きです • 最近はポケモンカードにハマっています • 今月末発売予定のFF7 REBIRTHが楽しみです
生成AI使っていますか?
世はまさに生成AI戦国時代! • chatGPT(OpenAI) • Bard(Google) • Copilot(Microsoft) • Rufus(Amazon) などなど
Gemini API • Androidアプリ開発ではGemini APIを使うことで、生成AIを利用したアプリが開発でき ます。 • Androidだけでなく、様々な言語でも利用可能です。 ◦ Python
◦ Go ◦ Node.js ◦ Swift ◦ JavaScript • curl コマンドを使用して Gemini API を試すこともできます。 ◦ REST API
料金 今のところ無料で使えるプランがあります。
Androidアプリで開発してみよう!
クイックスタート Android StudioはIguanaかJellyfishの最新プレビュー版を用意してください。
クイックスタート Gemini API Starterを選択します。 ※Hedgehogだとこれが出てこない(泣) 誠に遺憾です
クイックスタート ここでAPI Keyが必要になります。 Google AI StudioでKeyを作成し、入力してください。 ※Google AI Studioへは「Generate API
key with Google AI Studio」から飛ぶことができます。 ※2 API Keyは誰にも教えないように注意しましょう。
クイックスタート ビルドしたら動かせます。
クイックスタート [File] > [New] > [Import Sample] を選択して 「generative」で検索すると、 他の機能の紹介を兼ねたコードサンプルを
Android Studio にインポートできます。
クイックスタート マルチモーダル テキストと画像をGeminiに渡して会話できる。
クイックスタート チャット テキストだけの会話だが、チャットの履歴を記憶した 状態で会話を続けることができる。 ※テンプレートからビルドできるアプリは毎回記憶が リセットされるワンショット
コードを見てみよう
GenerativeModelのセットアップ GenerativeModelの引数に各種設定値を渡してセットアップする。 modelName ユースケースに合わせてモデル名を設定。ワンショットとチャットの場合は 「gemini-pro」、マルチモーダルの場合は「 gemini-pro-vision」 apiKey Google AI Studioで作成したKeyを設定。秘匿性を高めるため、
local.propertiesなどに書いておいて、 BuildConfig.apiKeyで呼び出すと良いで すね。 generationConfig 返答のランダム性や、返してほしくない語句の設定(セーフティ機能)などの設 定ができます。サンプルではランダム性だけ設定しています。 引用: https://github.com/google/generative-ai-android/tree/main/generativeai-android-sample
ユーザーの入力内容をGeminiに渡している箇所 • GenerativeModelのgenerateContent()にユーザーの入力内容(prompt)を渡し、Geminiからの返答 を受け取ってUIStateに流している。 引用: https://github.com/google/generative-ai-android/tree/main/generativeai-android-sample
すごい簡単。 嬉しいね!
もう少し詳しくコードを見てみよう
GenerativeModel.generateContent() 引数に応じてpromptの型が3つ用意されています。 • Stringだけを渡して会話する。 • 画像だけを渡して会話する。 • 画像とテキストを複数混合して会話する。 現在はこれらのユースケースが実装されています。 Genimiからの返答はGenerateContentResponseとして返ってきます。
引用: https://github.com/google/generative-ai-android/tree/main/generativeai-android-sample
Content Content型はStringやBitmap を複数抱えることができるクラ ス。 ユーザーの入力から画像とテキ ストを複数混合してGeminiに渡 したいときはContent型で promptを渡すことができます。 引用: https://github.com/google/generative-ai-android/tree/main/generativeai-android-sample
GenerateContentResponse Genimiからの返答はGenerateContentResponseとして返ってきます。 candidatesはGeminiからの返答リストです。 GenerativeModelのセットアップでgenerationConfig.candidateCountを2以上にしておくと複数返って きます。 promptFeedbackは与えられたpromptに対するフィードバックです。不適切な入力などがあった場合に 返されるようです。(ちょっと BANが怖くて試してません) 引用: https://github.com/google/generative-ai-android/tree/main/generativeai-android-sample
Candidate Geminiからの返答を定義したクラスです。 ユーザー入力と同じContentとして返してくるようですね。 その他はセーフティーレーティングなどの付与情報です。 (ここまでコードを見てみると、 AIセーフティに対してかなり慎重になっている姿勢が感じられますね。) 引用: https://github.com/google/generative-ai-android/tree/main/generativeai-android-sample
ということは簡単に図示すると
None
公式ドキュメントには書いてなかったけ ど、Gemini APIで画像生成できるので は!?!!?
None
ご清聴ありがとうございました!