File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change 1818from langtrace_python_sdk .utils import set_span_attribute
1919from openai import NOT_GIVEN
2020from tiktoken import get_encoding
21+ from tiktoken import get_encoding , list_encoding_names
2122
2223from langtrace_python_sdk .constants .instrumentation .common import (
2324 LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY ,
3031from opentelemetry import baggage
3132from opentelemetry .trace import Span
3233from opentelemetry .trace .status import StatusCode
34+
3335import os
3436
3537
@@ -253,6 +255,11 @@ def setup(self):
253255 self ._span_started = True
254256
255257 def cleanup (self ):
258+ if self .completion_tokens == 0 :
259+ response_model = 'cl100k_base'
260+ if self ._response_model in list_encoding_names ():
261+ response_model = self ._response_model
262+ self .completion_tokens = estimate_tokens_using_tiktoken ("" .join (self .result_content ), response_model )
256263 if self ._span_started :
257264 set_span_attribute (
258265 self .span ,
Original file line number Diff line number Diff line change 1- __version__ = "2.2.26 "
1+ __version__ = "2.2.27 "
You can’t perform that action at this time.
0 commit comments