From 71df415b140fec2b2754fd4cf99a38a6f38dacc2 Mon Sep 17 00:00:00 2001 From: skymkmk Date: Fri, 13 Sep 2024 13:18:07 +0800 Subject: [PATCH 1/3] feat: add o1 model --- app/client/platforms/openai.ts | 15 +++++++++------ app/constant.ts | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 4d6f2884541..da3153c6234 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -160,6 +160,7 @@ export class ChatGPTApi implements LLMApi { let requestPayload: RequestPayload | DalleRequestPayload; const isDalle3 = _isDalle3(options.config.model); + const isO1 = options.config.model.startsWith("o1"); if (isDalle3) { const prompt = getMessageTextContent( options.messages.slice(-1)?.pop() as any, @@ -181,17 +182,19 @@ export class ChatGPTApi implements LLMApi { const content = visionModel ? await preProcessImageContent(v.content) : getMessageTextContent(v); - messages.push({ role: v.role, content }); + if(!(isO1 && v.role === "system")) + messages.push({ role: v.role, content }); } + // O1 not support image, tools (plugin in ChatGPTNextWeb) and system, stream, logprobs, temperature, top_p, n, presence_penalty, frequency_penalty yet. requestPayload = { messages, - stream: options.config.stream, + stream: !isO1 ? options.config.stream : false, model: modelConfig.model, - temperature: modelConfig.temperature, - presence_penalty: modelConfig.presence_penalty, - frequency_penalty: modelConfig.frequency_penalty, - top_p: modelConfig.top_p, + temperature: !isO1 ? modelConfig.temperature : 1, + presence_penalty: !isO1 ? modelConfig.presence_penalty : 0, + frequency_penalty: !isO1 ? modelConfig.frequency_penalty : 0, + top_p: !isO1 ? modelConfig.top_p : 1, // max_tokens: Math.max(modelConfig.max_tokens, 1024), // Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore. }; diff --git a/app/constant.ts b/app/constant.ts index eb82d3c6600..3d33a047e90 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -250,6 +250,8 @@ export const KnowledgeCutOffDate: Record = { "gpt-4o-mini": "2023-10", "gpt-4o-mini-2024-07-18": "2023-10", "gpt-4-vision-preview": "2023-04", + "o1-mini": "2023-10", + "o1-preview": "2023-10", // After improvements, // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously. "gemini-pro": "2023-12", @@ -276,6 +278,8 @@ const openaiModels = [ "gpt-4-turbo-2024-04-09", "gpt-4-1106-preview", "dall-e-3", + "o1-mini", + "o1-preview" ]; const googleModels = [ From d0dce654bffead1971600a5feb313d9079800254 Mon Sep 17 00:00:00 2001 From: skymkmk Date: Fri, 13 Sep 2024 14:18:18 +0800 Subject: [PATCH 2/3] fix: shouldstream is not depend on iso1 --- app/client/platforms/openai.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index da3153c6234..bff34fdf8d3 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -207,7 +207,7 @@ export class ChatGPTApi implements LLMApi { console.log("[Request] openai payload: ", requestPayload); - const shouldStream = !isDalle3 && !!options.config.stream; + const shouldStream = !isDalle3 && !!options.config.stream && !isO1; const controller = new AbortController(); options.onController?.(controller); From 03fa580a558374c80485b6b36f9b1aad810f2df4 Mon Sep 17 00:00:00 2001 From: skymkmk Date: Fri, 13 Sep 2024 16:25:04 +0800 Subject: [PATCH 3/3] fix: give o1 some time to think twice --- app/client/platforms/openai.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index bff34fdf8d3..492278a9b44 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -182,7 +182,7 @@ export class ChatGPTApi implements LLMApi { const content = visionModel ? await preProcessImageContent(v.content) : getMessageTextContent(v); - if(!(isO1 && v.role === "system")) + if (!(isO1 && v.role === "system")) messages.push({ role: v.role, content }); } @@ -316,7 +316,7 @@ export class ChatGPTApi implements LLMApi { // make a fetch request const requestTimeoutId = setTimeout( () => controller.abort(), - isDalle3 ? REQUEST_TIMEOUT_MS * 2 : REQUEST_TIMEOUT_MS, // dalle3 using b64_json is slow. + isDalle3 || isO1 ? REQUEST_TIMEOUT_MS * 2 : REQUEST_TIMEOUT_MS, // dalle3 using b64_json is slow. ); const res = await fetch(chatPath, chatPayload);