Skip to content

Commit e63bee2

Browse files
committed
Merge branch 'development' into release
2 parents 510e4b8 + d812b71 commit e63bee2

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/langtrace_python_sdk/instrumentation/langchain_core/patch.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ def traced_method(wrapped, instance, args, kwargs):
8787
completion_tokens = result.usage.completion_tokens
8888
span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, prompt_tokens)
8989
span.set_attribute(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, completion_tokens)
90-
91-
elif result.generations[0][0].text:
90+
elif hasattr(result, 'generations') and len(result.generations) > 0 and len(result.generations[0]) > 0 and hasattr(result.generations[0][0], 'text') and isinstance(result.generations[0][0].text, str):
9291
span.set_attribute(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, instance.get_num_tokens(result.generations[0][0].text))
93-
elif isinstance(args[0][0], str):
92+
elif len(args) > 0 and len(args[0]) > 0 and not hasattr(args[0][0], 'text') and hasattr(instance, 'get_num_tokens'):
9493
span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, instance.get_num_tokens(args[0][0]))
95-
96-
else:
94+
elif len(args) > 0 and len(args[0]) > 0 and hasattr(args[0][0], 'text') and isinstance(args[0][0].text, str) and hasattr(instance, 'get_num_tokens'):
9795
span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, instance.get_num_tokens(args[0][0].text))
9896

9997
span.set_status(StatusCode.OK)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.3.7"
1+
__version__ = "2.3.8"

0 commit comments

Comments
 (0)