refactor(flags): migrate output token max to runtime flags (#27680)
This commit is contained in:
@@ -228,7 +228,12 @@ export const layer = Layer.effect(
|
||||
tokens: MessageV2.Assistant["tokens"]
|
||||
model: Provider.Model
|
||||
}) {
|
||||
return overflow({ cfg: yield* config.get(), tokens: input.tokens, model: input.model })
|
||||
return overflow({
|
||||
cfg: yield* config.get(),
|
||||
tokens: input.tokens,
|
||||
model: input.model,
|
||||
outputTokenMax: flags.outputTokenMax,
|
||||
})
|
||||
})
|
||||
|
||||
const estimate = Effect.fn("SessionCompaction.estimate")(function* (input: {
|
||||
|
||||
@@ -173,7 +173,7 @@ const live: Layer.Layer<
|
||||
: undefined,
|
||||
topP: input.agent.topP ?? ProviderTransform.topP(input.model),
|
||||
topK: ProviderTransform.topK(input.model),
|
||||
maxOutputTokens: ProviderTransform.maxOutputTokens(input.model),
|
||||
maxOutputTokens: ProviderTransform.maxOutputTokens(input.model, flags.outputTokenMax),
|
||||
options,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -5,18 +5,24 @@ import type { MessageV2 } from "./message-v2"
|
||||
|
||||
const COMPACTION_BUFFER = 20_000
|
||||
|
||||
export function usable(input: { cfg: Config.Info; model: Provider.Model }) {
|
||||
export function usable(input: { cfg: Config.Info; model: Provider.Model; outputTokenMax?: number }) {
|
||||
const context = input.model.limit.context
|
||||
if (context === 0) return 0
|
||||
|
||||
const reserved =
|
||||
input.cfg.compaction?.reserved ?? Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model))
|
||||
input.cfg.compaction?.reserved ??
|
||||
Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax))
|
||||
return input.model.limit.input
|
||||
? Math.max(0, input.model.limit.input - reserved)
|
||||
: Math.max(0, context - ProviderTransform.maxOutputTokens(input.model))
|
||||
: Math.max(0, context - ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax))
|
||||
}
|
||||
|
||||
export function isOverflow(input: { cfg: Config.Info; tokens: MessageV2.Assistant["tokens"]; model: Provider.Model }) {
|
||||
export function isOverflow(input: {
|
||||
cfg: Config.Info
|
||||
tokens: MessageV2.Assistant["tokens"]
|
||||
model: Provider.Model
|
||||
outputTokenMax?: number
|
||||
}) {
|
||||
if (input.cfg.compaction?.auto === false) return false
|
||||
if (input.model.limit.context === 0) return false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user