Skip to navigation

How to control response randomness with temperature

View as Markdown

The temperature parameter controls how focused or varied model responses are.

Range: 0 to 2
Default: depends on the model and reasoning mode:

ModelReasoningDefault temperature
sarvam-105bOn (the default)1.0
sarvam-105bOff (reasoning_effort=None)0.6
sarvam-105b-conversationsOff (always)0.6
  • Lower temperature → more focused, predictable answers (e.g. 0.2)
  • Higher temperature → more creative, varied responses (e.g. 0.8 or 1.0)

👉 Tip: For most use cases, values between 0.2 and 0.8 give good results.

Output is not bit-reproducible, even with temperature=0. Use a lower temperature to reduce variation, not to guarantee identical responses.

How it works:

ModeRecommended temperatureBehavior
Non-thinking mode0.6 (default)Straightforward, factual responses
Thinking mode1.0 (default)Deeper reasoning, more exploration
Highly creative0.8 - 1.0Storytelling, brainstorming, poetry
Very random / playful> 1.0Unexpected, experimental output

First, install the SDK:

pip install -Uqq sarvamai

Then use the following Python code:

from sarvamai import SarvamAI
# Initialize the SarvamAI client with your API key
client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
# Example 1: Using the default temperature (1.0, since reasoning is on by default)
response = client.chat.completions(
model="sarvam-105b",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain the concept of gravity."}
],
# temperature is not specified → uses default 1.0 (0.6 if reasoning_effort=None)
)
print(response.choices[0].message.content)
from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
# Example 2: Using temperature = 0.9: more creative, varied response
response = client.chat.completions(
model="sarvam-105b",
messages=[
{"role": "system", "content": "You are a creative storyteller."},
{"role": "user", "content": "Tell me a story about a magical tiger."}
],
temperature=0.9 # More creative storytelling
)
# Receive assistant's reply as output
print(response.choices[0].message.content)