Skip to content

Commit

Permalink
Change Langhchain->LangChain per agent spec (#1176)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
hmstepanek and mergify[bot] authored Jul 10, 2024
1 parent f7efc7d commit 9b6b2e5
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 112 deletions.
24 changes: 12 additions & 12 deletions newrelic/hooks/mlmodel_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ async def wrap_asimilarity_search(wrapped, instance, args, kwargs):
if not settings.ai_monitoring.enabled:
return await wrapped(*args, **kwargs)

transaction.add_ml_model_info("Langchain", LANGCHAIN_VERSION)
transaction.add_ml_model_info("LangChain", LANGCHAIN_VERSION)
transaction._add_agent_attribute("llm", True)

search_id = str(uuid.uuid4())

ft = FunctionTrace(name=wrapped.__name__, group="Llm/vectorstore/Langchain")
ft = FunctionTrace(name=wrapped.__name__, group="Llm/vectorstore/LangChain")
ft.__enter__()
linking_metadata = get_trace_linking_metadata()
try:
Expand Down Expand Up @@ -193,12 +193,12 @@ def wrap_similarity_search(wrapped, instance, args, kwargs):
if not settings.ai_monitoring.enabled:
return wrapped(*args, **kwargs)

transaction.add_ml_model_info("Langchain", LANGCHAIN_VERSION)
transaction.add_ml_model_info("LangChain", LANGCHAIN_VERSION)
transaction._add_agent_attribute("llm", True)

search_id = str(uuid.uuid4())

ft = FunctionTrace(name=wrapped.__name__, group="Llm/vectorstore/Langchain")
ft = FunctionTrace(name=wrapped.__name__, group="Llm/vectorstore/LangChain")
ft.__enter__()
linking_metadata = get_trace_linking_metadata()
try:
Expand Down Expand Up @@ -277,14 +277,14 @@ def wrap_tool_sync_run(wrapped, instance, args, kwargs):
return wrapped(*args, **kwargs)

# Framework metric also used for entity tagging in the UI
transaction.add_ml_model_info("Langchain", LANGCHAIN_VERSION)
transaction.add_ml_model_info("LangChain", LANGCHAIN_VERSION)
transaction._add_agent_attribute("llm", True)

tool_id, metadata, tags, tool_input, tool_name, tool_description, run_args = _capture_tool_info(
instance, wrapped, args, kwargs
)

ft = FunctionTrace(name=wrapped.__name__, group="Llm/tool/Langchain")
ft = FunctionTrace(name=wrapped.__name__, group="Llm/tool/LangChain")
ft.__enter__()
linking_metadata = get_trace_linking_metadata()
try:
Expand Down Expand Up @@ -334,14 +334,14 @@ async def wrap_tool_async_run(wrapped, instance, args, kwargs):
return await wrapped(*args, **kwargs)

# Framework metric also used for entity tagging in the UI
transaction.add_ml_model_info("Langchain", LANGCHAIN_VERSION)
transaction.add_ml_model_info("LangChain", LANGCHAIN_VERSION)
transaction._add_agent_attribute("llm", True)

tool_id, metadata, tags, tool_input, tool_name, tool_description, run_args = _capture_tool_info(
instance, wrapped, args, kwargs
)

ft = FunctionTrace(name=wrapped.__name__, group="Llm/tool/Langchain")
ft = FunctionTrace(name=wrapped.__name__, group="Llm/tool/LangChain")
ft.__enter__()
linking_metadata = get_trace_linking_metadata()
try:
Expand Down Expand Up @@ -536,7 +536,7 @@ async def wrap_chain_async_run(wrapped, instance, args, kwargs):
return await wrapped(*args, **kwargs)

# Framework metric also used for entity tagging in the UI
transaction.add_ml_model_info("Langchain", LANGCHAIN_VERSION)
transaction.add_ml_model_info("LangChain", LANGCHAIN_VERSION)
transaction._add_agent_attribute("llm", True)

run_args = bind_args(wrapped, args, kwargs)
Expand All @@ -546,7 +546,7 @@ async def wrap_chain_async_run(wrapped, instance, args, kwargs):
# The trace group will reflect from where it has started.
# The AgentExecutor class has an attribute "agent" that does
# not exist within the Chain class
group_name = "Llm/agent/Langchain" if hasattr(instance, "agent") else "Llm/chain/Langchain"
group_name = "Llm/agent/LangChain" if hasattr(instance, "agent") else "Llm/chain/LangChain"
ft = FunctionTrace(name=wrapped.__name__, group=group_name)
ft.__enter__()
linking_metadata = get_trace_linking_metadata()
Expand Down Expand Up @@ -584,7 +584,7 @@ def wrap_chain_sync_run(wrapped, instance, args, kwargs):
return wrapped(*args, **kwargs)

# Framework metric also used for entity tagging in the UI
transaction.add_ml_model_info("Langchain", LANGCHAIN_VERSION)
transaction.add_ml_model_info("LangChain", LANGCHAIN_VERSION)
transaction._add_agent_attribute("llm", True)

run_args = bind_args(wrapped, args, kwargs)
Expand All @@ -594,7 +594,7 @@ def wrap_chain_sync_run(wrapped, instance, args, kwargs):
# The trace group will reflect from where it has started.
# The AgentExecutor class has an attribute "agent" that does
# not exist within the Chain class
group_name = "Llm/agent/Langchain" if hasattr(instance, "agent") else "Llm/chain/Langchain"
group_name = "Llm/agent/LangChain" if hasattr(instance, "agent") else "Llm/chain/LangChain"
ft = FunctionTrace(name=wrapped.__name__, group=group_name)
ft.__enter__()
linking_metadata = get_trace_linking_metadata()
Expand Down
12 changes: 6 additions & 6 deletions tests/mlmodel_langchain/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def prompt():
@reset_core_stats_engine()
@validate_transaction_metrics(
name="test_agent:test_sync_agent",
scoped_metrics=[("Llm/agent/Langchain/invoke", 1)],
rollup_metrics=[("Llm/agent/Langchain/invoke", 1)],
scoped_metrics=[("Llm/agent/LangChain/invoke", 1)],
rollup_metrics=[("Llm/agent/LangChain/invoke", 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand All @@ -78,10 +78,10 @@ def test_sync_agent(chat_openai_client, tools, prompt):
@reset_core_stats_engine()
@validate_transaction_metrics(
name="test_agent:test_async_agent",
scoped_metrics=[("Llm/agent/Langchain/ainvoke", 1)],
rollup_metrics=[("Llm/agent/Langchain/ainvoke", 1)],
scoped_metrics=[("Llm/agent/LangChain/ainvoke", 1)],
rollup_metrics=[("Llm/agent/LangChain/ainvoke", 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down
78 changes: 39 additions & 39 deletions tests/mlmodel_langchain/test_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,10 @@
@validate_custom_event_count(count=7)
@validate_transaction_metrics(
name="test_chain:test_langchain_chain_list_response",
scoped_metrics=[("Llm/chain/Langchain/invoke", 1)],
rollup_metrics=[("Llm/chain/Langchain/invoke", 1)],
scoped_metrics=[("Llm/chain/LangChain/invoke", 1)],
rollup_metrics=[("Llm/chain/LangChain/invoke", 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -608,10 +608,10 @@ def test_langchain_chain(
@validate_custom_event_count(count=8)
@validate_transaction_metrics(
name="test_chain:test_langchain_chain.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -682,10 +682,10 @@ def test_langchain_chain_no_content(
@validate_custom_event_count(count=8)
@validate_transaction_metrics(
name="test_chain:test_langchain_chain_no_content.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -781,10 +781,10 @@ def test_langchain_chain_error_in_openai(
@validate_custom_event_count(count=6)
@validate_transaction_metrics(
name="test_chain:test_langchain_chain_error_in_openai.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -858,10 +858,10 @@ def test_langchain_chain_error_in_langchain(
@validate_custom_event_count(count=2)
@validate_transaction_metrics(
name="test_chain:test_langchain_chain_error_in_langchain.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -936,10 +936,10 @@ def test_langchain_chain_error_in_langchain_no_content(
@validate_custom_event_count(count=2)
@validate_transaction_metrics(
name="test_chain:test_langchain_chain_error_in_langchain_no_content.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -1005,10 +1005,10 @@ def test_langchain_chain_ai_monitoring_disabled(
@validate_custom_event_count(count=7)
@validate_transaction_metrics(
name="test_chain:test_async_langchain_chain_list_response",
scoped_metrics=[("Llm/chain/Langchain/ainvoke", 1)],
rollup_metrics=[("Llm/chain/Langchain/ainvoke", 1)],
scoped_metrics=[("Llm/chain/LangChain/ainvoke", 1)],
rollup_metrics=[("Llm/chain/LangChain/ainvoke", 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -1050,10 +1050,10 @@ def test_async_langchain_chain_list_response(
@validate_custom_event_count(count=7)
@validate_transaction_metrics(
name="test_chain:test_async_langchain_chain_list_response_no_content",
scoped_metrics=[("Llm/chain/Langchain/ainvoke", 1)],
rollup_metrics=[("Llm/chain/Langchain/ainvoke", 1)],
scoped_metrics=[("Llm/chain/LangChain/ainvoke", 1)],
rollup_metrics=[("Llm/chain/LangChain/ainvoke", 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -1186,10 +1186,10 @@ def test_async_langchain_chain(
@validate_custom_event_count(count=8)
@validate_transaction_metrics(
name="test_chain:test_async_langchain_chain.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -1285,10 +1285,10 @@ def test_async_langchain_chain_error_in_openai(
@validate_custom_event_count(count=6)
@validate_transaction_metrics(
name="test_chain:test_async_langchain_chain_error_in_openai.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -1361,10 +1361,10 @@ def test_async_langchain_chain_error_in_langchain(
@validate_custom_event_count(count=2)
@validate_transaction_metrics(
name="test_chain:test_async_langchain_chain_error_in_langchain.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -1438,10 +1438,10 @@ def test_async_langchain_chain_error_in_langchain_no_content(
@validate_custom_event_count(count=2)
@validate_transaction_metrics(
name="test_chain:test_async_langchain_chain_error_in_langchain_no_content.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 1)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 1)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down Expand Up @@ -1541,10 +1541,10 @@ def test_multiple_async_langchain_chain(
@validate_custom_event_count(count=16)
@validate_transaction_metrics(
name="test_chain:test_multiple_async_langchain_chain.<locals>._test",
scoped_metrics=[("Llm/chain/Langchain/%s" % call_function, 2)],
rollup_metrics=[("Llm/chain/Langchain/%s" % call_function, 2)],
scoped_metrics=[("Llm/chain/LangChain/%s" % call_function, 2)],
rollup_metrics=[("Llm/chain/LangChain/%s" % call_function, 2)],
custom_metrics=[
("Supportability/Python/ML/Langchain/%s" % langchain.__version__, 1),
("Supportability/Python/ML/LangChain/%s" % langchain.__version__, 1),
],
background_task=True,
)
Expand Down
Loading

0 comments on commit 9b6b2e5

Please sign in to comment.