Skip to content

Commit 159717b

Browse files
authored
Add gemini samples (#1323)
* Add gemini samples * remove .vscode folder * PR comments * change name of place to get api key
1 parent 9c6e6b9 commit 159717b

File tree

8 files changed

+1076
-0
lines changed

8 files changed

+1076
-0
lines changed

.templates/template_location_v2.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,21 @@
186186
"templateName": "Dataflow Java: Read Pub/Sub Write BigQuery",
187187
"templateLanguages": ["java"],
188188
"runPlatforms": ["dataflow"]
189+
},
190+
{
191+
"repoPath": "https://github.com/GoogleCloudPlatform/cloud-code-samples.git",
192+
"directoryPath": "nodejs/gemini-api",
193+
"templatePath": "gemini-generate",
194+
"templateName": "Gemini API Node.js: Generate text content based on a prompt",
195+
"templateLanguages": ["nodejs"],
196+
"runPlatforms": ["gemini"]
197+
},
198+
{
199+
"repoPath": "https://github.com/GoogleCloudPlatform/cloud-code-samples.git",
200+
"directoryPath": "python/gemini-api",
201+
"templatePath": "gemini-generate",
202+
"templateName": "Gemini API Python: Generate text content based on a prompt",
203+
"templateLanguages": ["python"],
204+
"runPlatforms": ["gemini"]
189205
}
190206
]

nodejs/gemini-api/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
2+
3+
# Simple application to interact with Gemini API
4+
5+
"NodeJS: Gemini API" is a simple sample application that shows you how to interact with Google's Gemini APIs .
6+
7+
## Table of Contents
8+
9+
* [Directory contents](#directory-contents)
10+
* [Setting up the API Key](#setting-up-the-api-key)
11+
* [Getting started](#getting-started-with-vs-code)
12+
* [Sign up for user research](#sign-up-for-user-research)
13+
14+
## Directory contents
15+
* `launch.json` - config file for later when you deploy your application to Google Cloud
16+
* `index.js` - the Node sample application that asks Gemini API to generate content based on a prompt
17+
* `package.json` - includes the google generative ai dependency
18+
19+
## Setting up the API Key
20+
Before you can use the Gemini API, you must first obtain an API key. If you don't already have one, create a key with one click in Google AI Studio.
21+
[Get API](https://makersuite.google.com/app/apikey)
22+
23+
## Getting started with Cloud Code
24+
25+
### Run the application locally
26+
27+
1. Make sure you have generated the API key as shown above. Please make sure to use and store this key securely.
28+
29+
1. Install the package using
30+
```npm install @google/generative-ai```
31+
32+
1. Run this using
33+
```node index.js```
34+
35+
### Documentation
36+
1. You can see detailed API Reference for the Gemini APIs [here](https://googledevai.google.com/api)
37+
38+
1. You can see more samples and things to do [here](https://googledevai.google.com/tutorials/python_quickstart)
39+
40+
### Other things to try
41+
42+
1. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial/signup/tos) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
43+
44+
1. Install the Cloud Code [VS Code plugin](https://cloud.google.com/code/docs/vscode/install#installing) or [Jetbrains Extension](https://cloud.google.com/code/docs/intellij/install) if you haven't already.
45+
46+
1. Access Cloud Code [documentation](https://cloud.google.com/code/docs/) to learn how you can deploy your app to Google Cloud
47+
48+
### Sign up for user research
49+
50+
We want to hear your feedback!
51+
52+
The Cloud Code team is inviting our user community to sign-up to participate in Google User Experience Research.
53+
54+
If you’re invited to join a study, you may try out a new product or tell us what you think about the products you use every day. At this time, Google is only sending invitations for upcoming remote studies. Once a study is complete, you’ll receive a token of thanks for your participation such as a gift card or some Google swag.
55+
56+
[Sign up using this link](https://google.qualtrics.com/jfe/form/SV_4Me7SiMewdvVYhL?reserved=1&utm_source=In-product&Q_Language=en&utm_medium=own_prd&utm_campaign=Q1&productTag=clou&campaignDate=January2021&referral_code=UXbT481079) and answer a few questions about yourself, as this will help our research team match you to studies that are a great fit.

nodejs/gemini-api/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { GoogleGenerativeAI } = require("@google/generative-ai");
2+
3+
// Access your API key as an environment variable (see "Set up your API key" above)
4+
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
5+
6+
async function run() {
7+
// For text-only input, use the gemini-pro model
8+
const model = genAI.getGenerativeModel({ model: "gemini-pro"});
9+
10+
const prompt = "Write a story about a magic backpack."
11+
12+
const result = await model.generateContent(prompt);
13+
const text = result.response.text();
14+
console.log(text);
15+
}
16+
17+
run();

0 commit comments

Comments
 (0)