@@ -227,6 +227,13 @@ enum ContentBlockDeltaType {
227227 } ,
228228}
229229
230+ #[ derive( serde:: Serialize , Debug , Clone ) ]
231+ struct AnthropicThinking {
232+ #[ serde( rename = "type" ) ]
233+ thinking_type : String ,
234+ budget_tokens : usize ,
235+ }
236+
230237#[ derive( serde:: Serialize , Debug , Clone ) ]
231238struct AnthropicRequest {
232239 system : Vec < AnthropicMessageContent > ,
@@ -238,6 +245,8 @@ struct AnthropicRequest {
238245 stream : bool ,
239246 #[ serde( skip_serializing_if = "Option::is_none" ) ]
240247 max_tokens : Option < usize > ,
248+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
249+ thinking : Option < AnthropicThinking > ,
241250 model : String ,
242251}
243252
@@ -251,6 +260,12 @@ impl AnthropicRequest {
251260 Some ( tokens) => Some ( tokens) ,
252261 None => Some ( 8192 ) ,
253262 } ;
263+ let thinking = completion_request
264+ . thinking_budget ( )
265+ . map ( |budget| AnthropicThinking {
266+ thinking_type : "enabled" . to_owned ( ) ,
267+ budget_tokens : budget,
268+ } ) ;
254269 let messages = completion_request. messages ( ) ;
255270 // grab the tools over here ONLY from the system message
256271 let tools = messages
@@ -335,6 +350,7 @@ impl AnthropicRequest {
335350 tools,
336351 stream : true ,
337352 max_tokens,
353+ thinking,
338354 model : model_str,
339355 }
340356 }
@@ -345,6 +361,12 @@ impl AnthropicRequest {
345361 ) -> Self {
346362 let temperature = completion_request. temperature ( ) ;
347363 let max_tokens = completion_request. get_max_tokens ( ) ;
364+ let thinking = completion_request
365+ . thinking_budget ( )
366+ . map ( |budget| AnthropicThinking {
367+ thinking_type : "enabled" . to_owned ( ) ,
368+ budget_tokens : budget,
369+ } ) ;
348370 let messages = vec ! [ AnthropicMessage :: new(
349371 "user" . to_owned( ) ,
350372 completion_request. prompt( ) . to_owned( ) ,
@@ -356,6 +378,7 @@ impl AnthropicRequest {
356378 tools : vec ! [ ] ,
357379 stream : true ,
358380 max_tokens,
381+ thinking,
359382 model : model_str,
360383 }
361384 }
@@ -936,4 +959,4 @@ impl LLMClient for AnthropicClient {
936959
937960 Ok ( buffered_string)
938961 }
939- }
962+ }
0 commit comments