Skip to content

Commit

Permalink
Update text_generation.js
Browse files Browse the repository at this point in the history
Making updates so that the quickstart "just works"
  • Loading branch information
logankilpatrick committed Sep 16, 2024
1 parent cf223ff commit 81fbfd4
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions samples/text_generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ const mediaPath = __dirname + "/media";

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

const prompt = "Write a story about a magic backpack.";
const prompt = "Explain how AI works";

const result = await model.generateContent(prompt);
console.log(result.response.text());
Expand All @@ -40,12 +39,10 @@ async function textGenTextOnlyPrompt() {

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

const prompt = "Write a story about a magic backpack.";
const prompt = "Explain how AI works";

const result = await model.generateContentStream(prompt);

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

function fileToGenerativePart(path, mimeType) {
Expand All @@ -87,9 +84,8 @@ async function textGenMultimodalOneImagePrompt() {

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

function fileToGenerativePart(path, mimeType) {
Expand Down Expand Up @@ -120,9 +116,8 @@ async function textGenMultimodalOneImagePromptStreaming() {

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

function fileToGenerativePart(path, mimeType) {
Expand Down Expand Up @@ -152,9 +147,8 @@ async function textGenMultimodalMultiImagePrompt() {

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

function fileToGenerativePart(path, mimeType) {
Expand Down Expand Up @@ -189,9 +183,8 @@ async function textGenMultimodalMultiImagePromptStreaming() {

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

function fileToGenerativePart(path, mimeType) {
Expand All @@ -217,10 +210,9 @@ async function textGenMultimodalAudio() {

async function textGenMultimodalVideoPrompt() {
// [START text_gen_multimodal_video_prompt]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
// import { GoogleAIFileManager, FileState } from "@google/generative-ai/server";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
import { GoogleGenerativeAI } from "@google/generative-ai";
import { GoogleAIFileManager, FileState } from "@google/generative-ai/server";
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

const fileManager = new GoogleAIFileManager(process.env.API_KEY);
Expand Down Expand Up @@ -259,10 +251,9 @@ async function textGenMultimodalVideoPrompt() {

async function textGenMultimodalVideoPromptStreaming() {
// [START text_gen_multimodal_video_prompt_streaming]
// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
// import { GoogleAIFileManager, FileState } from "@google/generative-ai/server";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
import { GoogleGenerativeAI } from "@google/generative-ai";
import { GoogleAIFileManager, FileState } from "@google/generative-ai/server";
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

const fileManager = new GoogleAIFileManager(process.env.API_KEY);
Expand Down

0 comments on commit 81fbfd4

Please sign in to comment.