Skip to content

Commit 630a033

Browse files
committed
initial commit
1 parent 571dd94 commit 630a033

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+21634
-1
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# create your own API KEY at https://aistudio.google.com/apikey
2+
#REACT_APP_GEMINI_API_KEY=''

.gcloudignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore everything except app.yaml and the build directory
2+
*
3+
!app.yaml
4+
!build
5+
!build/**

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

CONTRIBUTING

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# How to contribute
2+
3+
We'd love to accept your patches and contributions to this project.
4+
5+
## Before you begin
6+
7+
### Sign our Contributor License Agreement
8+
9+
Contributions to this project must be accompanied by a
10+
[Contributor License Agreement](https://cla.developers.google.com/about) (CLA).
11+
You (or your employer) retain the copyright to your contribution; this simply
12+
gives us permission to use and redistribute your contributions as part of the
13+
project.
14+
15+
If you or your current employer have already signed the Google CLA (even if it
16+
was for a different project), you probably don't need to do it again.
17+
18+
Visit <https://cla.developers.google.com/> to see your current agreements or to
19+
sign a new one.
20+
21+
### Review our community guidelines
22+
23+
This project follows
24+
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).
25+
26+
## Contribution process
27+
28+
### Code reviews
29+
30+
All submissions, including submissions by project members, require review. We
31+
use GitHub pull requests for this purpose. Consult
32+
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
33+
information on using pull requests.

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Apache License
23
Version 2.0, January 2004
34
http://www.apache.org/licenses/

README.md

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,105 @@
1-
# multimodal-live-api-web-console
1+
# Multimodal Live API - Web console
2+
3+
This repository contains a react-based starter app for using the [Multimodal Live API](https://ai.google.dev/gemini-api) over a websocket. It provides modules for streaming audio playback, recording user media such as from a microphone, webcam or screen capture as well as a unified log view to aid in development of your application.
4+
5+
We have provided several example applications on other branches of this repository:
6+
7+
- [demos/GenExplainer](https://github.com/google-gemini/multimodal-live-api-web-console/tree/demos/genexplainer)
8+
- [demos/GenWeather](https://github.com/google-gemini/multimodal-live-api-web-console/tree/demos/genweather)
9+
10+
Below is an example of an entire application that will use Google Search grounding and then render graphs using [vega-embed](https://github.com/vega/vega-embed):
11+
12+
```typescript
13+
import { type FunctionDeclaration, SchemaType } from "@google/generative-ai";
14+
import { useEffect, useRef, useState, memo } from "react";
15+
import vegaEmbed from "vega-embed";
16+
import { useLiveAPIContext } from "../../contexts/LiveAPIContext";
17+
18+
export const declaration: FunctionDeclaration = {
19+
name: "render_altair",
20+
description: "Displays an altair graph in json format.",
21+
parameters: {
22+
type: SchemaType.OBJECT,
23+
properties: {
24+
json_graph: {
25+
type: SchemaType.STRING,
26+
description:
27+
"JSON STRING representation of the graph to render. Must be a string, not a json object",
28+
},
29+
},
30+
required: ["json_graph"],
31+
},
32+
};
33+
34+
export function Altair() {
35+
const [jsonString, setJSONString] = useState<string>("");
36+
const { client, setConfig } = useLiveAPIContext();
37+
38+
useEffect(() => {
39+
setConfig({
40+
model: "models/gemini-v3-s-test",
41+
systemInstruction: {
42+
parts: [
43+
{
44+
text: 'You are my helpful assistant. Any time I ask you for a graph call the "render_altair" function I have provided you. Dont ask for additional information just make your best judgement.',
45+
},
46+
],
47+
},
48+
tools: [{ googleSearch: {} }, { functionDeclarations: [declaration] }],
49+
});
50+
}, [setConfig]);
51+
52+
useEffect(() => {
53+
client.on("toolcall", (toolCall) => {
54+
console.log(`got toolcall`, toolCall);
55+
const fc = toolCall.functionCalls.find(
56+
(fc) => fc.name === declaration.name
57+
);
58+
if (fc) {
59+
const str = (fc.args as any).json_graph;
60+
setJSONString(str);
61+
}
62+
});
63+
}, [client]);
64+
65+
const embedRef = useRef<HTMLDivElement>(null);
66+
67+
useEffect(() => {
68+
if (embedRef.current && jsonString) {
69+
vegaEmbed(embedRef.current, JSON.parse(jsonString));
70+
}
71+
}, [embedRef, jsonString]);
72+
return <div className="vega-embed" ref={embedRef} />;
73+
}
74+
```
75+
76+
## development
77+
78+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
79+
Project consists of:
80+
81+
- an Event-emitting websocket-client to ease communication between the websocket and the front-end
82+
- communication layer for processing audio in and out
83+
- a boilerplate view for starting to build your apps and view logs
84+
85+
## Available Scripts
86+
87+
In the project directory, you can run:
88+
89+
### `npm start`
90+
91+
Runs the app in the development mode.\
92+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
93+
94+
The page will reload if you make edits.\
95+
You will also see any lint errors in the console.
96+
97+
### `npm run build`
98+
99+
Builds the app for production to the `build` folder.\
100+
It correctly bundles React in production mode and optimizes the build for the best performance.
101+
102+
The build is minified and the filenames include the hashes.\
103+
Your app is ready to be deployed!
104+
105+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

app.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
runtime: nodejs20
16+
env: standard
17+
18+
handlers:
19+
# serve static files
20+
- url: /(.*\..+)$
21+
static_files: build/\1
22+
upload: build/(.*\..+)$
23+
24+
# Catch all handler to index.html
25+
- url: /.*
26+
static_files: build/index.html
27+
secure: always
28+
redirect_http_response_code: 301
29+
upload: buid/index.html

0 commit comments

Comments
 (0)