MCPcopy Index your code
hub / github.com/simstudioai/sim / executeGeminiRequest

Function executeGeminiRequest

apps/sim/providers/gemini/core.ts:896–1277  ·  view source on GitHub ↗
(
  config: GeminiExecutionConfig
)

Source from the content-addressed store, hash-verified

894 * The only difference is how the GoogleGenAI client is configured.
895 */
896export async function executeGeminiRequest(
897 config: GeminiExecutionConfig
898): Promise<ProviderResponse | StreamingExecution> {
899 const { ai, model, request, providerType } = config
900
901 // Route deep research models to the interactions API
902 if (isDeepResearchModel(model)) {
903 return executeDeepResearchRequest(config)
904 }
905
906 const logger = createLogger(providerType === 'google' ? 'GoogleProvider' : 'VertexProvider')
907
908 logger.info(`Preparing ${providerType} Gemini request`, {
909 model,
910 hasSystemPrompt: !!request.systemPrompt,
911 hasMessages: !!request.messages?.length,
912 hasTools: !!request.tools?.length,
913 toolCount: request.tools?.length ?? 0,
914 hasResponseFormat: !!request.responseFormat,
915 streaming: !!request.stream,
916 })
917
918 const providerStartTime = Date.now()
919 const providerStartTimeISO = new Date(providerStartTime).toISOString()
920
921 try {
922 const { contents, tools, systemInstruction } = convertToGeminiFormat(request, providerType)
923
924 // Build configuration
925 const geminiConfig: GenerateContentConfig = {}
926
927 if (request.abortSignal) {
928 geminiConfig.abortSignal = request.abortSignal
929 }
930 if (request.temperature !== undefined) {
931 geminiConfig.temperature = request.temperature
932 }
933 if (request.maxTokens != null) {
934 geminiConfig.maxOutputTokens = request.maxTokens
935 }
936 if (systemInstruction) {
937 geminiConfig.systemInstruction = systemInstruction
938 }
939
940 // Handle response format
941 if (request.responseFormat && !tools?.length) {
942 geminiConfig.responseMimeType = 'application/json'
943 geminiConfig.responseSchema = cleanSchemaForGemini(request.responseFormat.schema) as Schema
944 logger.info('Using Gemini native structured output format')
945 } else if (request.responseFormat && tools?.length && isGemini3Model(model)) {
946 geminiConfig.responseMimeType = 'application/json'
947 geminiConfig.responseJsonSchema = request.responseFormat.schema
948 logger.info('Using Gemini 3 structured output with tools (responseJsonSchema)')
949 } else if (request.responseFormat && tools?.length) {
950 logger.warn(
951 'Gemini 2 does not support responseFormat with tools. Structured output will be applied after tool execution.'
952 )
953 }

Callers 2

index.tsFile · 0.90
index.tsFile · 0.90

Calls 15

isDeepResearchModelFunction · 0.90
createLoggerFunction · 0.90
convertToGeminiFormatFunction · 0.90
cleanSchemaForGeminiFunction · 0.90
isGemini3ModelFunction · 0.90
mapToThinkingLevelFunction · 0.90
calculateCostFunction · 0.90
convertUsageMetadataFunction · 0.90
extractTextContentFunction · 0.90

Tested by

no test coverage detected