@@ -611,7 +611,6 @@ def _set_streaming_completions_api_output_data(
611611
612612 def new_iterator () -> "Iterator[ChatCompletionChunk]" :
613613 nonlocal ttft
614- count_tokens_manually = True
615614 for x in old_iterator :
616615 with capture_internal_exceptions ():
617616 if hasattr (x , "choices" ):
@@ -641,21 +640,12 @@ def new_iterator() -> "Iterator[ChatCompletionChunk]":
641640 set_data_normalized (
642641 span , SPANDATA .GEN_AI_RESPONSE_TEXT , all_responses
643642 )
644- if count_tokens_manually :
645- _calculate_token_usage (
646- messages ,
647- response ,
648- span ,
649- all_responses ,
650- integration .count_tokens ,
651- )
652643
653644 if finish_span :
654645 span .__exit__ (None , None , None )
655646
656647 async def new_iterator_async () -> "AsyncIterator[ChatCompletionChunk]" :
657648 nonlocal ttft
658- count_tokens_manually = True
659649 async for x in old_iterator :
660650 with capture_internal_exceptions ():
661651 if hasattr (x , "choices" ):
@@ -685,14 +675,7 @@ async def new_iterator_async() -> "AsyncIterator[ChatCompletionChunk]":
685675 set_data_normalized (
686676 span , SPANDATA .GEN_AI_RESPONSE_TEXT , all_responses
687677 )
688- if count_tokens_manually :
689- _calculate_token_usage (
690- messages ,
691- response ,
692- span ,
693- all_responses ,
694- integration .count_tokens ,
695- )
678+
696679 if finish_span :
697680 span .__exit__ (None , None , None )
698681
0 commit comments