diff --git a/CHANGELOG.md b/CHANGELOG.md index 258db3f1..9a3e1e5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ### Added - **chat**: add reasoning effort, max completion tokens, store options for reasoning model support (#415) (thanks @Taewan-P) +### Added +- **chat**: feat(chat): add reasoningContent support for both ChatMessage and ChatDelta + ## 4.0.0 > Published 01 Feb 2025 diff --git a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatDelta.kt b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatDelta.kt index db448ebe..40540c1e 100644 --- a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatDelta.kt +++ b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatDelta.kt @@ -18,6 +18,11 @@ public data class ChatDelta( */ @SerialName("content") val content: String? = null, + /** + * The reasoning contents of the message. + */ + @SerialName("reasoning_content") val reasoningContent: String? = null, + /** * The name and arguments of a function that should be called, as generated by the model. */ diff --git a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatMessage.kt b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatMessage.kt index 1a76e031..9d0f778a 100644 --- a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatMessage.kt +++ b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatMessage.kt @@ -23,6 +23,12 @@ public data class ChatMessage( */ @SerialName("content") public val messageContent: Content? = null, + /** + * The model's reasoning content, providing intermediate logical steps or justification for the response. + * This field is typically populated by advanced models supporting reasoning transparency. + */ + @SerialName("reasoning_content") public val messageReasoningContent: Content? = null, + /** * The author's name of this message. * [name] is required if the role is `[ChatRole.Function], and it should be the name of the function whose response is @@ -103,6 +109,12 @@ public data class ChatMessage( else -> error("Content is not text") } + val reasoningContent: String? + get() = when (messageReasoningContent) { + is TextContent? -> messageReasoningContent?.content + else -> error("Content is not text") + } + @Suppress("FunctionName") public companion object {