Skip to content

Commit 461aefe

Browse files
committed
Merge branch 'develop' of github.com:NVIDIA/NeMo-Agent-Toolkit into david-document-async-endpoints
Signed-off-by: David Gardner <[email protected]>
2 parents 8b22f69 + c506b31 commit 461aefe

36 files changed

+5341
-2439
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Default Approval rule
2-
* @nvidia/aiqtoolkit-developers
2+
* @nvidia/nat-developers
3+
4+
# Dependency changes
5+
uv.lock @nvidia/nat-dep-approvers

packages/nvidia_nat_crewai/src/nat/plugins/crewai/llm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ async def azure_openai_crewai(llm_config: AzureOpenAIModelConfig, _builder: Buil
9191
"thinking",
9292
},
9393
by_alias=True,
94+
exclude_none=True,
9495
),
9596
model=model,
9697
)
@@ -110,7 +111,7 @@ async def nim_crewai(llm_config: NIMModelConfig, _builder: Builder):
110111
os.environ["NVIDIA_NIM_API_KEY"] = nvidia_api_key
111112

112113
client = LLM(
113-
**llm_config.model_dump(exclude={"type", "model_name", "thinking"}, by_alias=True),
114+
**llm_config.model_dump(exclude={"type", "model_name", "thinking"}, by_alias=True, exclude_none=True),
114115
model=f"nvidia_nim/{llm_config.model_name}",
115116
)
116117

@@ -122,6 +123,6 @@ async def openai_crewai(llm_config: OpenAIModelConfig, _builder: Builder):
122123

123124
from crewai import LLM
124125

125-
client = LLM(**llm_config.model_dump(exclude={"type", "thinking"}, by_alias=True))
126+
client = LLM(**llm_config.model_dump(exclude={"type", "thinking"}, by_alias=True, exclude_none=True))
126127

127128
yield _patch_llm_based_on_config(client, llm_config)

packages/nvidia_nat_langchain/src/nat/plugins/langchain/embedder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def azure_openai_langchain(embedder_config: AzureOpenAIEmbedderModelConfig
2828

2929
from langchain_openai import AzureOpenAIEmbeddings
3030

31-
client = AzureOpenAIEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True))
31+
client = AzureOpenAIEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
3232

3333
if isinstance(embedder_config, RetryMixin):
3434
client = patch_with_retry(client,
@@ -44,7 +44,7 @@ async def nim_langchain(embedder_config: NIMEmbedderModelConfig, builder: Builde
4444

4545
from langchain_nvidia_ai_endpoints import NVIDIAEmbeddings
4646

47-
client = NVIDIAEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True))
47+
client = NVIDIAEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
4848

4949
if isinstance(embedder_config, RetryMixin):
5050
client = patch_with_retry(client,
@@ -60,7 +60,7 @@ async def openai_langchain(embedder_config: OpenAIEmbedderModelConfig, builder:
6060

6161
from langchain_openai import OpenAIEmbeddings
6262

63-
client = OpenAIEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True))
63+
client = OpenAIEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
6464

6565
if isinstance(embedder_config, RetryMixin):
6666
client = patch_with_retry(client,

packages/nvidia_nat_langchain/src/nat/plugins/langchain/llm.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ async def aws_bedrock_langchain(llm_config: AWSBedrockModelConfig, _builder: Bui
107107

108108
from langchain_aws import ChatBedrockConverse
109109

110-
client = ChatBedrockConverse(**llm_config.model_dump(exclude={"type", "context_size", "thinking"}, by_alias=True))
110+
client = ChatBedrockConverse(**llm_config.model_dump(
111+
exclude={"type", "context_size", "thinking"},
112+
by_alias=True,
113+
exclude_none=True,
114+
))
111115

112116
yield _patch_llm_based_on_config(client, llm_config)
113117

@@ -117,7 +121,7 @@ async def azure_openai_langchain(llm_config: AzureOpenAIModelConfig, _builder: B
117121

118122
from langchain_openai import AzureChatOpenAI
119123

120-
client = AzureChatOpenAI(**llm_config.model_dump(exclude={"type", "thinking"}, by_alias=True))
124+
client = AzureChatOpenAI(**llm_config.model_dump(exclude={"type", "thinking"}, by_alias=True, exclude_none=True))
121125

122126
yield _patch_llm_based_on_config(client, llm_config)
123127

@@ -129,7 +133,7 @@ async def nim_langchain(llm_config: NIMModelConfig, _builder: Builder):
129133

130134
# prefer max_completion_tokens over max_tokens
131135
client = ChatNVIDIA(
132-
**llm_config.model_dump(exclude={"type", "max_tokens", "thinking"}, by_alias=True),
136+
**llm_config.model_dump(exclude={"type", "max_tokens", "thinking"}, by_alias=True, exclude_none=True),
133137
max_completion_tokens=llm_config.max_tokens,
134138
)
135139

@@ -142,6 +146,11 @@ async def openai_langchain(llm_config: OpenAIModelConfig, _builder: Builder):
142146
from langchain_openai import ChatOpenAI
143147

144148
# If stream_usage is specified, it will override the default value of True.
145-
client = ChatOpenAI(stream_usage=True, **llm_config.model_dump(exclude={"type", "thinking"}, by_alias=True))
149+
client = ChatOpenAI(stream_usage=True,
150+
**llm_config.model_dump(
151+
exclude={"type", "thinking"},
152+
by_alias=True,
153+
exclude_none=True,
154+
))
146155

147156
yield _patch_llm_based_on_config(client, llm_config)

packages/nvidia_nat_llama_index/src/nat/plugins/llama_index/embedder.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def azure_openai_llama_index(embedder_config: AzureOpenAIEmbedderModelConf
2828

2929
from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding
3030

31-
client = AzureOpenAIEmbedding(**embedder_config.model_dump(exclude={"type"}, by_alias=True))
31+
client = AzureOpenAIEmbedding(**embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
3232

3333
if isinstance(embedder_config, RetryMixin):
3434
client = patch_with_retry(client,
@@ -40,25 +40,30 @@ async def azure_openai_llama_index(embedder_config: AzureOpenAIEmbedderModelConf
4040

4141

4242
@register_embedder_client(config_type=NIMEmbedderModelConfig, wrapper_type=LLMFrameworkEnum.LLAMA_INDEX)
43-
async def nim_llamaindex(embedder_config: NIMEmbedderModelConfig, _builder: Builder):
43+
async def nim_llama_index(embedder_config: NIMEmbedderModelConfig, _builder: Builder):
4444

45-
from llama_index.embeddings.nvidia import NVIDIAEmbedding
45+
from llama_index.embeddings.nvidia import NVIDIAEmbedding # pylint: disable=no-name-in-module
4646

47-
config_obj = {
48-
**embedder_config.model_dump(exclude={"type", "model_name"}, by_alias=True),
49-
"model":
50-
embedder_config.model_name,
51-
}
47+
client = NVIDIAEmbedding(
48+
**embedder_config.model_dump(exclude={"type", "model_name"}, by_alias=True, exclude_none=True),
49+
model=embedder_config.model_name,
50+
)
5251

53-
yield NVIDIAEmbedding(**config_obj)
52+
if isinstance(embedder_config, RetryMixin):
53+
client = patch_with_retry(client,
54+
retries=embedder_config.num_retries,
55+
retry_codes=embedder_config.retry_on_status_codes,
56+
retry_on_messages=embedder_config.retry_on_errors)
57+
58+
yield client
5459

5560

5661
@register_embedder_client(config_type=OpenAIEmbedderModelConfig, wrapper_type=LLMFrameworkEnum.LLAMA_INDEX)
5762
async def openai_llama_index(embedder_config: OpenAIEmbedderModelConfig, _builder: Builder):
5863

5964
from llama_index.embeddings.openai import OpenAIEmbedding
6065

61-
client = OpenAIEmbedding(**embedder_config.model_dump(exclude={"type"}, by_alias=True))
66+
client = OpenAIEmbedding(**embedder_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
6267

6368
if isinstance(embedder_config, RetryMixin):
6469
client = patch_with_retry(client,

packages/nvidia_nat_opentelemetry/src/nat/plugins/opentelemetry/otlp_span_redaction_adapter_exporter.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515

1616
import logging
1717
from collections.abc import Callable
18+
from collections.abc import Mapping
19+
from enum import Enum
20+
from typing import Any
1821

1922
from nat.builder.context import ContextState
20-
from nat.observability.mixin.tagging_config_mixin import PrivacyLevel
21-
from nat.observability.processor.header_redaction_processor import HeaderRedactionProcessor
23+
from nat.observability.processor.redaction import SpanHeaderRedactionProcessor
2224
from nat.observability.processor.span_tagging_processor import SpanTaggingProcessor
2325
from nat.plugins.opentelemetry.otlp_span_adapter_exporter import OTLPSpanAdapterExporter
2426

@@ -61,11 +63,10 @@ def should_redact(auth_key: str) -> bool:
6163
endpoint="https://api.service.com/v1/traces",
6264
headers={"Authorization": "Bearer your-token"},
6365
redaction_attributes=["user.email", "request.body"],
64-
redaction_header="x-user-id",
66+
redaction_headers=["x-user-id"],
6567
redaction_callback=should_redact,
6668
redaction_value="REDACTED",
67-
privacy_tag_key="privacy.level",
68-
privacy_tag_value=PrivacyLevel.HIGH,
69+
tags={"privacy.level": PrivacyLevel.HIGH, "service.type": "sensitive"},
6970
batch_size=50,
7071
flush_interval=10.0
7172
)
@@ -84,13 +85,13 @@ def __init__(
8485
resource_attributes: dict[str, str] | None = None,
8586
# Redaction args
8687
redaction_attributes: list[str] | None = None,
87-
redaction_header: str | None = None,
88-
redaction_callback: Callable[[str], bool] | None = None,
88+
redaction_headers: list[str] | None = None,
89+
redaction_callback: Callable[..., Any] | None = None,
8990
redaction_enabled: bool = False,
9091
force_redaction: bool = False,
9192
redaction_value: str = "[REDACTED]",
92-
privacy_tag_key: str | None = None,
93-
privacy_tag_value: PrivacyLevel | None = None,
93+
redaction_tag: str | None = None,
94+
tags: Mapping[str, Enum | str] | None = None,
9495
# OTLPSpanExporterMixin args
9596
endpoint: str,
9697
headers: dict[str, str] | None = None,
@@ -99,20 +100,20 @@ def __init__(
99100
100101
Args:
101102
context_state: The context state for the exporter.
102-
batch_size: Number of spans to batch before exporting.
103-
flush_interval: Time in seconds between automatic batch flushes.
104-
max_queue_size: Maximum number of spans to queue.
105-
drop_on_overflow: Whether to drop spans when queue is full.
106-
shutdown_timeout: Maximum time to wait for export completion during shutdown.
103+
batch_size: Number of spans to batch before exporting, default is 100.
104+
flush_interval: Time in seconds between automatic batch flushes, default is 5.0.
105+
max_queue_size: Maximum number of spans to queue, default is 1000.
106+
drop_on_overflow: Whether to drop spans when queue is full, default is False.
107+
shutdown_timeout: Maximum time to wait for export completion during shutdown, default is 10.0.
107108
resource_attributes: Additional resource attributes for spans.
108109
redaction_attributes: List of span attribute keys to redact when conditions are met.
109-
redaction_header: Header key to check for authentication/user identification.
110-
redaction_callback: Function to determine if spans should be redacted based on header value.
111-
redaction_enabled: Whether the redaction processor is enabled.
112-
force_redaction: If True, always redact regardless of header checks.
113-
redaction_value: Value to replace redacted attributes with.
114-
privacy_tag_key: Key name for the privacy level tag to add to spans.
115-
privacy_tag_value: Privacy level value to assign to spans.
110+
redaction_headers: List of header keys to check for authentication/user identification.
111+
redaction_callback: Function that returns true to redact spans based on header value, false otherwise.
112+
redaction_enabled: Whether the redaction processor is enabled, default is False.
113+
force_redaction: If True, always redact regardless of header checks, default is False.
114+
redaction_value: Value to replace redacted attributes with, default is "[REDACTED]".
115+
tags: Mapping of tag keys to their values (enums or strings) to add to spans.
116+
redaction_tag: Tag to add to spans when redaction occurs.
116117
endpoint: The endpoint for the OTLP service.
117118
headers: The headers for the OTLP service.
118119
**otlp_kwargs: Additional keyword arguments for the OTLP service.
@@ -129,16 +130,14 @@ def __init__(
129130
**otlp_kwargs)
130131

131132
# Insert redaction and tagging processors to the front of the processing pipeline
132-
self.add_processor(HeaderRedactionProcessor(attributes=redaction_attributes,
133-
header=redaction_header,
134-
callback=redaction_callback,
135-
enabled=redaction_enabled,
136-
force_redact=force_redaction,
137-
redaction_value=redaction_value),
133+
self.add_processor(SpanHeaderRedactionProcessor(attributes=redaction_attributes or [],
134+
headers=redaction_headers or [],
135+
callback=redaction_callback or (lambda _: False),
136+
enabled=redaction_enabled,
137+
force_redact=force_redaction,
138+
redaction_value=redaction_value,
139+
redaction_tag=redaction_tag),
138140
name="header_redaction",
139141
position=0)
140142

141-
self.add_processor(SpanTaggingProcessor(tag_key=privacy_tag_key,
142-
tag_value=privacy_tag_value.value if privacy_tag_value else None),
143-
name="span_privacy_tagging",
144-
position=1)
143+
self.add_processor(SpanTaggingProcessor(tags=tags), name="span_sensitivity_tagging", position=1)

0 commit comments

Comments
 (0)