Skip to content

Commit 8b578a4

Browse files
Biki-devdayuan.jiang
andauthored
fix: Remove hardcoded temperature parameter to support models that don't support it (#133)
* Fix: remove hardcoded temperature parameter to support reasoning models * feat: make temperature configurable via AI_TEMPERATURE env var - Instead of removing temperature entirely, make it optional via env var - Set AI_TEMPERATURE=0 for deterministic output (recommended for diagrams) - Leave unset for models that don't support temperature (e.g., GPT-5.1 reasoning) * docs: add AI_TEMPERATURE env var documentation - Update env.example with AI_TEMPERATURE option - Update README.md configuration section - Add Temperature Setting section in ai-providers.md * docs: add TEMPERATURE env var documentation - Update env.example with TEMPERATURE option - Update README.md, README_CN.md, README_JA.md configuration sections - Add Temperature Setting section in ai-providers.md - Update route.ts to use TEMPERATURE env var --------- Co-authored-by: dayuan.jiang <[email protected]>
1 parent 05d5802 commit 8b578a4

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Edit `.env.local` and configure your chosen provider:
149149
- Set `AI_PROVIDER` to your chosen provider (bedrock, openai, anthropic, google, azure, ollama, openrouter, deepseek)
150150
- Set `AI_MODEL` to the specific model you want to use
151151
- Add the required API keys for your provider
152+
- `TEMPERATURE`: Optional temperature setting (e.g., `0` for deterministic output). Leave unset for models that don't support it (e.g., reasoning models).
152153
- `ACCESS_CODE_LIST`: Optional access password(s), can be comma-separated for multiple passwords.
153154

154155
> Warning: If you do not set `ACCESS_CODE_LIST`, anyone can access your deployed site directly, which may lead to rapid depletion of your token. It is recommended to set this option.

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ cp env.example .env.local
149149
-`AI_PROVIDER` 设置为您选择的提供商(bedrock, openai, anthropic, google, azure, ollama, openrouter, deepseek)
150150
-`AI_MODEL` 设置为您要使用的特定模型
151151
- 添加您的提供商所需的API密钥
152+
- `TEMPERATURE`:可选的温度设置(例如 `0` 表示确定性输出)。对于不支持此参数的模型(如推理模型),请不要设置。
152153
- `ACCESS_CODE_LIST` 访问密码,可选,可以使用逗号隔开多个密码。
153154

154155
> 警告:如果不填写 `ACCESS_CODE_LIST`,则任何人都可以直接使用你部署后的网站,可能会导致你的 token 被急速消耗完毕,建议填写此选项。

README_JA.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ cp env.example .env.local
149149
- `AI_PROVIDER`を選択したプロバイダーに設定(bedrock, openai, anthropic, google, azure, ollama, openrouter, deepseek)
150150
- `AI_MODEL`を使用する特定のモデルに設定
151151
- プロバイダーに必要なAPIキーを追加
152+
- `TEMPERATURE`:オプションの温度設定(例:`0`で決定論的な出力)。温度をサポートしないモデル(推論モデルなど)では設定しないでください。
152153
- `ACCESS_CODE_LIST` アクセスパスワード(オプション)。カンマ区切りで複数のパスワードを指定できます。
153154

154155
> 警告:`ACCESS_CODE_LIST`を設定しない場合、誰でもデプロイされたサイトに直接アクセスできるため、トークンが急速に消費される可能性があります。このオプションを設定することをお勧めします。

app/api/chat/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ IMPORTANT: Keep edits concise:
418418
}),
419419
},
420420
},
421-
temperature: 0,
421+
...(process.env.TEMPERATURE !== undefined && {
422+
temperature: parseFloat(process.env.TEMPERATURE),
423+
}),
422424
})
423425

424426
return result.toUIMessageStreamResponse()

docs/ai-providers.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ This task requires exceptionally strong model capabilities, as it involves gener
133133

134134
**Note on Ollama**: While Ollama is supported as a provider, it's generally not practical for this use case unless you're running high-capability models like DeepSeek R1 or Qwen3-235B locally.
135135

136+
## Temperature Setting
137+
138+
You can optionally configure the temperature via environment variable:
139+
140+
```bash
141+
TEMPERATURE=0 # More deterministic output (recommended for diagrams)
142+
```
143+
144+
**Important**: Leave `TEMPERATURE` unset for models that don't support temperature settings, such as:
145+
- GPT-5.1 and other reasoning models
146+
- Some specialized models
147+
148+
When unset, the model uses its default behavior.
149+
136150
## Recommendations
137151

138152
- **Best experience**: Use models with vision support (GPT-4o, Claude, Gemini) for image-to-diagram features

env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,10 @@ AI_MODEL=global.anthropic.claude-sonnet-4-5-20250929-v1:0
4848
# LANGFUSE_SECRET_KEY=sk-lf-...
4949
# LANGFUSE_BASEURL=https://cloud.langfuse.com # EU region, use https://us.cloud.langfuse.com for US
5050

51+
# Temperature (Optional)
52+
# Controls randomness in AI responses. Lower = more deterministic.
53+
# Leave unset for models that don't support temperature (e.g., GPT-5.1 reasoning models)
54+
# TEMPERATURE=0
55+
5156
# Access Control (Optional)
5257
# ACCESS_CODE_LIST=your-secret-code,another-code

0 commit comments

Comments
 (0)