Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions core/llm/openaiTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,25 @@ function appendReasoningFieldsIfSupported(
includeReasoningContentField?: boolean;
},
) {
if (!prevMessage || prevMessage.role !== "thinking") return;

const includeReasoning = !!providerFlags?.includeReasoningField;
const includeReasoningDetails = !!providerFlags?.includeReasoningDetailsField;
const includeReasoningContent = !!providerFlags?.includeReasoningContentField;
if (!includeReasoning && !includeReasoningDetails && !includeReasoningContent)
return;

const hasThinkingContent = prevMessage && prevMessage.role === "thinking";

// DeepSeek Reasoner requires reasoning_content on every assistant message,
// even when no thinking message precedes it (e.g. resumed sessions).
// Default to empty string to avoid 400 "Missing reasoning_content field".
if (includeReasoningContent) {
msg.reasoning_content = hasThinkingContent
? (prevMessage.content as string)
: "";
}

if (!hasThinkingContent) return;

const reasoningDetailsValue =
prevMessage.reasoning_details ||
(prevMessage.signature
Expand Down Expand Up @@ -88,9 +99,6 @@ function appendReasoningFieldsIfSupported(
if (includeReasoning) {
msg.reasoning = prevMessage.content as string;
}
if (includeReasoningContent) {
msg.reasoning_content = prevMessage.content as string;
}
}

export function toChatMessage(
Expand Down
Loading