From bd1e940a81a22c7fa519e561d93b3f274a06c622 Mon Sep 17 00:00:00 2001 From: octo-patch Date: Sun, 12 Apr 2026 12:14:08 +0800 Subject: [PATCH 1/2] fix: skip presence_penalty and frequency_penalty for Grok-3-mini and Grok-4 models (fixes #6593) xAI's Grok-3-mini and Grok-4 models do not accept the presence_penalty and frequency_penalty request parameters. Sending these params causes an API error. This change detects these model families and removes the unsupported parameters from the request payload. --- app/client/platforms/xai.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/client/platforms/xai.ts b/app/client/platforms/xai.ts index 830ad4778ac..d87164b6412 100644 --- a/app/client/platforms/xai.ts +++ b/app/client/platforms/xai.ts @@ -76,6 +76,11 @@ export class XAIApi implements LLMApi { }, }; + // Grok-3-mini and Grok-4 models do not support presence_penalty and frequency_penalty + const isGrokMiniOrV4 = + /grok-3-mini/i.test(modelConfig.model) || + /grok-4/i.test(modelConfig.model); + const requestPayload: RequestPayload = { messages, stream: options.config.stream, @@ -86,6 +91,12 @@ export class XAIApi implements LLMApi { top_p: modelConfig.top_p, }; + if (isGrokMiniOrV4) { + // These models do not accept presence_penalty / frequency_penalty + delete (requestPayload as any).presence_penalty; + delete (requestPayload as any).frequency_penalty; + } + console.log("[Request] xai payload: ", requestPayload); const shouldStream = !!options.config.stream; From 0ba694b89c0dbeaebe5a920d8d595d68d63055f7 Mon Sep 17 00:00:00 2001 From: octo-patch Date: Fri, 17 Apr 2026 11:12:59 +0800 Subject: [PATCH 2/2] fix: preserve $$ and other special chars in fillTemplateWith (fixes #6574) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When user input contains JavaScript special replacement patterns like $$, $&, $', or $`, String.prototype.replace() interprets them as replacement directives: - $$ → $ (literal dollar sign) - $& → the matched substring - $' → string after match - $` → string before match This caused e.g. $$e=mc^2$$ (display math) to be stored as $e=mc^2$ (inline math) after going through fillTemplateWith(). Fix: use a function callback in .replace() to treat the replacement value as a literal string, bypassing all special replacement patterns. --- app/store/chat.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index 87c1a8beba0..611a22d2c95 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -196,7 +196,9 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) { Object.entries(vars).forEach(([name, value]) => { const regex = new RegExp(`{{${name}}}`, "g"); - output = output.replace(regex, value.toString()); // Ensure value is a string + // Use a function callback to avoid special replacement patterns ($$, $&, $`, $') + // in String.prototype.replace when user input contains these sequences + output = output.replace(regex, () => value.toString()); }); return output;