Open 7thRA-ONE opened 3 months ago
This error will occur if there's no fetch
available in the global namespace. If you're using Node 20, this shouldn't be a problem. Are you able to run a simple node script in that same environment that just calls fetch()
(on any valid url)? Are you using any kind of framework or library that polyfills or overwrites fetch
?
const genAI = new GoogleGenerativeAI(GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });
const fetchGeminiResponse = async (message) => { try { const prompt = message;
const result = await model.generateContent(prompt);
console.log(result)
const response = result.response;
const text = response.text();
return text;
} catch (error) { console.log(error) return 'Sorry, something went wrong.'; } }; I am using this codebase from Gemini Docs, and my node version is 20.14.0? What will be reason and how to overcome this?
was this ever fixed?
Description of the bug:
Error: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: fetchFn is not a function
Environment Host: Heroku "@google/generative-ai": "^0.12.0", "engines": { "node": "^20.12.2", "npm": "^10.5.2" },
Actual vs expected behavior:
No response
Any other information you'd like to share?
No response