mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-11 16:39:15 +08:00
fix: respect enableMaxTokens setting when maxTokens is not configured (#11438)
* fix: respect enableMaxTokens setting when maxTokens is not configured When enableMaxTokens is disabled, getMaxTokens() should return undefined to let the API use its own default value, instead of forcing 4096 tokens. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix(modelParameters): handle max tokens when feature is disabled Check if max tokens feature is enabled before returning undefined to ensure proper API behavior --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: icarus <eurfelux@gmail.com>
This commit is contained in:
parent
1992363580
commit
0004a8cafe
@ -3,7 +3,6 @@
|
|||||||
* 处理温度、TopP、超时等基础参数的获取逻辑
|
* 处理温度、TopP、超时等基础参数的获取逻辑
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { DEFAULT_MAX_TOKENS } from '@renderer/config/constant'
|
|
||||||
import {
|
import {
|
||||||
isClaude45ReasoningModel,
|
isClaude45ReasoningModel,
|
||||||
isClaudeReasoningModel,
|
isClaudeReasoningModel,
|
||||||
@ -73,11 +72,19 @@ export function getTimeout(model: Model): number {
|
|||||||
|
|
||||||
export function getMaxTokens(assistant: Assistant, model: Model): number | undefined {
|
export function getMaxTokens(assistant: Assistant, model: Model): number | undefined {
|
||||||
// NOTE: ai-sdk会把maxToken和budgetToken加起来
|
// NOTE: ai-sdk会把maxToken和budgetToken加起来
|
||||||
let { maxTokens = DEFAULT_MAX_TOKENS } = getAssistantSettings(assistant)
|
const assistantSettings = getAssistantSettings(assistant)
|
||||||
|
const enabledMaxTokens = assistantSettings.enableMaxTokens ?? false
|
||||||
|
let maxTokens = assistantSettings.maxTokens
|
||||||
|
|
||||||
|
// If user hasn't enabled enableMaxTokens, return undefined to let the API use its default value.
|
||||||
|
// Note: Anthropic API requires max_tokens, but that's handled by the Anthropic client with a fallback.
|
||||||
|
if (!enabledMaxTokens || maxTokens === undefined) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
const provider = getProviderByModel(model)
|
const provider = getProviderByModel(model)
|
||||||
if (isSupportedThinkingTokenClaudeModel(model) && ['anthropic', 'aws-bedrock'].includes(provider.type)) {
|
if (isSupportedThinkingTokenClaudeModel(model) && ['anthropic', 'aws-bedrock'].includes(provider.type)) {
|
||||||
const { reasoning_effort: reasoningEffort } = getAssistantSettings(assistant)
|
const { reasoning_effort: reasoningEffort } = assistantSettings
|
||||||
const budget = getAnthropicThinkingBudget(maxTokens, reasoningEffort, model.id)
|
const budget = getAnthropicThinkingBudget(maxTokens, reasoningEffort, model.id)
|
||||||
if (budget) {
|
if (budget) {
|
||||||
maxTokens -= budget
|
maxTokens -= budget
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user