mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-09 18:29:39 +00:00
fix: max output tokens when using large thinking budget (#2976)
This commit is contained in:
@@ -105,18 +105,29 @@ export namespace ProviderTransform {
|
||||
return result
|
||||
}
|
||||
|
||||
export function maxOutputTokens(providerID: string, outputLimit: number, options: Record<string, any>): number {
|
||||
export function maxOutputTokens(
|
||||
providerID: string,
|
||||
options: Record<string, any>,
|
||||
modelLimit: number,
|
||||
globalLimit: number,
|
||||
): number {
|
||||
const modelCap = modelLimit || globalLimit
|
||||
const standardLimit = Math.min(modelCap, globalLimit)
|
||||
|
||||
if (providerID === "anthropic") {
|
||||
const thinking = options["thinking"]
|
||||
if (typeof thinking === "object" && thinking !== null) {
|
||||
const type = thinking["type"]
|
||||
const budgetTokens = thinking["budgetTokens"]
|
||||
if (type === "enabled" && typeof budgetTokens === "number" && budgetTokens > 0) {
|
||||
return outputLimit - budgetTokens
|
||||
const thinking = options?.["thinking"]
|
||||
const budgetTokens = typeof thinking?.["budgetTokens"] === "number" ? thinking["budgetTokens"] : 0
|
||||
const enabled = thinking?.["type"] === "enabled"
|
||||
if (enabled && budgetTokens > 0) {
|
||||
// Return text tokens so that text + thinking <= model cap, preferring 32k text when possible.
|
||||
if (budgetTokens + standardLimit <= modelCap) {
|
||||
return standardLimit
|
||||
}
|
||||
return modelCap - budgetTokens
|
||||
}
|
||||
}
|
||||
return outputLimit
|
||||
|
||||
return standardLimit
|
||||
}
|
||||
|
||||
export function schema(_providerID: string, _modelID: string, schema: JSONSchema.BaseSchema) {
|
||||
|
||||
Reference in New Issue
Block a user