From 4fbb81c77489c484d3fa5f4e08faf7d91f783b39 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 6 May 2025 08:40:00 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20fix:=20o-Series=20Model=20Regex?= =?UTF-8?q?=20for=20System=20Messages=20(#7245)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: no system message only for o1-preview and o1-mini * chore(OpenAIClient): linting * fix: update regex to include o1-preview and o1-mini in noSystemModelRegex * refactor: rename variable for consistency with AgentClient --------- Co-authored-by: Andres <9771158+andresgit@users.noreply.github.com> --- api/app/clients/OpenAIClient.js | 12 +++++++----- api/server/controllers/agents/client.js | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js index c6a6bcc68e..091a36919e 100644 --- a/api/app/clients/OpenAIClient.js +++ b/api/app/clients/OpenAIClient.js @@ -475,7 +475,9 @@ class OpenAIClient extends BaseClient { promptPrefix = this.augmentedPrompt + promptPrefix; } - if (promptPrefix && this.isOmni !== true) { + const noSystemModelRegex = /\b(o1-preview|o1-mini)\b/i.test(this.modelOptions.model); + + if (promptPrefix && !noSystemModelRegex) { promptPrefix = `Instructions:\n${promptPrefix.trim()}`; instructions = { role: 'system', @@ -503,7 +505,7 @@ class OpenAIClient extends BaseClient { }; /** EXPERIMENTAL */ - if (promptPrefix && this.isOmni === true) { + if (promptPrefix && noSystemModelRegex) { const lastUserMessageIndex = payload.findLastIndex((message) => message.role === 'user'); if (lastUserMessageIndex !== -1) { if (Array.isArray(payload[lastUserMessageIndex].content)) { @@ -1227,9 +1229,9 @@ ${convo} opts.baseURL = this.langchainProxy ? constructAzureURL({ - baseURL: this.langchainProxy, - azureOptions: this.azure, - }) + baseURL: this.langchainProxy, + azureOptions: this.azure, + }) : this.azureEndpoint.split(/(? { const legacyContentEndpoints = new Set([KnownEndpoints.groq, KnownEndpoints.deepseek]); -const noSystemModelRegex = [/\b(o1)\b/gi]; +const noSystemModelRegex = [/\b(o1-preview|o1-mini)\b/gi]; // const { processMemory, memoryInstructions } = require('~/server/services/Endpoints/agents/memory'); // const { getFormattedMemories } = require('~/models/Memory');