Skip to content

Commit

Permalink
add Gemini API sample (#1240)
Browse files Browse the repository at this point in the history
* add Gemini API sample

* Simplify configuration and fix response formatting

* Update wording for gemini nano sample
  • Loading branch information
sebastianbenz authored Jul 25, 2024
1 parent 2dd50d5 commit 005f7ca
Show file tree
Hide file tree
Showing 15 changed files with 595 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
# Temporary directory for debugging extension samples
_debug
_metadata
*.swp # vim temp files
1 change: 1 addition & 0 deletions functional-samples/ai.gemini-in-the-cloud/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
23 changes: 23 additions & 0 deletions functional-samples/ai.gemini-in-the-cloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# On-device AI with Gemini Nano

This sample demonstrates how to use the Gemini Cloud API in a Chrome Extension.

## Overview

The extension provides a chat interface for the Gemini API. To learn more about the API head over to [https://ai.google.dev/](https://ai.google.dev/).

## Running this extension

1. Clone this repository.
2. Download the Gemini API client by running:
```sh
npm install
```
3. [Retrieve an API key](https://ai.google.dev/gemini-api/docs/api-key) and update [functional-samples/ai.gemini-in-the-cloud/sidepanel/index.js](functional-samples/ai.gemini-in-the-cloud/sidepanel/index.js) (only for testing).
4. Compile the JS bundle for the sidepanel implementation by running:
```sh
npm run build
```
5. Load this directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked).
6. Click the extension icon.
7. Interact with the prompt API in the sidebar.
3 changes: 3 additions & 0 deletions functional-samples/ai.gemini-in-the-cloud/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chrome.sidePanel
.setPanelBehavior({ openPanelOnActionClick: true })
.catch((error) => console.error(error));
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions functional-samples/ai.gemini-in-the-cloud/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Google Gemini Demo",
"version": "0.1",
"manifest_version": 3,
"description": "Try the Gemini Models.",
"background": {
"service_worker": "background.js"
},
"permissions": ["sidePanel"],
"side_panel": {
"default_path": "sidepanel/index.html"
},
"action": {
"default_icon": {
"16": "images/icon16.png",
"32": "images/icon32.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"default_title": "Open Chat Interface"
}
}
288 changes: 288 additions & 0 deletions functional-samples/ai.gemini-in-the-cloud/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions functional-samples/ai.gemini-in-the-cloud/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Chrome Extensions Gemini Demo",
"version": "1.0",
"scripts": {
"build": "rollup sidepanel/index.js --file dist/sidepanel.bundle.js --format iife"
},
"private": true,
"devDependencies": {
"@google/generative-ai": "0.15.0",
"rollup": "4.19.0"
}
}
Loading

0 comments on commit 005f7ca

Please sign in to comment.