Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import comments to all samples #207

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions samples/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const mediaPath = __dirname + "/media";

async function cacheCreate() {
// [START cache_create]
// Make sure to include these imports:
// import { GoogleAICacheManager, GoogleAIFileManager } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const cacheManager = new GoogleAICacheManager(process.env.API_KEY);
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

Expand Down Expand Up @@ -66,6 +69,9 @@ async function cacheCreate() {

async function cacheCreateFromName() {
// [START cache_create_from_name]
// Make sure to include these imports:
// import { GoogleAICacheManager, GoogleAIFileManager } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const cacheManager = new GoogleAICacheManager(process.env.API_KEY);
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

Expand Down Expand Up @@ -102,6 +108,9 @@ async function cacheCreateFromName() {

async function cacheCreateFromChat() {
// [START cache_create_from_chat]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
// import { GoogleAICacheManager, GoogleAIFileManager } from "@google/generative-ai/server";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const cacheManager = new GoogleAICacheManager(process.env.API_KEY);
const fileManager = new GoogleAIFileManager(process.env.API_KEY);
Expand Down Expand Up @@ -147,6 +156,8 @@ async function cacheCreateFromChat() {

async function cacheDelete() {
// [START cache_delete]
// Make sure to include these imports:
// import { GoogleAICacheManager, GoogleAIFileManager } from "@google/generative-ai/server";
const cacheManager = new GoogleAICacheManager(process.env.API_KEY);
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

Expand Down Expand Up @@ -176,6 +187,8 @@ async function cacheDelete() {

async function cacheGet() {
// [START cache_get]
// Make sure to include these imports:
// import { GoogleAICacheManager, GoogleAIFileManager } from "@google/generative-ai/server";
const cacheManager = new GoogleAICacheManager(process.env.API_KEY);
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

Expand Down Expand Up @@ -207,6 +220,8 @@ async function cacheGet() {

async function cacheList() {
// [START cache_list]
// Make sure to include these imports:
// import { GoogleAICacheManager, GoogleAIFileManager } from "@google/generative-ai/server";
const cacheManager = new GoogleAICacheManager(process.env.API_KEY);
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

Expand Down Expand Up @@ -241,6 +256,8 @@ async function cacheList() {

async function cacheUpdate() {
// [START cache_update]
// Make sure to include these imports:
// import { GoogleAICacheManager, GoogleAIFileManager } from "@google/generative-ai/server";
const cacheManager = new GoogleAICacheManager(process.env.API_KEY);
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

Expand Down
6 changes: 6 additions & 0 deletions samples/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const mediaPath = __dirname + "/media";

async function chat() {
// [START chat]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
const chat = model.startChat({
Expand All @@ -48,6 +50,8 @@ async function chat() {

async function chatStreaming() {
// [START chat_streaming]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
const chat = model.startChat({
Expand Down Expand Up @@ -77,6 +81,8 @@ async function chatStreaming() {

async function chatStreamingWithImages() {
// [START chat_streaming_with_images]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
const chat = model.startChat();
Expand Down
6 changes: 6 additions & 0 deletions samples/code_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { GoogleGenerativeAI } from "@google/generative-ai";

async function codeExecutionBasic() {
// [START code_execution_basic]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand All @@ -37,6 +39,8 @@ async function codeExecutionBasic() {

async function codeExecutionRequestOverride() {
// [START code_execution_request_override]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand Down Expand Up @@ -65,6 +69,8 @@ async function codeExecutionRequestOverride() {

async function codeExecutionChat() {
// [START code_execution_chat]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand Down
4 changes: 4 additions & 0 deletions samples/controlled_generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {

async function jsonControlledGeneration() {
// [START json_controlled_generation]
// Make sure to include these imports:
// import { GoogleGenerativeAI, FunctionDeclarationSchemaType } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);

const schema = {
Expand Down Expand Up @@ -57,6 +59,8 @@ async function jsonControlledGeneration() {

async function jsonNoSchema() {
// [START json_no_schema]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);

const model = genAI.getGenerativeModel({
Expand Down
19 changes: 19 additions & 0 deletions samples/count_tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const mediaPath = __dirname + "/media";

async function tokensTextOnly() {
// [START tokens_text_only]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand Down Expand Up @@ -57,6 +59,8 @@ async function tokensTextOnly() {

async function tokensChat() {
// [START tokens_chat]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand All @@ -70,6 +74,8 @@ async function tokensChat() {

async function tokensMultimodalImageInline() {
// [START tokens_multimodal_image_inline]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand Down Expand Up @@ -99,6 +105,9 @@ async function tokensMultimodalImageInline() {

async function tokensMultimodalImageFileApi() {
// [START tokens_multimodal_image_file_api]
// Make sure to include these imports:
// import { GoogleAIFileManager } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResult = await fileManager.uploadFile(
Expand Down Expand Up @@ -129,6 +138,9 @@ async function tokensMultimodalImageFileApi() {

async function tokensMultimodalVideoAudioFileApi() {
// [START tokens_multimodal_video_audio_file_api]
// Make sure to include these imports:
// import { GoogleAIFileManager, FileState } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

function waitForProcessing(fileName) {
Expand Down Expand Up @@ -195,6 +207,9 @@ async function tokensMultimodalVideoAudioFileApi() {

async function tokensCachedContent() {
// [START tokens_cached_content]
// Make sure to include these imports:
// import { GoogleAICacheManager } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
// Generate a very long string
let longContentString = "";
for (let i = 0; i < 32001; i++) {
Expand Down Expand Up @@ -235,6 +250,8 @@ async function tokensCachedContent() {

async function tokensSystemInstruction() {
// [START tokens_system_instruction]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "models/gemini-1.5-flash",
Expand Down Expand Up @@ -266,6 +283,8 @@ async function tokensSystemInstruction() {

async function tokensTools() {
// [START tokens_tools]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "models/gemini-1.5-flash",
Expand Down
4 changes: 4 additions & 0 deletions samples/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { GoogleGenerativeAI } from "@google/generative-ai";

async function embedContent() {
// [START embed_content]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "text-embedding-004",
Expand All @@ -32,6 +34,8 @@ async function embedContent() {

async function batchEmbedContents() {
// [START batch_embed_contents]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "text-embedding-004",
Expand Down
18 changes: 18 additions & 0 deletions samples/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const mediaPath = __dirname + "/media";

async function filesCreateImage() {
// [START files_create_image]
// Make sure to include these imports:
// import { GoogleAIFileManager } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResult = await fileManager.uploadFile(
Expand Down Expand Up @@ -56,6 +59,9 @@ async function filesCreateImage() {

async function filesCreateAudio() {
// [START files_create_audio]
// Make sure to include these imports:
// import { GoogleAIFileManager, FileState } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResult = await fileManager.uploadFile(
Expand Down Expand Up @@ -101,6 +107,9 @@ async function filesCreateAudio() {

async function filesCreateText() {
// [START files_create_text]
// Make sure to include these imports:
// import { GoogleAIFileManager } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResult = await fileManager.uploadFile(`${mediaPath}/a11.txt`, {
Expand Down Expand Up @@ -129,6 +138,9 @@ async function filesCreateText() {

async function filesCreateVideo() {
// [START files_create_video]
// Make sure to include these imports:
// import { GoogleAIFileManager, FileState } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResult = await fileManager.uploadFile(
Expand Down Expand Up @@ -174,6 +186,8 @@ async function filesCreateVideo() {

async function filesList() {
// [START files_list]
// Make sure to include these imports:
// import { GoogleAIFileManager } from "@google/generative-ai/server";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const listFilesResponse = await fileManager.listFiles();
Expand All @@ -187,6 +201,8 @@ async function filesList() {

async function filesGet() {
// [START files_get]
// Make sure to include these imports:
// import { GoogleAIFileManager } from "@google/generative-ai/server";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResponse = await fileManager.uploadFile(
Expand All @@ -209,6 +225,8 @@ async function filesGet() {

async function filesDelete() {
// [START files_delete]
// Make sure to include these imports:
// import { GoogleAIFileManager } from "@google/generative-ai/server";
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResult = await fileManager.uploadFile(
Expand Down
2 changes: 2 additions & 0 deletions samples/function_calling.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { GoogleGenerativeAI } from "@google/generative-ai";

async function functionCalling() {
// [START function_calling]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
async function setLightValues(brightness, colorTemperature) {
// This mock API returns the requested lighting values
return {
Expand Down
2 changes: 2 additions & 0 deletions samples/model_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { GoogleGenerativeAI } from "@google/generative-ai";

async function configureModel() {
// [START configure_model]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand Down
1 change: 1 addition & 0 deletions samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"scripts": {
"check-samples": "node ./utils/check-samples.js",
"import-comments": "node ./utils/insert-import-comments.js",
"test": "yarn check-samples"
}
}
4 changes: 4 additions & 0 deletions samples/safety_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {

async function safetySettings() {
// [START safety_settings]
// Make sure to include these imports:
// import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand Down Expand Up @@ -52,6 +54,8 @@ async function safetySettings() {

async function safetySettingsMulti() {
// [START safety_settings_multi]
// Make sure to include these imports:
// import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand Down
2 changes: 2 additions & 0 deletions samples/system_instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { GoogleGenerativeAI } from "@google/generative-ai";

async function systemInstruction() {
// [START system_instruction]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
Expand Down
Loading
Loading