Skip to content

Commit d6edda0

Browse files
committed
[fix]: stringinfy tools before json.dumps
1 parent 30260f6 commit d6edda0

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/langtrace_python_sdk/instrumentation/openai/patch.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def traced_method(wrapped, instance, args, kwargs):
294294
prompt_tokens = 0
295295
for message in kwargs.get("messages", {}):
296296
prompt_tokens += calculate_prompt_tokens(
297-
json.dumps(message), kwargs.get("model")
297+
json.dumps(str(message)), kwargs.get("model")
298298
)
299299

300300
if (
@@ -388,7 +388,7 @@ async def traced_method(wrapped, instance, args, kwargs):
388388
prompt_tokens = 0
389389
for message in kwargs.get("messages", {}):
390390
prompt_tokens += calculate_prompt_tokens(
391-
json.dumps(message), kwargs.get("model")
391+
json.dumps((str(message))), kwargs.get("model")
392392
)
393393

394394
if (
@@ -582,12 +582,11 @@ def extract_content(choice):
582582

583583
@silently_fail
584584
def _set_input_attributes(span, kwargs, attributes):
585-
585+
tools = []
586586
for field, value in attributes.model_dump(by_alias=True).items():
587587
set_span_attribute(span, field, value)
588588

589589
if kwargs.get("functions") is not None and kwargs.get("functions") != NOT_GIVEN:
590-
tools = []
591590
for function in kwargs.get("functions"):
592591
tools.append(json.dumps({"type": "function", "function": function}))
593592

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.2.11"
1+
__version__ = "2.2.12"

0 commit comments

Comments
 (0)