Optional
candidatesResponse variations returned by the model.
Optional
createTimestamp when the request is made to the server.
Optional
modelOutput only. The model version used to generate the response.
Optional
promptOutput only. Content filter results for a prompt sent in the request. Note: Sent only in the first stream chunk. Only happens when no candidates were generated due to content violations.
Optional
responseIdentifier for each response.
Optional
usageUsage metadata about the response(s).
Returns the first code execution result from the first candidate in the response.
If there are multiple candidates in the response, the code execution result from the first one will be returned. If there are no code execution result in the response, undefined will be returned.
const response = await ai.models.generateContent({
model: 'gemini-2.0-flash',
contents:
'What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50.'
config: {
tools: [{codeExecution: {}}],
},
});
console.debug(response.codeExecutionResult);
Returns the first executable code from the first candidate in the response.
If there are multiple candidates in the response, the executable code from the first one will be returned. If there are no executable code in the response, undefined will be returned.
const response = await ai.models.generateContent({
model: 'gemini-2.0-flash',
contents:
'What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50.'
config: {
tools: [{codeExecution: {}}],
},
});
console.debug(response.executableCode);
Returns the function calls from the first candidate in the response.
If there are multiple candidates in the response, the function calls from the first one will be returned. If there are no function calls in the response, undefined will be returned.
const controlLightFunctionDeclaration: FunctionDeclaration = {
name: 'controlLight',
parameters: {
type: Type.OBJECT,
description: 'Set the brightness and color temperature of a room light.',
properties: {
brightness: {
type: Type.NUMBER,
description:
'Light level from 0 to 100. Zero is off and 100 is full brightness.',
},
colorTemperature: {
type: Type.STRING,
description:
'Color temperature of the light fixture which can be `daylight`, `cool` or `warm`.',
},
},
required: ['brightness', 'colorTemperature'],
};
const response = await ai.models.generateContent({
model: 'gemini-2.0-flash',
contents: 'Dim the lights so the room feels cozy and warm.',
config: {
tools: [{functionDeclarations: [controlLightFunctionDeclaration]}],
toolConfig: {
functionCallingConfig: {
mode: FunctionCallingConfigMode.ANY,
allowedFunctionNames: ['controlLight'],
},
},
},
});
console.debug(JSON.stringify(response.functionCalls));
Returns the concatenation of all text parts from the first candidate in the response.
If there are multiple candidates in the response, the text from the first one will be returned. If there are non-text parts in the response, the concatenation of all text parts will be returned, and a warning will be logged. If there are thought parts in the response, the concatenation of all text parts excluding the thought parts will be returned.
Response message for PredictionService.GenerateContent.