Skip to content

Generation Options

Control temperature, sampling strategy, and token limits.

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

async function main() {
  const session = new LanguageModelSession();

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

  session.dispose();
}

main().catch(console.error);

What This Shows

  1. Set temperature for creative output
  2. Use SamplingMode.random() with top-K and a seed for reproducible randomness
  3. Limit response length with maximumResponseTokens

Released under the Apache 2.0 License.