From 4e64f2680cadc9627a58f710b8e393751832df42 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 16 Oct 2026 13:50:29 +0800 Subject: [PATCH] factory 0.1.31: an OpenAI model's request goes without temperature and top_p, not 400 (sweanng424, Nowledge Mem on gpt-6.1-sol, magpie's Discord) OpenAI's reasoning models turn temperature and top_p away with a 400, and droid sends neither. droidBody now takes both out of a Responses request for a model whose upstream is openai, also when the body already opens with droid's line. configModels says temperature: false for those models, so OpenCode doesn't send it either. Grok and the chat-completions models keep theirs. Run: bun test in packages/factory, 144 pass. The new test fails on 0.1.30's index.mjs (temperature still in the body). Not tried against Factory's API with a real account. --- packages/factory/droid.test.mjs | 24 ++++++++++++++++++++++++ packages/factory/index.mjs | 12 ++++++++++-- packages/factory/package.json | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/factory/droid.test.mjs b/packages/factory/droid.test.mjs index d110b52..d904c6e 100644 --- a/packages/factory/droid.test.mjs +++ b/packages/factory/droid.test.mjs @@ -174,3 +174,27 @@ test("a key account's usage reads the limits with the key", async () => { expect(u.windows[0].used).toBe(5) expect(asked).toEqual({ host: "api.factory.ai", auth: "Bearer fk-test-0123456789" }) }) + +// Nowledge Mem on factory-plugin/gpt-6.1-sol (magpie's Discord): a request +// with temperature got 400. OpenAI's reasoning models take no temperature or +// top_p, and droid sends neither; another vendor's model keeps them. +test("an OpenAI model's request goes without temperature and top_p", async () => { + const { send, hooks } = await loaded({ ...signedIn }) + let b = JSON.parse((await send(responses, `{"model":"gpt-6.1-sol","input":"hi","temperature":0.2,"top_p":0.9,"stream":true}`)).body) + expect("temperature" in b).toBe(false) + expect("top_p" in b).toBe(false) + expect(b.stream).toBe(true) + expect(b.instructions).toBe(DROID_LINE) + // already opened as droid's: still taken out + b = JSON.parse((await send(responses, JSON.stringify({ model: "gpt-5.5-fast", input: "hi", instructions: DROID_LINE, temperature: 0 }))).body) + expect("temperature" in b).toBe(false) + b = JSON.parse((await send(responses, `{"model":"grok-4.7","input":"hi","temperature":0.2}`)).body) + expect(b.temperature).toBe(0.2) + b = JSON.parse((await send(chat, `{"model":"glm-5.3","messages":[{"role":"user","content":"hi"}],"temperature":0.7}`)).body) + expect(b.temperature).toBe(0.7) + const cfg = { provider: {} } + await hooks.config(cfg) + const models = cfg.provider.factory.models + expect(models["gpt-6.1-sol"].temperature).toBe(false) + expect(models["glm-5.3"].temperature).toBe(true) +}) diff --git a/packages/factory/index.mjs b/packages/factory/index.mjs index d2db11f..0fc8618 100644 --- a/packages/factory/index.mjs +++ b/packages/factory/index.mjs @@ -172,7 +172,8 @@ function configModels() { reasoning: m.efforts.length > 0, attachment: m.images, tool_call: true, - temperature: true, + // OpenAI's reasoning models take no temperature (droidBody) + temperature: m.upstream !== "openai", modalities: { input: m.images ? ["text", "image"] : ["text"], output: ["text"] }, cost: { input: 0, output: 0 }, limit: { context: m.context, output: m.output }, @@ -474,11 +475,18 @@ function droidBody(path, body) { if (path.endsWith("/responses")) { const v = m.instructions if (v !== undefined && v !== null && typeof v !== "string") return body // not something droid sends + // OpenAI's reasoning models turn temperature and top_p away with a 400, + // and droid sends neither (Nowledge Mem on gpt-6.1-sol, magpie's Discord) + const sampled = byId.get(m.model)?.upstream === "openai" && ("temperature" in m || "top_p" in m) + if (sampled) { + delete m.temperature + delete m.top_p + } const opened = promptOpenings(m.input) const ins = promptText(v ?? "") if (!ins.startsWith(DROID_LINE)) m.instructions = ins.trim() === "" ? DROID_LINE : DROID_LINE + "\n" + ins else if (ins !== v || opened) m.instructions = ins - else return body + else if (!sampled) return body } else if (path.endsWith("/chat/completions")) { if (!Array.isArray(m.messages)) return body const opened = promptOpenings(m.messages, true) diff --git a/packages/factory/package.json b/packages/factory/package.json index a16e3c0..84a6cd0 100644 --- a/packages/factory/package.json +++ b/packages/factory/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-factory-auth", - "version": "0.1.30", + "version": "0.1.31", "description": "Sign in to a Factory (Droid) subscription from OpenCode or magpie", "type": "module", "main": "./index.mjs",