Skip to content
1 min read · 56 words

Type Alias: ChatSampler ​

ts
type ChatSampler = "greedy" | "top-k" | "top-p";

Defined in: src/batteries/llm/chat_common/generation.ts:30

The portable sampler strategy. Maps to each battery's native mechanism:

  • 'greedy' — deterministic argmax. transformers.js do_sample:false; LiteRT SamplerType.GREEDY (which is top-1, so k is forced to 1).
  • 'top-k' — sample from the top-k logits. transformers.js do_sample:true+top_k; LiteRT SamplerType.TOP_K+k.
  • 'top-p' — nucleus sampling. transformers.js do_sample:true+top_p; LiteRT SamplerType.TOP_P+p.