Better thonk effort for Gem 3

83ea6e5cbf20f919c3d5add2ec65cfdd9faf2197

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +62 -6Showing whitespace changes
public/index.html+7 -1
@@ -2108,8 +2108,14 @@
21082108 <div class="toggle-description justifyLeft marginBot5" data-source="claude" data-i18n="Allocates a portion of the response length for thinking (min: 1024 tokens, low: 10%, medium: 25%, high: 50%, max: 95%), but minimum 1024 tokens. Auto does not request thinking.">
21092109 Allocates a portion of the response length for thinking (min: 1024 tokens, low: 10%, medium: 25%, high: 50%, max: 95%), but minimum 1024 tokens. Auto does not request thinking.
21102110 </div>
2111- <div class="toggle-description justifyLeft marginBot5" data-source="makersuite,vertexai" data-i18n="Allocates a portion of the response length for thinking (Flash 2.5/Pro 2.5) (min: 0/128 tokens, low: 10%, medium: 25%, high: 50%, max: 24576/32768 tokens). Auto lets the model decide.">
2111+ <div class="toggle-description justifyLeft marginBot5" data-source="makersuite,vertexai">
2112+ <span data-i18n="Sets a dynamic reasoning depth level for thinking (Flash 3/Pro 3). High and low are supported by both, minimal and medium are Flash 3 only. Auto lets the model decide.">
2113+ Sets a dynamic reasoning depth level for thinking (Flash 3/Pro 3). High and low are supported by both, minimal and medium are Flash 3 only. Auto lets the model decide.
2114+ </span>
2115+ <br>
2116+ <span data-i18n="Allocates a portion of the response length for thinking (Flash 2.5/Pro 2.5) (min: 0/128 tokens, low: 10%, medium: 25%, high: 50%, max: 24576/32768 tokens). Auto lets the model decide.">
21122117 Allocates a portion of the response length for thinking (Flash 2.5/Pro 2.5) (min: 0/128 tokens, low: 10%, medium: 25%, high: 50%, max: 24576/32768 tokens). Auto lets the model decide.
2118+ </span>
21132119 </div>
21142120 </div>
21152121 </div>
src/endpoints/backends/chat-completions.js+5 -1
@@ -474,10 +474,14 @@ async function sendMakerSuiteRequest(request, response) {
474474 const thinkingConfig = { includeThoughts: includeReasoning };
475475
476476 const thinkingBudget = calculateGoogleBudgetTokens(generationConfig.maxOutputTokens, reasoningEffort, model);
477477 if (typeof thinkingBudget === 'number' && Number.isInteger(thinkingBudget)) {
478478 thinkingConfig.thinkingBudget = thinkingBudget;
479479 }
480480
481+ if (typeof thinkingBudget === 'string' && thinkingBudget.length > 0) {
482+ thinkingConfig.thinkingLevel = thinkingBudget;
483+ }
484+
481485 // Vertex doesn't allow mixing disabled thinking with includeThoughts
482486 if (useVertexAi && thinkingBudget === 0 && thinkingConfig.includeThoughts) {
483487 console.info('Thinking budget is 0, but includeThoughts is true. Thoughts will not be included in the response.');
src/prompt-converters.js+50 -4
@@ -1145,7 +1145,7 @@ export function calculateClaudeBudgetTokens(maxTokens, reasoningEffort, stream)
11451145 * @param {number} maxTokens Maximum tokens
11461146 * @param {string} reasoningEffort Reasoning effort
11471147 * @param {string} model Model name
11481148 * @returns {number?|string|null} Budget tokens
11491149 */
11501150export function calculateGoogleBudgetTokens(maxTokens, reasoningEffort, model) {
11511151 function getFlashBudget() {
@@ -1230,15 +1230,61 @@ export function calculateGoogleBudgetTokens(maxTokens, reasoningEffort, model) {
12301230 return budgetTokens;
12311231 }
12321232
1233- if (model.includes('flash-lite')) {
1233+ function getGemini3FlashBudget() {
1234+ switch (reasoningEffort) {
1235+ case REASONING_EFFORT.auto:
1236+ return null;
1237+ case REASONING_EFFORT.min:
1238+ return 'minimal';
1239+ case REASONING_EFFORT.low:
1240+ return 'low';
1241+ case REASONING_EFFORT.medium:
1242+ return 'medium';
1243+ case REASONING_EFFORT.high:
1244+ return 'high';
1245+ case REASONING_EFFORT.max:
1246+ return 'high';
1247+ }
1248+
1249+ return null;
1250+ }
1251+
1252+ function getGemini3ProBudget() {
1253+ switch (reasoningEffort) {
1254+ case REASONING_EFFORT.auto:
1255+ return null;
1256+ case REASONING_EFFORT.min:
1257+ return 'low';
1258+ case REASONING_EFFORT.low:
1259+ return 'low';
1260+ case REASONING_EFFORT.medium:
1261+ return 'low';
1262+ case REASONING_EFFORT.high:
1263+ return 'high';
1264+ case REASONING_EFFORT.max:
1265+ return 'high';
1266+ }
1267+
1268+ return null;
1269+ }
1270+
1271+ if (/gemini-3-pro/.test(model)) {
1272+ return getGemini3ProBudget();
1273+ }
1274+
1275+ if (/gemini-3-flash/.test(model) ) {
1276+ return getGemini3FlashBudget();
1277+ }
1278+
1279+ if (/flash-lite/.test(model)) {
12341280 return getFlashLiteBudget();
12351281 }
12361282
12371283 if (model/flash/.includestest('flash'model)) {
12381284 return getFlashBudget();
12391285 }
12401286
12411287 if (model/pro/.includestest('pro'model)) {
12421288 return getProBudget();
12431289 }
12441290