Skip to content

Instantly share code, notes, and snippets.

@nuhmanpk
Created May 10, 2025 11:34
Show Gist options
  • Save nuhmanpk/37f2e95351ade935ea31d67a42e471b8 to your computer and use it in GitHub Desktop.
Save nuhmanpk/37f2e95351ade935ea31d67a42e471b8 to your computer and use it in GitHub Desktop.
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