({
format,
modelId,
model,
settings,
defaultTemperature,
}: GetModelParamsOptions<Format>)
| 73 | export function getModelParams(options: GetModelParamsOptions<"gemini">): GeminiModelParams |
| 74 | export function getModelParams(options: GetModelParamsOptions<"openrouter">): OpenRouterModelParams |
| 75 | export function getModelParams({ |
| 76 | format, |
| 77 | modelId, |
| 78 | model, |
| 79 | settings, |
| 80 | defaultTemperature, |
| 81 | }: GetModelParamsOptions<Format>): ModelParams { |
| 82 | const { |
| 83 | modelMaxTokens: customMaxTokens, |
| 84 | modelMaxThinkingTokens: customMaxThinkingTokens, |
| 85 | modelTemperature: customTemperature, |
| 86 | reasoningEffort: customReasoningEffort, |
| 87 | verbosity: customVerbosity, |
| 88 | } = settings |
| 89 | |
| 90 | // Use the centralized logic for computing maxTokens |
| 91 | const maxTokens = getModelMaxOutputTokens({ |
| 92 | modelId, |
| 93 | model, |
| 94 | settings, |
| 95 | format, |
| 96 | }) |
| 97 | |
| 98 | let temperature = customTemperature ?? model.defaultTemperature ?? defaultTemperature |
| 99 | let reasoningBudget: ModelParams["reasoningBudget"] = undefined |
| 100 | let reasoningEffort: ModelParams["reasoningEffort"] = undefined |
| 101 | const verbosity: VerbosityLevel | undefined = customVerbosity |
| 102 | |
| 103 | if (shouldUseReasoningBudget({ model, settings })) { |
| 104 | // Check if this is a Gemini 2.5 Pro model |
| 105 | const isGemini25Pro = modelId.includes("gemini-2.5-pro") |
| 106 | |
| 107 | // If `customMaxThinkingTokens` is not specified use the default. |
| 108 | // For Gemini 2.5 Pro, default to 128 instead of 8192 |
| 109 | const defaultThinkingTokens = isGemini25Pro |
| 110 | ? GEMINI_25_PRO_MIN_THINKING_TOKENS |
| 111 | : DEFAULT_HYBRID_REASONING_MODEL_THINKING_TOKENS |
| 112 | reasoningBudget = customMaxThinkingTokens ?? defaultThinkingTokens |
| 113 | |
| 114 | // Reasoning cannot exceed 80% of the `maxTokens` value. |
| 115 | // maxTokens should always be defined for reasoning budget models, but add a guard just in case |
| 116 | if (maxTokens && reasoningBudget > Math.floor(maxTokens * 0.8)) { |
| 117 | reasoningBudget = Math.floor(maxTokens * 0.8) |
| 118 | } |
| 119 | |
| 120 | // Reasoning cannot be less than minimum tokens. |
| 121 | // For Gemini 2.5 Pro models, the minimum is 128 tokens |
| 122 | // For other models, the minimum is 1024 tokens |
| 123 | const minThinkingTokens = isGemini25Pro ? GEMINI_25_PRO_MIN_THINKING_TOKENS : 1024 |
| 124 | if (reasoningBudget < minThinkingTokens) { |
| 125 | reasoningBudget = minThinkingTokens |
| 126 | } |
| 127 | |
| 128 | // Let's assume that "Hybrid" reasoning models require a temperature of |
| 129 | // 1.0 since Anthropic does. |
| 130 | temperature = 1.0 |
| 131 | } else if (shouldUseReasoningEffort({ model, settings })) { |
| 132 | // "Traditional" reasoning models use the `reasoningEffort` parameter. |
no test coverage detected