@@ -80,21 +80,6 @@ def calculate_prompt_tokens(prompt_content, model):
8080 return estimate_tokens (prompt_content ) # Fallback method
8181
8282
83- def get_streaming_tokens (kwargs ):
84- prompt_tokens = 0
85- for message in kwargs .get ("messages" , {}):
86- prompt_tokens += calculate_prompt_tokens (
87- json .dumps (message ), kwargs .get ("model" )
88- )
89-
90- if kwargs .get ("functions" ) is not None and kwargs .get ("functions" ) != NOT_GIVEN :
91- for function in kwargs .get ("functions" ):
92- prompt_tokens += calculate_prompt_tokens (
93- json .dumps (function ), kwargs .get ("model" )
94- )
95- return prompt_tokens
96-
97-
9883def calculate_price_from_usage (model , usage ):
9984 """
10085 Calculate the price of a model based on its usage."""
@@ -178,12 +163,11 @@ def get_base_url(instance):
178163
179164
180165def is_streaming (kwargs ):
181- streaming = kwargs .get ("stream" , None )
182-
183- if "optional_params" in kwargs :
184- streaming = kwargs .get ("optional_params" ).get ("stream" , None )
185-
186- return not (streaming is False or streaming is None or streaming == NOT_GIVEN )
166+ return not (
167+ kwargs .get ("stream" ) is False
168+ or kwargs .get ("stream" ) is None
169+ or kwargs .get ("stream" ) == NOT_GIVEN
170+ )
187171
188172
189173def set_usage_attributes (span , usage ):
0 commit comments