Better thonk effort for Gem 3
This commit is contained in:
+8
-2
@@ -2108,8 +2108,14 @@
|
||||
<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.">
|
||||
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.
|
||||
</div>
|
||||
<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.">
|
||||
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.
|
||||
<div class="toggle-description justifyLeft marginBot5" data-source="makersuite,vertexai">
|
||||
<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.">
|
||||
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.
|
||||
</span>
|
||||
<br>
|
||||
<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.">
|
||||
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.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -474,10 +474,14 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
const thinkingConfig = { includeThoughts: includeReasoning };
|
||||
|
||||
const thinkingBudget = calculateGoogleBudgetTokens(generationConfig.maxOutputTokens, reasoningEffort, model);
|
||||
if (Number.isInteger(thinkingBudget)) {
|
||||
if (typeof thinkingBudget === 'number' && Number.isInteger(thinkingBudget)) {
|
||||
thinkingConfig.thinkingBudget = thinkingBudget;
|
||||
}
|
||||
|
||||
if (typeof thinkingBudget === 'string' && thinkingBudget.length > 0) {
|
||||
thinkingConfig.thinkingLevel = thinkingBudget;
|
||||
}
|
||||
|
||||
// Vertex doesn't allow mixing disabled thinking with includeThoughts
|
||||
if (useVertexAi && thinkingBudget === 0 && thinkingConfig.includeThoughts) {
|
||||
console.info('Thinking budget is 0, but includeThoughts is true. Thoughts will not be included in the response.');
|
||||
|
||||
@@ -1145,7 +1145,7 @@ export function calculateClaudeBudgetTokens(maxTokens, reasoningEffort, stream)
|
||||
* @param {number} maxTokens Maximum tokens
|
||||
* @param {string} reasoningEffort Reasoning effort
|
||||
* @param {string} model Model name
|
||||
* @returns {number?} Budget tokens
|
||||
* @returns {number|string|null} Budget tokens
|
||||
*/
|
||||
export function calculateGoogleBudgetTokens(maxTokens, reasoningEffort, model) {
|
||||
function getFlashBudget() {
|
||||
@@ -1230,15 +1230,61 @@ export function calculateGoogleBudgetTokens(maxTokens, reasoningEffort, model) {
|
||||
return budgetTokens;
|
||||
}
|
||||
|
||||
if (model.includes('flash-lite')) {
|
||||
function getGemini3FlashBudget() {
|
||||
switch (reasoningEffort) {
|
||||
case REASONING_EFFORT.auto:
|
||||
return null;
|
||||
case REASONING_EFFORT.min:
|
||||
return 'minimal';
|
||||
case REASONING_EFFORT.low:
|
||||
return 'low';
|
||||
case REASONING_EFFORT.medium:
|
||||
return 'medium';
|
||||
case REASONING_EFFORT.high:
|
||||
return 'high';
|
||||
case REASONING_EFFORT.max:
|
||||
return 'high';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getGemini3ProBudget() {
|
||||
switch (reasoningEffort) {
|
||||
case REASONING_EFFORT.auto:
|
||||
return null;
|
||||
case REASONING_EFFORT.min:
|
||||
return 'low';
|
||||
case REASONING_EFFORT.low:
|
||||
return 'low';
|
||||
case REASONING_EFFORT.medium:
|
||||
return 'low';
|
||||
case REASONING_EFFORT.high:
|
||||
return 'high';
|
||||
case REASONING_EFFORT.max:
|
||||
return 'high';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (/gemini-3-pro/.test(model)) {
|
||||
return getGemini3ProBudget();
|
||||
}
|
||||
|
||||
if (/gemini-3-flash/.test(model) ) {
|
||||
return getGemini3FlashBudget();
|
||||
}
|
||||
|
||||
if (/flash-lite/.test(model)) {
|
||||
return getFlashLiteBudget();
|
||||
}
|
||||
|
||||
if (model.includes('flash')) {
|
||||
if (/flash/.test(model)) {
|
||||
return getFlashBudget();
|
||||
}
|
||||
|
||||
if (model.includes('pro')) {
|
||||
if (/pro/.test(model)) {
|
||||
return getProBudget();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user