#Ai Error
5 messages · Page 1 of 1 (latest)
Hi @woeful dune. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
It looks like you're encountering an error when trying to use Google's AI API (likely Gemini) with Convex. The error indicates that there's an empty content part in your request to the Google AI API.
The specific error message shows that in your request, at index 14 of the contents array, there's a parts field that is empty, which violates Google's API requirements. The API expects all parts to contain content.
When using Google's Generative AI with Convex, you need to ensure all message parts contain text or other valid content. Here are a few approaches to fix this:
- Check your message structure to ensure no empty parts are being sent
- Make sure all parts in your request have valid content
- Remove any empty parts before sending the request
If you're using the Google Generative AI SDK with Convex, you might need to add the 'use node' directive at the top of your action file as mentioned in this Discord thread:
Discord support thread: gemini
Here's an example of how to properly structure a request to Google's Generative AI from a Convex action:
'use node';
import { GoogleGenerativeAI } from '@google/generative-ai';
import { action } from './_generated/server';
export const generateResponse = action({
args: {},
handler: async (ctx, args) => {
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY as string);
const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash-8b' });
const chat = model.startChat({
history: [
{
role: 'user',
parts: [{ text: 'My name is Pedro' }],
},
],
});
const result = await chat.sendMessage(
'You have access to the history of messages from this chat session right?'
);
console.log(result.response.text());
return result.response.text();
},
});
Remember to set your API key as an environment variable in Convex:
npx convex env set GEMINI_API_KEY your-api-key
If you continue to experience issues, you might want to check if there are any account-related problems with your Google AI service, as mentioned in this Discord thread:
[Discord support thread: Debug Internal Node Errors](<https://discord.com/channels/1019350475847499849/1330845961571926046>)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@woeful dune Kapa.ai is still learning and improving, please let me know how I did by reacting below.