From 8bb57afc84646fafa2e141c89820091551202cea Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Tue, 2 Sep 2025 15:18:04 -0700 Subject: [PATCH] oss --- codex-rs/core/src/chat_completions.rs | 23 +++++++++++++++-------- codex-rs/core/src/client.rs | 1 + codex-rs/core/src/config.rs | 11 +++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/codex-rs/core/src/chat_completions.rs b/codex-rs/core/src/chat_completions.rs index f253d5ae84..03e3517942 100644 --- a/codex-rs/core/src/chat_completions.rs +++ b/codex-rs/core/src/chat_completions.rs @@ -19,6 +19,7 @@ use crate::ModelProviderInfo; use crate::client_common::Prompt; use crate::client_common::ResponseEvent; use crate::client_common::ResponseStream; +use crate::config::Config; use crate::error::CodexErr; use crate::error::Result; use crate::model_family::ModelFamily; @@ -34,6 +35,7 @@ pub(crate) async fn stream_chat_completions( model_family: &ModelFamily, client: &reqwest::Client, provider: &ModelProviderInfo, + config: &Config, ) -> Result { // Build messages array let mut messages = Vec::::new(); @@ -130,17 +132,22 @@ pub(crate) async fn stream_chat_completions( })); } ResponseItem::Reasoning { - id, + id: _, summary, content, - encrypted_content, + encrypted_content: _, } => { - tracing::info!("reasoning item: {:?}", item); - messages.push(json!({ - "role": "assistant", - "content": null, - "reasoning": content, - })); + if !config.skip_reasoning_in_chat_completions { + // There is no clear way of sending reasoning items over chat completions. + // We are sending it as an assistant message. + tracing::info!("reasoning item: {:?}", item); + let reasoning = + format!("Reasoning Summary: {summary:?}, Reasoning Content: {content:?}"); + messages.push(json!({ + "role": "assistant", + "content": reasoning, + })); + } } ResponseItem::WebSearchCall { .. } | ResponseItem::Other => { tracing::info!("omitting item from chat completions: {:?}", item); diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index b7bfeaa7ca..b321080ff5 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -110,6 +110,7 @@ impl ModelClient { &self.config.model_family, &self.client, &self.provider, + &self.config, ) .await?; diff --git a/codex-rs/core/src/config.rs b/codex-rs/core/src/config.rs index 7845f5d4ce..c52b5e0161 100644 --- a/codex-rs/core/src/config.rs +++ b/codex-rs/core/src/config.rs @@ -185,6 +185,10 @@ pub struct Config { /// All characters are inserted as they are received, and no buffering /// or placeholder replacement will occur for fast keypress bursts. pub disable_paste_burst: bool, + + /// When `true`, reasoning items in Chat Completions input will be skipped. + /// Defaults to `false`. + pub skip_reasoning_in_chat_completions: bool, } impl Config { @@ -497,6 +501,10 @@ pub struct ConfigToml { /// All characters are inserted as they are received, and no buffering /// or placeholder replacement will occur for fast keypress bursts. pub disable_paste_burst: Option, + + /// When set to `true`, reasoning items will be skipped from Chat Completions input. + /// Defaults to `false`. + pub skip_reasoning_in_chat_completions: Option, } #[derive(Deserialize, Debug, Clone, PartialEq, Eq)] @@ -807,6 +815,9 @@ impl Config { .unwrap_or(false), include_view_image_tool, disable_paste_burst: cfg.disable_paste_burst.unwrap_or(false), + skip_reasoning_in_chat_completions: cfg + .skip_reasoning_in_chat_completions + .unwrap_or(false), }; Ok(config) }