Skip to content

Commit

Permalink
fix langchain chain test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Kim committed Nov 27, 2024
1 parent 3346570 commit e28c218
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions ddtrace/llmobs/_integrations/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def _llmobs_set_meta_tags_from_chain(self, span: Span, args, kwargs, outputs: An
inputs = get_argument_value(args, kwargs, 0, "input")
else:
inputs = kwargs
formatted_inputs = ""
if inputs is not None:
formatted_inputs = self.format_io(inputs)
formatted_outputs = ""
Expand All @@ -310,8 +311,8 @@ def _llmobs_set_meta_tags_from_chain(self, span: Span, args, kwargs, outputs: An
span._set_ctx_items(
{
SPAN_KIND: "workflow",
INPUT_VALUE: formatted_inputs,
OUTPUT_VALUE: formatted_outputs,
INPUT_VALUE: str(formatted_inputs),
OUTPUT_VALUE: str(formatted_outputs),
}
)

Expand Down
9 changes: 5 additions & 4 deletions tests/contrib/langchain/test_langchain_llmobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,14 @@ def test_llmobs_chain_schema_io(self, langchain, mock_llmobs_span_writer, mock_t
input_value=str(
{
"ability": "world capitals",
"history": [["user", "Can you be my science teacher instead?"], ["assistant", "Yes"]],
"history": [("user", "Can you be my science teacher instead?"), ("assistant", "Yes")],
"input": "What's the powerhouse of the cell?",
}
),
output_value=str(
{
"ability": "world capitals",
"history": [["user", "Can you be my science teacher instead?"], ["assistant", "Yes"]],
"history": [("user", "Can you be my science teacher instead?"), ("assistant", "Yes")],
"input": "What's the powerhouse of the cell?",
"text": "Mitochondria.",
}
Expand Down Expand Up @@ -608,14 +608,15 @@ def test_llmobs_chain_schema_io(self, langchain_core, langchain_openai, mock_llm
cassette_name="lcel_openai_chain_schema_io.yaml",
)
assert mock_llmobs_span_writer.enqueue.call_count == 2

_assert_expected_llmobs_chain_span(
trace[0],
mock_llmobs_span_writer,
input_value=str(
[
{
"ability": "world capitals",
"history": [["user", "Can you be my science teacher instead?"], ["assistant", "Yes"]],
"history": [("user", "Can you be my science teacher instead?"), ("assistant", "Yes")],
"input": "What's the powerhouse of the cell?",
}
]
Expand Down Expand Up @@ -1066,7 +1067,7 @@ def test_llmobs_with_openai_enabled_non_ascii_value(self):
with get_request_vcr(subdirectory_name="langchain_community").use_cassette("openai_completion_non_ascii.yaml"):
llm.invoke("안녕,\n 지금 몇 시야?")
langchain_span = self.mock_llmobs_span_writer.enqueue.call_args_list[0][0][0]
assert langchain_span["meta"]["input"]["value"] == str([{"content": "안녕,\\n 지금 몇 시야?"}])
assert langchain_span["meta"]["input"]["value"] == [{"content": "안녕,\n 지금 몇 시야?"}]

@run_in_subprocess(env_overrides=openai_env_config)
def test_llmobs_with_openai_disabled(self):
Expand Down

0 comments on commit e28c218

Please sign in to comment.