Skip to main content
πŸ€– Learn AI: Build with LLMs

Temperature & Sampling

Temperature controls randomness: 0 is focused and deterministic (great for extraction), higher values are more creative. Different providers use different ranges β€” Anthropic caps at 1, OpenAI allows up to 2 β€” so a safe wrapper clamps user input into a sensible range.

Your task

Write clampTemperature(t) that limits t to the range [0, 2].

⚑ 30 XP
solution.jsRuns in your browser
Loading editor…
Tests3 to pass
in range
too high
negative

Run your code to check these.