Skip to content

Commit c30ddfb

Browse files
authored
Merge pull request #6425 from yunlingz/o_model_md_response
Fix: Encourage markdown inclusion in model responses for o1/o3
2 parents a2f0149 + c261ebc commit c30ddfb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/client/platforms/openai.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface OpenAIListModelResponse {
5656

5757
export interface RequestPayload {
5858
messages: {
59-
role: "system" | "user" | "assistant";
59+
role: "developer" | "system" | "user" | "assistant";
6060
content: string | MultimodalContent[];
6161
}[];
6262
stream?: boolean;
@@ -238,8 +238,16 @@ export class ChatGPTApi implements LLMApi {
238238
// Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore.
239239
};
240240

241-
// O1 使用 max_completion_tokens 控制token数 (https://platform.openai.com/docs/guides/reasoning#controlling-costs)
242241
if (isO1OrO3) {
242+
// by default the o1/o3 models will not attempt to produce output that includes markdown formatting
243+
// manually add "Formatting re-enabled" developer message to encourage markdown inclusion in model responses
244+
// (https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/reasoning?tabs=python-secure#markdown-output)
245+
requestPayload["messages"].unshift({
246+
role: "developer",
247+
content: "Formatting re-enabled",
248+
});
249+
250+
// o1/o3 uses max_completion_tokens to control the number of tokens (https://platform.openai.com/docs/guides/reasoning#controlling-costs)
243251
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
244252
}
245253

0 commit comments

Comments
 (0)