@@ -252,6 +252,8 @@ pub struct OpenAIChatMessage {
252
252
#[ serde( skip_serializing_if = "Option::is_none" ) ]
253
253
pub content : Option < OpenAIChatMessageContent > ,
254
254
#[ serde( skip_serializing_if = "Option::is_none" ) ]
255
+ pub reasoning_content : Option < String > ,
256
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
255
257
pub name : Option < String > ,
256
258
#[ serde( skip_serializing_if = "Option::is_none" ) ]
257
259
pub tool_calls : Option < Vec < OpenAIToolCall > > ,
@@ -264,6 +266,8 @@ pub struct OpenAICompletionChatMessage {
264
266
#[ serde( skip_serializing_if = "Option::is_none" ) ]
265
267
pub content : Option < String > ,
266
268
#[ serde( skip_serializing_if = "Option::is_none" ) ]
269
+ pub reasoning_content : Option < String > ,
270
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
267
271
pub name : Option < String > ,
268
272
pub role : OpenAIChatMessageRole ,
269
273
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -331,6 +335,10 @@ impl TryFrom<&OpenAICompletionChatMessage> for AssistantChatMessage {
331
335
Some ( c) => Some ( c. clone ( ) ) ,
332
336
None => None ,
333
337
} ;
338
+ let reasoning_content = match cm. reasoning_content . as_ref ( ) {
339
+ Some ( c) => Some ( c. clone ( ) ) ,
340
+ None => None ,
341
+ } ;
334
342
335
343
let function_calls = if let Some ( tool_calls) = cm. tool_calls . as_ref ( ) {
336
344
let cfc = tool_calls
@@ -360,6 +368,7 @@ impl TryFrom<&OpenAICompletionChatMessage> for AssistantChatMessage {
360
368
361
369
Ok ( AssistantChatMessage {
362
370
content,
371
+ reasoning_content,
363
372
role,
364
373
name,
365
374
function_call,
@@ -429,6 +438,7 @@ impl TryFrom<&ChatMessage> for OpenAIChatMessage {
429
438
Some ( c) => Some ( OpenAIChatMessageContent :: try_from ( c) ?) ,
430
439
None => None ,
431
440
} ,
441
+ reasoning_content : None ,
432
442
name : assistant_msg. name . clone ( ) ,
433
443
role : OpenAIChatMessageRole :: from ( & assistant_msg. role ) ,
434
444
tool_calls : match assistant_msg. function_calls . as_ref ( ) {
@@ -443,20 +453,23 @@ impl TryFrom<&ChatMessage> for OpenAIChatMessage {
443
453
} ) ,
444
454
ChatMessage :: Function ( function_msg) => Ok ( OpenAIChatMessage {
445
455
content : Some ( OpenAIChatMessageContent :: try_from ( & function_msg. content ) ?) ,
456
+ reasoning_content : None ,
446
457
name : None ,
447
458
role : OpenAIChatMessageRole :: Tool ,
448
459
tool_calls : None ,
449
460
tool_call_id : Some ( function_msg. function_call_id . clone ( ) ) ,
450
461
} ) ,
451
462
ChatMessage :: System ( system_msg) => Ok ( OpenAIChatMessage {
452
463
content : Some ( OpenAIChatMessageContent :: try_from ( & system_msg. content ) ?) ,
464
+ reasoning_content : None ,
453
465
name : None ,
454
466
role : OpenAIChatMessageRole :: from ( & system_msg. role ) ,
455
467
tool_calls : None ,
456
468
tool_call_id : None ,
457
469
} ) ,
458
470
ChatMessage :: User ( user_msg) => Ok ( OpenAIChatMessage {
459
471
content : Some ( OpenAIChatMessageContent :: try_from ( & user_msg. content ) ?) ,
472
+ reasoning_content : None ,
460
473
name : user_msg. name . clone ( ) ,
461
474
role : OpenAIChatMessageRole :: from ( & user_msg. role ) ,
462
475
tool_calls : None ,
@@ -806,6 +819,7 @@ fn to_openai_messages(
806
819
// Case 3: there's more than one content, the content isn't text or we don't want to squash them => keep structured format
807
820
( _, _, _) => Some ( OpenAIChatMessageContent :: Structured ( contents) ) ,
808
821
} ,
822
+ reasoning_content : None ,
809
823
}
810
824
}
811
825
} )
@@ -829,6 +843,7 @@ fn to_openai_messages(
829
843
. collect ( )
830
844
} ) ,
831
845
content : m. content ,
846
+ reasoning_content : None ,
832
847
}
833
848
} )
834
849
// Remove system messages if requested.
@@ -1215,6 +1230,7 @@ async fn streamed_chat_completion(
1215
1230
. map ( |c| OpenAIChatChoice {
1216
1231
message : OpenAICompletionChatMessage {
1217
1232
content : Some ( "" . to_string ( ) ) ,
1233
+ reasoning_content : None ,
1218
1234
name : None ,
1219
1235
role : OpenAIChatMessageRole :: System ,
1220
1236
tool_calls : None ,
@@ -1272,6 +1288,14 @@ async fn streamed_chat_completion(
1272
1288
} ,
1273
1289
} ;
1274
1290
1291
+ match a. choices [ j] . delta . get ( "reasoning_content" ) {
1292
+ None => ( ) ,
1293
+ Some ( reasoning_content) => {
1294
+ c. choices [ j] . message . reasoning_content =
1295
+ Some ( reasoning_content. as_str ( ) . unwrap_or ( "" ) . to_string ( ) ) ;
1296
+ }
1297
+ } ;
1298
+
1275
1299
if let Some ( tool_calls) = a. choices [ j]
1276
1300
. delta
1277
1301
. get ( "tool_calls" )
@@ -1346,6 +1370,10 @@ async fn streamed_chat_completion(
1346
1370
None => None ,
1347
1371
Some ( c) => Some ( c. trim ( ) . to_string ( ) ) ,
1348
1372
} ;
1373
+ m. message . reasoning_content = match m. message . reasoning_content . as_ref ( ) {
1374
+ None => None ,
1375
+ Some ( c) => Some ( c. trim ( ) . to_string ( ) ) ,
1376
+ } ;
1349
1377
}
1350
1378
1351
1379
Ok ( ( completion, request_id) )
@@ -1497,6 +1525,10 @@ async fn chat_completion(
1497
1525
None => None ,
1498
1526
Some ( c) => Some ( c. trim ( ) . to_string ( ) ) ,
1499
1527
} ;
1528
+ m. message . reasoning_content = match m. message . reasoning_content . as_ref ( ) {
1529
+ None => None ,
1530
+ Some ( c) => Some ( c. trim ( ) . to_string ( ) ) ,
1531
+ } ;
1500
1532
}
1501
1533
1502
1534
Ok ( ( completion, request_id) )
0 commit comments