@@ -124,11 +124,10 @@ pub async fn call_api(
124
124
"llm_payload" ,
125
125
& payload_log,
126
126
) {
127
- eprintln ! ( "failed to add payload trace: {:?}" , e ) ;
127
+ // ignore tracing failures
128
128
}
129
129
}
130
130
131
- eprintln ! ( "Call API Body: {}" , serde_json:: to_string_pretty( & payload) . unwrap( ) ) ;
132
131
133
132
if is_stream {
134
133
handle_streaming_response_responses (
@@ -198,8 +197,6 @@ async fn handle_non_streaming_response_responses(
198
197
199
198
let response_json: serde_json:: Value = res. json ( ) . await ?;
200
199
201
- eprintln ! ( "Response JSON: {}" , serde_json:: to_string_pretty( & response_json) . unwrap( ) ) ;
202
-
203
200
// Only extract from output.content[].text where type="output_text" - no fallbacks
204
201
// 1) Text content
205
202
let mut response_text = String :: new ( ) ;
@@ -408,9 +405,6 @@ async fn handle_streaming_response_responses(
408
405
}
409
406
410
407
if let Some ( ev) = event_type {
411
- // Debug: log all events to understand what we're receiving
412
- eprintln ! ( "DEBUG Streaming event: '{}' with data: '{}'" , ev, data_buf. chars( ) . take( 200 ) . collect:: <String >( ) ) ;
413
-
414
408
// handle event
415
409
match ev. as_str ( ) {
416
410
// Text deltas
@@ -550,7 +544,6 @@ async fn handle_streaming_response_responses(
550
544
. or_else ( || v. get ( "id" ) . and_then ( |s| s. as_str ( ) ) . map ( |s| s. to_string ( ) ) ) {
551
545
let name = v. get ( "name" ) . and_then ( |s| s. as_str ( ) ) . map ( |s| s. to_string ( ) )
552
546
. or_else ( || v. get ( "function" ) . and_then ( |f| f. get ( "name" ) ) . and_then ( |s| s. as_str ( ) ) . map ( |s| s. to_string ( ) ) ) ;
553
- eprintln ! ( "DEBUG function_call.created: id={}, name={:?}" , id, name) ;
554
547
tools_map. entry ( id) . or_insert ( ToolAccum { name, arguments : String :: new ( ) , call_type : Some ( "function" . to_string ( ) ) } ) ;
555
548
}
556
549
}
@@ -567,10 +560,7 @@ async fn handle_streaming_response_responses(
567
560
}
568
561
// delta may be in {"delta":{"arguments":"..."}}
569
562
if let Some ( delta) = v. get ( "delta" ) {
570
- if let Some ( args) = delta. get ( "arguments" ) . and_then ( |a| a. as_str ( ) ) {
571
- eprintln ! ( "DEBUG function_call.delta: id={}, args_delta='{}'" , id, args) ;
572
- entry. arguments . push_str ( args) ;
573
- }
563
+ if let Some ( args) = delta. get ( "arguments" ) . and_then ( |a| a. as_str ( ) ) { entry. arguments . push_str ( args) ; }
574
564
}
575
565
}
576
566
}
@@ -583,12 +573,7 @@ async fn handle_streaming_response_responses(
583
573
. or_else ( || v. get ( "id" ) . and_then ( |s| s. as_str ( ) ) ) {
584
574
let entry = tools_map. entry ( id. to_string ( ) ) . or_insert ( ToolAccum { name : None , arguments : String :: new ( ) , call_type : Some ( "function" . to_string ( ) ) } ) ;
585
575
// OpenAI Responses API puts the delta directly in the "delta" field
586
- if let Some ( delta) = v. get ( "delta" ) . and_then ( |d| d. as_str ( ) ) {
587
- eprintln ! ( "DEBUG function_call_arguments.delta: id={}, delta='{}'" , id, delta) ;
588
- entry. arguments . push_str ( delta) ;
589
- } else {
590
- eprintln ! ( "DEBUG function_call_arguments.delta: id={}, no delta found in data: '{}'" , id, data_buf. chars( ) . take( 200 ) . collect:: <String >( ) ) ;
591
- }
576
+ if let Some ( delta) = v. get ( "delta" ) . and_then ( |d| d. as_str ( ) ) { entry. arguments . push_str ( delta) ; }
592
577
}
593
578
}
594
579
}
@@ -598,7 +583,6 @@ async fn handle_streaming_response_responses(
598
583
if let Some ( id) = v. get ( "item_id" ) . and_then ( |s| s. as_str ( ) )
599
584
. or_else ( || v. get ( "call_id" ) . and_then ( |s| s. as_str ( ) ) )
600
585
. or_else ( || v. get ( "id" ) . and_then ( |s| s. as_str ( ) ) ) {
601
- eprintln ! ( "DEBUG function_call_arguments.done: id={}, tools_map contains: {:?}" , id, tools_map. get( id) ) ;
602
586
603
587
// Get the complete arguments from the event (fallback to accumulated)
604
588
let final_arguments = v. get ( "arguments" ) . and_then ( |a| a. as_str ( ) )
@@ -607,7 +591,6 @@ async fn handle_streaming_response_responses(
607
591
. unwrap_or_default ( ) ;
608
592
609
593
if let Some ( acc) = tools_map. remove ( id) {
610
- eprintln ! ( "DEBUG function_call_arguments.done: removed from tools_map, name={:?}, final_args='{}'" , acc. name, final_arguments) ;
611
594
if let Some ( name) = acc. name {
612
595
let args_map = serde_json:: from_str :: < serde_json:: Value > ( & final_arguments)
613
596
. ok ( )
@@ -622,19 +605,13 @@ async fn handle_streaming_response_responses(
622
605
id : Some ( id. to_string ( ) ) ,
623
606
call_type : acc. call_type . or ( Some ( "function" . to_string ( ) ) ) ,
624
607
} ) ;
625
- eprintln ! ( "DEBUG function_call_arguments.done: added to function_calls, total count now: {}" , function_calls. len( ) ) ;
626
-
627
608
// Send WebSocket update for this function call
628
609
if let Some ( ref inbox) = inbox_name {
629
610
if let Some ( last) = function_calls. last ( ) {
630
611
let _ = super :: shared:: shared_model_logic:: send_tool_ws_update ( & ws_manager_trait, Some ( inbox. clone ( ) ) , last) . await ;
631
612
}
632
613
}
633
- } else {
634
- eprintln ! ( "DEBUG function_call_arguments.done: WARNING - acc.name is None!" ) ;
635
614
}
636
- } else {
637
- eprintln ! ( "DEBUG function_call_arguments.done: WARNING - id '{}' not found in tools_map!" , id) ;
638
615
}
639
616
}
640
617
}
@@ -643,9 +620,7 @@ async fn handle_streaming_response_responses(
643
620
if let Ok ( v) = serde_json:: from_str :: < serde_json:: Value > ( & data_buf) {
644
621
if let Some ( id) = v. get ( "call_id" ) . and_then ( |s| s. as_str ( ) )
645
622
. or_else ( || v. get ( "id" ) . and_then ( |s| s. as_str ( ) ) ) {
646
- eprintln ! ( "DEBUG function_call.done: id={}, tools_map contains: {:?}" , id, tools_map. get( id) ) ;
647
623
if let Some ( acc) = tools_map. remove ( id) {
648
- eprintln ! ( "DEBUG function_call.done: removed from tools_map, name={:?}, args='{}'" , acc. name, acc. arguments) ;
649
624
if let Some ( name) = acc. name {
650
625
let args_map = serde_json:: from_str :: < serde_json:: Value > ( & acc. arguments )
651
626
. ok ( )
@@ -660,12 +635,7 @@ async fn handle_streaming_response_responses(
660
635
id : Some ( id. to_string ( ) ) ,
661
636
call_type : acc. call_type . or ( Some ( "function" . to_string ( ) ) ) ,
662
637
} ) ;
663
- eprintln ! ( "DEBUG function_call.done: added to function_calls, total count now: {}" , function_calls. len( ) ) ;
664
- } else {
665
- eprintln ! ( "DEBUG function_call.done: WARNING - acc.name is None!" ) ;
666
638
}
667
- } else {
668
- eprintln ! ( "DEBUG function_call.done: WARNING - id '{}' not found in tools_map!" , id) ;
669
639
}
670
640
if let Some ( ref inbox) = inbox_name {
671
641
if let Some ( last) = function_calls. last ( ) {
@@ -679,10 +649,8 @@ async fn handle_streaming_response_responses(
679
649
"response.completed" => {
680
650
// finalize any remaining tool calls
681
651
let ids: Vec < String > = tools_map. keys ( ) . cloned ( ) . collect ( ) ;
682
- eprintln ! ( "DEBUG response.completed: finalizing {} remaining tool calls" , ids. len( ) ) ;
683
652
for id in ids {
684
653
if let Some ( acc) = tools_map. remove ( & id) {
685
- eprintln ! ( "DEBUG response.completed: finalizing tool call id={}, name={:?}, args='{}'" , id, acc. name, acc. arguments) ;
686
654
if let Some ( name) = acc. name {
687
655
let args_map = serde_json:: from_str :: < serde_json:: Value > ( & acc. arguments )
688
656
. ok ( )
@@ -697,7 +665,6 @@ async fn handle_streaming_response_responses(
697
665
id : Some ( id. to_string ( ) ) ,
698
666
call_type : acc. call_type . or ( Some ( "function" . to_string ( ) ) ) ,
699
667
} ) ;
700
- eprintln ! ( "DEBUG response.completed: added to function_calls, total count now: {}" , function_calls. len( ) ) ;
701
668
}
702
669
}
703
670
}
@@ -739,7 +706,6 @@ async fn handle_streaming_response_responses(
739
706
let name = item. get ( "name" ) . and_then ( |n| n. as_str ( ) ) . map ( |s| s. to_string ( ) )
740
707
. or_else ( || item. get ( "function_name" ) . and_then ( |n| n. as_str ( ) ) . map ( |s| s. to_string ( ) ) )
741
708
. or_else ( || item. get ( "function" ) . and_then ( |f| f. get ( "name" ) ) . and_then ( |n| n. as_str ( ) ) . map ( |s| s. to_string ( ) ) ) ;
742
- eprintln ! ( "DEBUG output_item.added (function_call): id={}, name={:?}, full_item={}" , id, name, serde_json:: to_string( & item) . unwrap_or_default( ) ) ;
743
709
tools_map. entry ( id. to_string ( ) ) . or_insert ( ToolAccum {
744
710
name,
745
711
arguments : String :: new ( ) ,
@@ -760,14 +726,11 @@ async fn handle_streaming_response_responses(
760
726
let name = item. get ( "name" ) . and_then ( |n| n. as_str ( ) ) . map ( |s| s. to_string ( ) )
761
727
. or_else ( || item. get ( "function_name" ) . and_then ( |n| n. as_str ( ) ) . map ( |s| s. to_string ( ) ) )
762
728
. or_else ( || item. get ( "function" ) . and_then ( |f| f. get ( "name" ) ) . and_then ( |n| n. as_str ( ) ) . map ( |s| s. to_string ( ) ) ) ;
763
- eprintln ! ( "DEBUG output_item.done (function_call): id={}, name={:?}, full_item={}" , id, name, serde_json:: to_string( & item) . unwrap_or_default( ) ) ;
764
-
765
729
// Update the tools_map entry with the function name if we found it
766
730
if let Some ( name) = name {
767
731
if let Some ( entry) = tools_map. get_mut ( id) {
768
732
if entry. name . is_none ( ) {
769
733
entry. name = Some ( name) ;
770
- eprintln ! ( "DEBUG output_item.done: updated function name for id {}" , id) ;
771
734
}
772
735
}
773
736
}
@@ -776,10 +739,7 @@ async fn handle_streaming_response_responses(
776
739
}
777
740
}
778
741
}
779
- _ => {
780
- // Log unmatched events to see what we're missing
781
- eprintln ! ( "DEBUG Unmatched streaming event: '{}' with data: '{}'" , ev, data_buf. chars( ) . take( 100 ) . collect:: <String >( ) ) ;
782
- }
742
+ _ => { }
783
743
}
784
744
}
785
745
} else {
@@ -788,14 +748,7 @@ async fn handle_streaming_response_responses(
788
748
}
789
749
}
790
750
791
- // Debug: log final accumulated data
792
- eprintln ! ( "DEBUG Final streaming result - response_text: '{}', reasoning_text: '{}', function_calls count: {}" ,
793
- response_text. chars( ) . take( 100 ) . collect:: <String >( ) ,
794
- reasoning_text. chars( ) . take( 100 ) . collect:: <String >( ) ,
795
- function_calls. len( ) ) ;
796
- if !function_calls. is_empty ( ) {
797
- eprintln ! ( "DEBUG Function calls: {:?}" , function_calls) ;
798
- }
751
+ // End of stream
799
752
800
753
Ok ( LLMInferenceResponse :: new (
801
754
response_text,
0 commit comments