@@ -754,14 +754,17 @@ async def _process_openai_response(
754
754
consecutive_exceptions = 0
755
755
while True :
756
756
# Check if prompt_tokens_details exists in the response
757
- if hasattr (response .usage , 'prompt_tokens_details' ) and response .usage .prompt_tokens_details is not None :
757
+ if (
758
+ hasattr (response .usage , "prompt_tokens_details" )
759
+ and response .usage .prompt_tokens_details is not None
760
+ ):
758
761
cached_tokens = response .usage .prompt_tokens_details .cached_tokens
759
762
total_input_tokens += response .usage .prompt_tokens - cached_tokens
760
763
total_cached_input_tokens += cached_tokens
761
764
else :
762
765
# If prompt_tokens_details doesn't exist, assume all tokens are uncached
763
766
total_input_tokens += response .usage .prompt_tokens
764
-
767
+
765
768
total_output_tokens += response .usage .completion_tokens
766
769
message = response .choices [0 ].message
767
770
if message .tool_calls :
@@ -875,14 +878,17 @@ async def _process_openai_response(
875
878
876
879
usage = response .usage
877
880
# Check if prompt_tokens_details exists in the response
878
- if hasattr (usage , 'prompt_tokens_details' ) and usage .prompt_tokens_details is not None :
881
+ if (
882
+ hasattr (usage , "prompt_tokens_details" )
883
+ and usage .prompt_tokens_details is not None
884
+ ):
879
885
cached_tokens = usage .prompt_tokens_details .cached_tokens
880
886
total_cached_input_tokens += cached_tokens
881
887
total_input_tokens += usage .prompt_tokens - cached_tokens
882
888
else :
883
889
# If prompt_tokens_details doesn't exist, assume all tokens are uncached
884
890
total_input_tokens += usage .prompt_tokens
885
-
891
+
886
892
total_output_tokens += usage .completion_tokens
887
893
return (
888
894
content ,
0 commit comments