opencode-optimal-model-temps 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +22 -0
  2. package/package.json +6 -0
  3. package/src/index.ts +45 -0
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # opencode-optimal-model-temps
2
+
3
+ Minimal OpenCode plugin that hooks `chat.params` and nudges specific models to their preferred sampling temperature. Right now it only pinches Google Gemini 3 Pro to **0.35**, following the recommendation in [Optimal Temperature for Gemini 3 Pro](https://lynchmark.com/blog/gemini-optimal-temperature).
4
+
5
+ ## Usage
6
+
7
+ Add the plugin to your `~/.config/opencode/opencode.json`:
8
+
9
+ ```json
10
+ {
11
+ "plugin": [
12
+ "opencode-optimal-model-temps"
13
+ ]
14
+ }
15
+ ```
16
+
17
+ You can override the defaults with env vars:
18
+
19
+ - `OPENCODE_GEMINI3_TEMPERATURE`: override target (defaults to `0.35`).
20
+ - `OPENCODE_GEMINI3_BASELINE`: baseline value (defaults to `1`). The plugin only overrides when the CLI is still using this baseline, so your explicit agent temperatures still win.
21
+
22
+ Feel free to extend `src/index.ts` with more entries in `TEMPERATURE_RULES` as the “perfect” settings for other models surface.
package/package.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "opencode-optimal-model-temps",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "license": "MIT"
6
+ }
package/src/index.ts ADDED
@@ -0,0 +1,45 @@
1
+ const TEMPERATURE_EPSILON = 1e-3
2
+
3
+ type TemperatureRule = {
4
+ provider: string
5
+ match: RegExp
6
+ target: number
7
+ baseline?: number
8
+ }
9
+
10
+ const TEMPERATURE_RULES: TemperatureRule[] = [
11
+ {
12
+ provider: "google",
13
+ match: /gemini-3-pro/,
14
+ target: Number(process.env.OPENCODE_GEMINI3_TEMPERATURE ?? "0.35"),
15
+ baseline: Number(process.env.OPENCODE_GEMINI3_BASELINE ?? "1"),
16
+ },
17
+ ]
18
+
19
+ function findRule(model: any): TemperatureRule | undefined {
20
+ const provider = (model?.providerID ?? "").toLowerCase()
21
+ const modelId = (model?.modelID ?? model?.api?.id ?? "").toLowerCase()
22
+
23
+ return TEMPERATURE_RULES.find((rule) => {
24
+ if (provider !== rule.provider.toLowerCase()) return false
25
+ return rule.match.test(modelId)
26
+ })
27
+ }
28
+
29
+ function isDefaultTemperature(current: number | undefined, baseline?: number) {
30
+ if (baseline === undefined || !Number.isFinite(baseline)) {
31
+ return current === undefined
32
+ }
33
+ if (current === undefined) return true
34
+ return Math.abs(current - baseline) < TEMPERATURE_EPSILON
35
+ }
36
+
37
+ export const OptimalModelTemperaturesPlugin = async () => ({
38
+ "chat.params": async ({ model }: { model: any }, output: { temperature?: number }) => {
39
+ const rule = findRule(model)
40
+ if (!rule || !Number.isFinite(rule.target)) return
41
+ if (!isDefaultTemperature(output.temperature, rule.baseline)) return
42
+
43
+ output.temperature = rule.target
44
+ },
45
+ })