( config: GeminiExecutionConfig )
| 894 | * The only difference is how the GoogleGenAI client is configured. |
| 895 | */ |
| 896 | export 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 | } |
no test coverage detected