Configurable thinking budget (default to medium) (#494)

This commit is contained in:
Will Chen
2025-06-25 15:36:05 -07:00
committed by GitHub
parent 52aebae903
commit 2ea9500f73
21 changed files with 1417 additions and 8 deletions

View File

@@ -464,6 +464,7 @@ This conversation includes one or more image attachments. When the user uploads
providerOptions: {
"dyad-gateway": getExtraProviderOptions(
modelClient.builtinProviderId,
settings,
),
google: {
thinkingConfig: {

View File

@@ -84,6 +84,7 @@ export async function getModelClient(
: settings.enableProLazyEditsMode,
enableSmartFilesContext: settings.enableProSmartFilesContextMode,
},
settings,
})
: createOpenAICompatible({
name: "dyad-gateway",

View File

@@ -12,6 +12,7 @@ import {
import { OpenAICompatibleChatSettings } from "@ai-sdk/openai-compatible";
import log from "electron-log";
import { getExtraProviderOptions } from "./thinking_utils";
import type { UserSettings } from "../../lib/schemas";
const logger = log.scope("llm_engine_provider");
@@ -48,6 +49,7 @@ or to provide a custom fetch implementation for e.g. testing.
enableLazyEdits?: boolean;
enableSmartFilesContext?: boolean;
};
settings: UserSettings;
}
export interface DyadEngineProvider {
@@ -125,7 +127,10 @@ export function createDyadEngine(
// Parse the request body to manipulate it
const parsedBody = {
...JSON.parse(init.body),
...getExtraProviderOptions(options.originalProviderId),
...getExtraProviderOptions(
options.originalProviderId,
options.settings,
),
};
// Add files to the request if they exist

View File

@@ -1,16 +1,37 @@
import { PROVIDERS_THAT_SUPPORT_THINKING } from "../shared/language_model_helpers";
import type { UserSettings } from "../../lib/schemas";
function getThinkingBudgetTokens(
thinkingBudget?: "low" | "medium" | "high",
): number {
switch (thinkingBudget) {
case "low":
return 1_000;
case "medium":
return 4_000;
case "high":
return -1;
default:
return 4_000; // Default to medium
}
}
export function getExtraProviderOptions(
providerId: string | undefined,
settings: UserSettings,
): Record<string, any> {
if (!providerId) {
return {};
}
if (PROVIDERS_THAT_SUPPORT_THINKING.includes(providerId)) {
const budgetTokens = getThinkingBudgetTokens(settings?.thinkingBudget);
return {
thinking: {
type: "enabled",
include_thoughts: true,
// -1 means dynamic thinking where model determines.
// budget_tokens: 128, // minimum for Gemini Pro is 128
budget_tokens: budgetTokens,
},
};
}