Skip to content

Commit 5eb7599

Browse files
committed
fix(langchain): incorrect role on generations
1 parent ba1aa4c commit 5eb7599

File tree

1 file changed

+12
-10
lines changed
  • packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain

1 file changed

+12
-10
lines changed

packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ def set_chat_response(span: Span, response: LLMResult) -> None:
211211
for generations in response.generations:
212212
for generation in generations:
213213
prefix = f"{GenAIAttributes.GEN_AI_COMPLETION}.{i}"
214-
_set_span_attribute(
215-
span,
216-
f"{prefix}.role",
217-
_message_type_to_role(generation.type),
218-
)
219214

220215
# Try to get content from various sources
221216
content = None
@@ -268,12 +263,19 @@ def set_chat_response(span: Span, response: LLMResult) -> None:
268263
else generation.message.additional_kwargs.get("tool_calls")
269264
)
270265
if tool_calls and isinstance(tool_calls, list):
271-
_set_span_attribute(
272-
span,
273-
f"{prefix}.role",
274-
"assistant",
275-
)
276266
_set_chat_tool_calls(span, prefix, tool_calls)
267+
268+
_set_span_attribute(
269+
span,
270+
f"{prefix}.role",
271+
_message_type_to_role(generation.message.type),
272+
)
273+
else:
274+
_set_span_attribute(
275+
span,
276+
f"{prefix}.role",
277+
"assistant",
278+
)
277279
i += 1
278280

279281

0 commit comments

Comments
 (0)