Skip to content

Commit 34720b4

Browse files
authored
Merge branch 'main' into fix-azure-util
2 parents 54bf509 + 5f3cd80 commit 34720b4

File tree

2 files changed

+9
-107
lines changed

2 files changed

+9
-107
lines changed

tests/mlmodel_langchain/test_chain.py

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,90 +1642,6 @@ def test_async_langchain_chain_outside_transaction(
16421642
loop.run_until_complete(getattr(runnable, call_function)(input_))
16431643

16441644

1645-
@pytest.mark.parametrize(
1646-
"create_function,call_function,call_function_args,call_function_kwargs,expected_events",
1647-
(
1648-
pytest.param(
1649-
create_structured_output_runnable,
1650-
"ainvoke",
1651-
({"input": "Sally is 13"},),
1652-
{"config": {"tags": ["bar"], "metadata": {"id": "123"}}},
1653-
chat_completion_recorded_events_runnable_invoke,
1654-
id="runnable_chain.ainvoke-with-args-and-kwargs",
1655-
),
1656-
pytest.param(
1657-
create_structured_output_chain,
1658-
"ainvoke",
1659-
({"input": "Sally is 13"},),
1660-
{"config": {"tags": ["bar"], "metadata": {"id": "123"}}, "return_only_outputs": True},
1661-
chat_completion_recorded_events_invoke,
1662-
id="chain.ainvoke-with-args-and-kwargs",
1663-
),
1664-
),
1665-
)
1666-
def test_multiple_async_langchain_chain(
1667-
set_trace_info,
1668-
json_schema,
1669-
prompt,
1670-
chat_openai_client,
1671-
create_function,
1672-
call_function,
1673-
call_function_args,
1674-
call_function_kwargs,
1675-
expected_events,
1676-
loop,
1677-
):
1678-
call1 = events_with_context_attrs(expected_events.copy())
1679-
call1[0][1]["request_id"] = "b1883d9d-10d6-4b67-a911-f72849704e92"
1680-
call1[1][1]["request_id"] = "b1883d9d-10d6-4b67-a911-f72849704e92"
1681-
call1[2][1]["request_id"] = "b1883d9d-10d6-4b67-a911-f72849704e92"
1682-
call2 = events_with_context_attrs(expected_events.copy())
1683-
call2[0][1]["request_id"] = "a58aa0c0-c854-4657-9e7b-4cce442f3b61"
1684-
call2[1][1]["request_id"] = "a58aa0c0-c854-4657-9e7b-4cce442f3b61"
1685-
call2[2][1]["request_id"] = "a58aa0c0-c854-4657-9e7b-4cce442f3b61"
1686-
1687-
@reset_core_stats_engine()
1688-
@validate_custom_events(call1 + call2)
1689-
# 3 langchain events and 5 openai events.
1690-
@validate_custom_event_count(count=16)
1691-
@validate_transaction_metrics(
1692-
name="test_chain:test_multiple_async_langchain_chain.<locals>._test",
1693-
scoped_metrics=[(f"Llm/chain/LangChain/{call_function}", 2)],
1694-
rollup_metrics=[(f"Llm/chain/LangChain/{call_function}", 2)],
1695-
custom_metrics=[(f"Supportability/Python/ML/LangChain/{langchain.__version__}", 1)],
1696-
background_task=True,
1697-
)
1698-
@background_task()
1699-
def _test():
1700-
with patch("langchain_core.callbacks.manager.uuid", autospec=True) as mock_uuid:
1701-
mock_uuid.uuid4.side_effect = [
1702-
uuid.UUID("b1883d9d-10d6-4b67-a911-f72849704e92"), # first call
1703-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b61"),
1704-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b61"), # second call
1705-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b63"),
1706-
uuid.UUID("b1883d9d-10d6-4b67-a911-f72849704e93"),
1707-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b64"),
1708-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b65"),
1709-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b66"),
1710-
]
1711-
set_trace_info()
1712-
add_custom_attribute("llm.conversation_id", "my-awesome-id")
1713-
add_custom_attribute("llm.foo", "bar")
1714-
add_custom_attribute("non_llm_attr", "python-agent")
1715-
1716-
runnable = create_function(json_schema, chat_openai_client, prompt)
1717-
with WithLlmCustomAttributes({"context": "attr"}):
1718-
call1 = asyncio.ensure_future(
1719-
getattr(runnable, call_function)(*call_function_args, **call_function_kwargs), loop=loop
1720-
)
1721-
call2 = asyncio.ensure_future(
1722-
getattr(runnable, call_function)(*call_function_args, **call_function_kwargs), loop=loop
1723-
)
1724-
loop.run_until_complete(asyncio.gather(call1, call2))
1725-
1726-
_test()
1727-
1728-
17291645
@reset_core_stats_engine()
17301646
@validate_custom_events(recorded_events_retrieval_chain_response)
17311647
@validate_custom_event_count(count=17)

tests/mlmodel_langchain/test_tool.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,7 @@ def test_langchain_tool_disabled_ai_monitoring_events_async(set_trace_info, sing
384384

385385
def test_langchain_multiple_async_calls(set_trace_info, single_arg_tool, multi_arg_tool, loop):
386386
call1 = single_arg_tool_recorded_events.copy()
387-
call1[0][1]["run_id"] = "b1883d9d-10d6-4b67-a911-f72849704e92"
388387
call2 = multi_arg_tool_recorded_events.copy()
389-
call2[0][1]["run_id"] = "a58aa0c0-c854-4657-9e7b-4cce442f3b61"
390388
expected_events = call1 + call2
391389

392390
@reset_core_stats_engine()
@@ -401,27 +399,15 @@ def test_langchain_multiple_async_calls(set_trace_info, single_arg_tool, multi_a
401399
def _test():
402400
set_trace_info()
403401

404-
with patch("langchain_core.callbacks.manager.uuid", autospec=True) as mock_uuid:
405-
mock_uuid.uuid4.side_effect = [
406-
uuid.UUID("b1883d9d-10d6-4b67-a911-f72849704e92"), # first call
407-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b61"),
408-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b61"), # second call
409-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b63"),
410-
uuid.UUID("b1883d9d-10d6-4b67-a911-f72849704e93"),
411-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b64"),
412-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b65"),
413-
uuid.UUID("a58aa0c0-c854-4657-9e7b-4cce442f3b66"),
414-
]
415-
416-
loop.run_until_complete(
417-
asyncio.gather(
418-
single_arg_tool.arun({"query": "Python Agent"}),
419-
multi_arg_tool.arun(
420-
{"first_num": 53, "second_num": 28},
421-
tags=["python", "test_tags"],
422-
metadata={"test": "langchain", "test_run": True},
423-
),
424-
)
402+
loop.run_until_complete(
403+
asyncio.gather(
404+
single_arg_tool.arun({"query": "Python Agent"}),
405+
multi_arg_tool.arun(
406+
{"first_num": 53, "second_num": 28},
407+
tags=["python", "test_tags"],
408+
metadata={"test": "langchain", "test_run": True},
409+
),
425410
)
411+
)
426412

427413
_test()

0 commit comments

Comments
 (0)