-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(provider): apply reasoning_effort to ZAI providers via SetZaiThinking #3198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
42a6caf
bad7354
5f5f14d
76bd600
6053ca8
0103805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| use forge_domain::{Context, ContextMessage, Transformer}; | ||
|
|
||
| /// Strips assistant `reasoning_details` from every message but leaves | ||
| /// `context.reasoning` (the per-turn reasoning config) intact. | ||
| /// | ||
| /// Used on the z.ai provider path: when reasoning is opted out (e.g. | ||
| /// `:reasoning-effort none`), the orchestrator must keep `context.reasoning` | ||
| /// alive so [`SetZaiThinking`] can map it to `thinking: { type: disabled }`. | ||
| /// At the same time, prior assistant `reasoning_details` from earlier turns | ||
| /// must NOT replay into the request, otherwise the user's opt-out is | ||
| /// undermined and the upstream API may reject unsupported fields. | ||
| /// | ||
| /// Compare to `forge_domain::DropReasoningDetails`, which clears both the | ||
| /// per-message details and `context.reasoning`. | ||
| pub(crate) struct DropMessageReasoningDetails; | ||
|
|
||
| impl Transformer for DropMessageReasoningDetails { | ||
| type Value = Context; | ||
|
|
||
| fn transform(&mut self, mut context: Self::Value) -> Self::Value { | ||
| context.messages.iter_mut().for_each(|message| { | ||
| if let ContextMessage::Text(text) = &mut **message { | ||
| text.reasoning_details = None; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about other reasoning fields?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I scoped this to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be done at request layer as its zai specific change, not at context layer. |
||
| } | ||
| }); | ||
| context | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use forge_domain::{ContextMessage, ReasoningConfig, ReasoningFull, Role, TextMessage}; | ||
|
|
||
| use super::*; | ||
|
|
||
| fn make_reasoning() -> Vec<ReasoningFull> { | ||
| vec![ReasoningFull { | ||
| text: Some("prior thinking".to_string()), | ||
| signature: None, | ||
| ..Default::default() | ||
| }] | ||
| } | ||
|
|
||
| #[test] | ||
| fn drops_message_reasoning_details_but_keeps_context_reasoning() { | ||
| let reasoning = make_reasoning(); | ||
| let fixture = Context::default() | ||
| .add_message(ContextMessage::Text( | ||
| TextMessage::new(Role::Assistant, "hi").reasoning_details(reasoning), | ||
| )) | ||
| .reasoning(ReasoningConfig { enabled: Some(false), ..Default::default() }); | ||
|
|
||
| let mut transformer = DropMessageReasoningDetails; | ||
| let actual = transformer.transform(fixture); | ||
|
|
||
| let cleared = actual.messages.iter().all(|entry| match &**entry { | ||
| ContextMessage::Text(t) => t.reasoning_details.is_none(), | ||
| _ => true, | ||
| }); | ||
| assert!(cleared, "all message reasoning_details should be cleared"); | ||
| assert!( | ||
| actual.reasoning.is_some(), | ||
| "context.reasoning must survive so SetZaiThinking can map it" | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| mod compaction; | ||
| mod dedupe_role; | ||
| mod drop_message_reasoning_details; | ||
| mod drop_reasoning_only_messages; | ||
| mod drop_role; | ||
| mod model_specific_reasoning; | ||
| mod strip_working_dir; | ||
| mod trim_context_summary; | ||
|
|
||
| pub use compaction::SummaryTransformer; | ||
| pub(crate) use drop_message_reasoning_details::DropMessageReasoningDetails; | ||
| pub(crate) use drop_reasoning_only_messages::DropReasoningOnlyMessages; | ||
| pub(crate) use model_specific_reasoning::ModelSpecificReasoning; |
Uh oh!
There was an error while loading. Please reload this page.