Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🧠 feat: Implement O1 Model Support for Max Tokens Handling (#4376)

Danny Avila873e0473ec9a
diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js
index dce5ec54fa..c3e9a24ef3 100644
--- a/api/app/clients/OpenAIClient.js
+++ b/api/app/clients/OpenAIClient.js
@@ -68,6 +68,8 @@ class OpenAIClient extends BaseClient {
/** @type {OpenAIUsageMetadata | undefined} */
this.usage;
+ /** @type {boolean|undefined} */
+ this.isO1Model;
}
// TODO: PluginsClient calls this 3x, unneeded
@@ -98,6 +100,8 @@ class OpenAIClient extends BaseClient {
this.options.modelOptions,
);
+ this.isO1Model = /\bo1\b/i.test(this.modelOptions.model);
+
this.defaultVisionModel = this.options.visionModel ?? 'gpt-4-vision-preview';
if (typeof this.options.attachments?.then === 'function') {
this.options.attachments.then((attachments) => this.checkVisionRequest(attachments));
@@ -545,8 +549,7 @@ class OpenAIClient extends BaseClient {
promptPrefix = this.augmentedPrompt + promptPrefix;
}
- const isO1Model = /\bo1\b/i.test(this.modelOptions.model);
- if (promptPrefix && !isO1Model) {
+ if (promptPrefix && this.isO1Model !== true) {
promptPrefix = `Instructions:\n${promptPrefix.trim()}`;
instructions = {
role: 'system',
@@ -575,7 +578,7 @@ class OpenAIClient extends BaseClient {
};
/** EXPERIMENTAL */
- if (promptPrefix && isO1Model) {
+ if (promptPrefix && this.isO1Model === true) {
const lastUserMessageIndex = payload.findLastIndex((message) => message.role === 'user');
if (lastUserMessageIndex !== -1) {
payload[
@@ -1227,6 +1230,11 @@ ${convo}
opts.defaultHeaders = { ...opts.defaultHeaders, 'api-key': this.apiKey };
}
+ if (this.isO1Model === true && modelOptions.max_tokens != null) {
+ modelOptions.max_completion_tokens = modelOptions.max_tokens;
+ delete modelOptions.max_tokens;
+ }
+
if (process.env.OPENAI_ORGANIZATION) {
opts.organization = process.env.OPENAI_ORGANIZATION;
}