Created
May 10, 2025 11:34
-
-
Save nuhmanpk/37f2e95351ade935ea31d67a42e471b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GoogleGenAI } from "@google/genai"; | |
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY }); | |
let response = await ai.models.generateContent({ | |
model: "gemini-2.0-flash", | |
contents: [ | |
"Given the sentence 'hello world, this is an example sentence', find the longest word, count the vowels in it, and return the product of the length of the longest word and the number of vowels." | |
], | |
config: { | |
tools: [{ codeExecution: {} }], | |
}, | |
}); | |
const parts = response?.candidates?.[0]?.content?.parts || []; | |
parts.forEach((part) => { | |
if (part.text) { | |
console.log(part.text); | |
} | |
if (part.executableCode && part.executableCode.code) { | |
console.log(part.executableCode.code); | |
} | |
if (part.codeExecutionResult && part.codeExecutionResult.output) { | |
console.log(part.codeExecutionResult.output); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment