Skip to content

Generation Options

Control temperature, token limits, and sampling strategy for any generation method.

Usage

Pass options as part of the second argument to any generation method:

ts
import { SamplingMode } from "tsfm-sdk";

const reply = await session.respond("Write a haiku about rain", {
  options: {
    temperature: 0.9,
    maximumResponseTokens: 100,
    sampling: SamplingMode.random({ top: 50, seed: 42 }),
  },
});

Options

OptionTypeDescription
temperaturenumberControls randomness. Higher values (e.g. 0.9) produce more varied output.
maximumResponseTokensnumberMaximum number of tokens in the response.
samplingSamplingModeSampling strategy (see below).

Sampling Modes

Greedy

Always picks the most likely token. Deterministic output.

ts
SamplingMode.greedy()

Random

Sample from the token distribution with optional constraints:

ts
// Top-K sampling with a seed for reproducibility
SamplingMode.random({ top: 50, seed: 42 })

// Probability threshold (nucleus/top-P)
SamplingMode.random({ probabilityThreshold: 0.9 })
ParameterDescription
topOnly consider the top K most likely tokens
seedRandom seed for reproducible output
probabilityThresholdOnly consider tokens whose cumulative probability exceeds this threshold

Released under the Apache 2.0 License.