From f7c747c65f66951811d6a052c773b9703cbc1902 Mon Sep 17 00:00:00 2001 From: Yunling Zhu Date: Thu, 3 Apr 2025 22:11:59 +0800 Subject: [PATCH 1/2] encourage markdown inclusion for o1/o3 --- app/client/platforms/openai.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index c6f3fc425..cdfe9070c 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -56,7 +56,7 @@ export interface OpenAIListModelResponse { export interface RequestPayload { messages: { - role: "system" | "user" | "assistant"; + role: "developer" | "system" | "user" | "assistant"; content: string | MultimodalContent[]; }[]; stream?: boolean; @@ -237,8 +237,16 @@ export class ChatGPTApi implements LLMApi { // Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore. }; - // O1 使用 max_completion_tokens 控制token数 (https://platform.openai.com/docs/guides/reasoning#controlling-costs) if (isO1OrO3) { + // by default the o1/o3 models will not attempt to produce output that includes markdown formatting + // manually add "Formatting re-enabled" developer message to encourage markdown inclusion in model responses + // (https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/reasoning?tabs=python-secure#markdown-output) + requestPayload["messages"] = [ + { role: "developer", content: "Formatting re-enabled" }, + ...requestPayload["messages"], + ]; + + // O1 使用 max_completion_tokens 控制token数 (https://platform.openai.com/docs/guides/reasoning#controlling-costs) requestPayload["max_completion_tokens"] = modelConfig.max_tokens; } From c261ebc82c46d6857fe0f2addd28a18c9f44d7d9 Mon Sep 17 00:00:00 2001 From: Yunling Zhu Date: Sun, 6 Apr 2025 16:56:54 +0800 Subject: [PATCH 2/2] use unshift to improve perf --- app/client/platforms/openai.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index cdfe9070c..22953257d 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -241,12 +241,12 @@ export class ChatGPTApi implements LLMApi { // by default the o1/o3 models will not attempt to produce output that includes markdown formatting // manually add "Formatting re-enabled" developer message to encourage markdown inclusion in model responses // (https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/reasoning?tabs=python-secure#markdown-output) - requestPayload["messages"] = [ - { role: "developer", content: "Formatting re-enabled" }, - ...requestPayload["messages"], - ]; + requestPayload["messages"].unshift({ + role: "developer", + content: "Formatting re-enabled", + }); - // O1 使用 max_completion_tokens 控制token数 (https://platform.openai.com/docs/guides/reasoning#controlling-costs) + // o1/o3 uses max_completion_tokens to control the number of tokens (https://platform.openai.com/docs/guides/reasoning#controlling-costs) requestPayload["max_completion_tokens"] = modelConfig.max_tokens; }