nvidia-nat-langchain 1.2.0a20250813__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nat/meta/pypi.md +23 -0
- nat/plugins/langchain/__init__.py +0 -0
- nat/plugins/langchain/embedder.py +37 -0
- nat/plugins/langchain/llm.py +77 -0
- nat/plugins/langchain/register.py +26 -0
- nat/plugins/langchain/retriever.py +54 -0
- nat/plugins/langchain/tool_wrapper.py +52 -0
- nat/plugins/langchain/tools/__init__.py +0 -0
- nat/plugins/langchain/tools/code_generation_tool.py +66 -0
- nat/plugins/langchain/tools/register.py +24 -0
- nat/plugins/langchain/tools/tavily_internet_search.py +60 -0
- nat/plugins/langchain/tools/wikipedia_search.py +52 -0
- nvidia_nat_langchain-1.2.0a20250813.dist-info/METADATA +40 -0
- nvidia_nat_langchain-1.2.0a20250813.dist-info/RECORD +17 -0
- nvidia_nat_langchain-1.2.0a20250813.dist-info/WHEEL +5 -0
- nvidia_nat_langchain-1.2.0a20250813.dist-info/entry_points.txt +3 -0
- nvidia_nat_langchain-1.2.0a20250813.dist-info/top_level.txt +1 -0
nat/meta/pypi.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<!--
|
2
|
+
SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
-->
|
17
|
+
|
18
|
+

|
19
|
+
|
20
|
+
# NVIDIA NeMo Agent Toolkit Subpackage
|
21
|
+
This is a subpackage for LangChain and LangGraph integration in NeMo Agent toolkit.
|
22
|
+
|
23
|
+
For more information about the NVIDIA NeMo Agent toolkit, please visit the [NeMo Agent toolkit GitHub Repo](https://github.com/NVIDIA/NeMo-Agent-Toolkit).
|
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
from nat.builder.builder import Builder
|
17
|
+
from nat.builder.framework_enum import LLMFrameworkEnum
|
18
|
+
from nat.cli.register_workflow import register_embedder_client
|
19
|
+
from nat.data_models.retry_mixin import RetryMixin
|
20
|
+
from nat.embedder.openai_embedder import OpenAIEmbedderModelConfig
|
21
|
+
from nat.utils.exception_handlers.automatic_retries import patch_with_retry
|
22
|
+
|
23
|
+
|
24
|
+
@register_embedder_client(config_type=OpenAIEmbedderModelConfig, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
25
|
+
async def openai_langchain(embedder_config: OpenAIEmbedderModelConfig, builder: Builder):
|
26
|
+
|
27
|
+
from langchain_openai import OpenAIEmbeddings
|
28
|
+
|
29
|
+
client = OpenAIEmbeddings(**embedder_config.model_dump(exclude={"type"}, by_alias=True))
|
30
|
+
|
31
|
+
if isinstance(embedder_config, RetryMixin):
|
32
|
+
client = patch_with_retry(client,
|
33
|
+
retries=embedder_config.num_retries,
|
34
|
+
retry_codes=embedder_config.retry_on_status_codes,
|
35
|
+
retry_on_messages=embedder_config.retry_on_errors)
|
36
|
+
|
37
|
+
yield client
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
from nat.builder.builder import Builder
|
17
|
+
from nat.builder.framework_enum import LLMFrameworkEnum
|
18
|
+
from nat.cli.register_workflow import register_llm_client
|
19
|
+
from nat.data_models.retry_mixin import RetryMixin
|
20
|
+
from nat.llm.aws_bedrock_llm import AWSBedrockModelConfig
|
21
|
+
from nat.llm.nim_llm import NIMModelConfig
|
22
|
+
from nat.llm.openai_llm import OpenAIModelConfig
|
23
|
+
from nat.utils.exception_handlers.automatic_retries import patch_with_retry
|
24
|
+
|
25
|
+
|
26
|
+
@register_llm_client(config_type=NIMModelConfig, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
27
|
+
async def nim_langchain(llm_config: NIMModelConfig, builder: Builder):
|
28
|
+
|
29
|
+
from langchain_nvidia_ai_endpoints import ChatNVIDIA
|
30
|
+
|
31
|
+
client = ChatNVIDIA(**llm_config.model_dump(exclude={"type"}, by_alias=True))
|
32
|
+
|
33
|
+
if isinstance(llm_config, RetryMixin):
|
34
|
+
client = patch_with_retry(client,
|
35
|
+
retries=llm_config.num_retries,
|
36
|
+
retry_codes=llm_config.retry_on_status_codes,
|
37
|
+
retry_on_messages=llm_config.retry_on_errors)
|
38
|
+
|
39
|
+
yield client
|
40
|
+
|
41
|
+
|
42
|
+
@register_llm_client(config_type=OpenAIModelConfig, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
43
|
+
async def openai_langchain(llm_config: OpenAIModelConfig, builder: Builder):
|
44
|
+
|
45
|
+
from langchain_openai import ChatOpenAI
|
46
|
+
|
47
|
+
# Default kwargs for OpenAI to include usage metadata in the response. If the user has set stream_usage to False, we
|
48
|
+
# will not include this.
|
49
|
+
default_kwargs = {"stream_usage": True}
|
50
|
+
|
51
|
+
kwargs = {**default_kwargs, **llm_config.model_dump(exclude={"type"}, by_alias=True)}
|
52
|
+
|
53
|
+
client = ChatOpenAI(**kwargs)
|
54
|
+
|
55
|
+
if isinstance(llm_config, RetryMixin):
|
56
|
+
client = patch_with_retry(client,
|
57
|
+
retries=llm_config.num_retries,
|
58
|
+
retry_codes=llm_config.retry_on_status_codes,
|
59
|
+
retry_on_messages=llm_config.retry_on_errors)
|
60
|
+
|
61
|
+
yield client
|
62
|
+
|
63
|
+
|
64
|
+
@register_llm_client(config_type=AWSBedrockModelConfig, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
65
|
+
async def aws_bedrock_langchain(llm_config: AWSBedrockModelConfig, builder: Builder):
|
66
|
+
|
67
|
+
from langchain_aws import ChatBedrockConverse
|
68
|
+
|
69
|
+
client = ChatBedrockConverse(**llm_config.model_dump(exclude={"type", "context_size"}, by_alias=True))
|
70
|
+
|
71
|
+
if isinstance(llm_config, RetryMixin):
|
72
|
+
client = patch_with_retry(client,
|
73
|
+
retries=llm_config.num_retries,
|
74
|
+
retry_codes=llm_config.retry_on_status_codes,
|
75
|
+
retry_on_messages=llm_config.retry_on_errors)
|
76
|
+
|
77
|
+
yield client
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# pylint: disable=unused-import
|
17
|
+
# flake8: noqa
|
18
|
+
# isort:skip_file
|
19
|
+
|
20
|
+
# Import any providers which need to be automatically registered here
|
21
|
+
|
22
|
+
from . import embedder
|
23
|
+
from . import llm
|
24
|
+
from . import tool_wrapper
|
25
|
+
from . import retriever
|
26
|
+
from .tools import register
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
from nat.builder.builder import Builder
|
17
|
+
from nat.builder.framework_enum import LLMFrameworkEnum
|
18
|
+
from nat.cli.register_workflow import register_retriever_client
|
19
|
+
from nat.retriever.milvus.register import MilvusRetrieverConfig
|
20
|
+
from nat.retriever.nemo_retriever.register import NemoRetrieverConfig
|
21
|
+
|
22
|
+
|
23
|
+
@register_retriever_client(config_type=NemoRetrieverConfig, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
24
|
+
async def nemo_langchain(retriever_config: NemoRetrieverConfig, builder: Builder):
|
25
|
+
from nat.retriever.nemo_retriever.retriever import NemoLangchainRetriever
|
26
|
+
from nat.retriever.nemo_retriever.retriever import NemoRetriever
|
27
|
+
|
28
|
+
retriever = NemoRetriever(**retriever_config.model_dump(exclude={"type", "top_k", "collection_name"}))
|
29
|
+
optional_fields = ["collection_name", "top_k", "output_fields"]
|
30
|
+
model_dict = retriever_config.model_dump()
|
31
|
+
optional_args = {field: model_dict[field] for field in optional_fields if model_dict[field] is not None}
|
32
|
+
|
33
|
+
retriever.bind(**optional_args)
|
34
|
+
|
35
|
+
yield NemoLangchainRetriever(client=retriever)
|
36
|
+
|
37
|
+
|
38
|
+
@register_retriever_client(config_type=MilvusRetrieverConfig, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
39
|
+
async def milvus_langchain(retriever_config: MilvusRetrieverConfig, builder: Builder):
|
40
|
+
from langchain_milvus import Milvus
|
41
|
+
|
42
|
+
retriever_config.connection_args.update({"uri": str(retriever_config.uri)})
|
43
|
+
embedder = await builder.get_embedder(embedder_name=retriever_config.embedding_model,
|
44
|
+
wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
45
|
+
yield Milvus(embedding_function=embedder,
|
46
|
+
**retriever_config.model_dump(include={
|
47
|
+
"connection_args",
|
48
|
+
"collection_name",
|
49
|
+
"content_field",
|
50
|
+
"vector_field",
|
51
|
+
"search_params",
|
52
|
+
"description"
|
53
|
+
},
|
54
|
+
by_alias=True)).as_retriever()
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
import logging
|
17
|
+
|
18
|
+
from nat.builder.builder import Builder
|
19
|
+
from nat.builder.framework_enum import LLMFrameworkEnum
|
20
|
+
from nat.builder.function import Function
|
21
|
+
from nat.cli.register_workflow import register_tool_wrapper
|
22
|
+
|
23
|
+
logger = logging.getLogger(__name__)
|
24
|
+
|
25
|
+
|
26
|
+
@register_tool_wrapper(wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
27
|
+
def langchain_tool_wrapper(name: str, fn: Function, builder: Builder): # pylint: disable=unused-argument
|
28
|
+
|
29
|
+
import asyncio
|
30
|
+
|
31
|
+
from langchain_core.tools.structured import StructuredTool
|
32
|
+
|
33
|
+
assert fn.input_schema is not None, "Tool must have input schema"
|
34
|
+
|
35
|
+
loop = asyncio.get_running_loop()
|
36
|
+
|
37
|
+
# Provide a sync wrapper for the tool to support synchronous tool calls
|
38
|
+
def _sync_fn(*args, **kwargs):
|
39
|
+
logger.warning("Invoking a synchronous tool call, performance may be degraded: `%s`", fn.instance_name)
|
40
|
+
return loop.run_until_complete(fn.acall_invoke(*args, **kwargs))
|
41
|
+
|
42
|
+
if fn.description is None:
|
43
|
+
logger.warning("No description set for `%s` falling back to instance name: `%s`",
|
44
|
+
type(fn).__name__,
|
45
|
+
fn.instance_name)
|
46
|
+
_sync_fn.__doc__ = fn.instance_name
|
47
|
+
|
48
|
+
return StructuredTool.from_function(coroutine=fn.acall_invoke,
|
49
|
+
func=_sync_fn,
|
50
|
+
name=name,
|
51
|
+
description=fn.description,
|
52
|
+
args_schema=fn.input_schema)
|
File without changes
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
import logging
|
17
|
+
|
18
|
+
from nat.builder.builder import Builder
|
19
|
+
from nat.builder.framework_enum import LLMFrameworkEnum
|
20
|
+
from nat.builder.function_info import FunctionInfo
|
21
|
+
from nat.cli.register_workflow import register_function
|
22
|
+
from nat.data_models.component_ref import LLMRef
|
23
|
+
from nat.data_models.function import FunctionBaseConfig
|
24
|
+
|
25
|
+
log = logging.getLogger(__name__)
|
26
|
+
|
27
|
+
|
28
|
+
class CodeGenerationTool(FunctionBaseConfig, name="code_generation"):
|
29
|
+
"""
|
30
|
+
Tool for generating code using the configured LLM.
|
31
|
+
"""
|
32
|
+
llm_name: LLMRef
|
33
|
+
verbose: bool = False
|
34
|
+
programming_language: str = "Python"
|
35
|
+
description: str = ("Useful to generate Python code. For any questions about code generation, you must only use "
|
36
|
+
"this tool!")
|
37
|
+
|
38
|
+
|
39
|
+
@register_function(config_type=CodeGenerationTool)
|
40
|
+
async def code_generation_tool(config: CodeGenerationTool, builder: Builder):
|
41
|
+
from langchain_core.prompts.chat import ChatPromptTemplate
|
42
|
+
|
43
|
+
log.info('Initializing code generation tool\nGetting tool LLM from config')
|
44
|
+
llm = await builder.get_llm(config.llm_name, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
45
|
+
|
46
|
+
system_prompt = """
|
47
|
+
You are a helpful code assistant that can teach a junior developer how to code. Your language of
|
48
|
+
choice is {programming_language}. Don't explain the code, just generate the code block itself.
|
49
|
+
"""
|
50
|
+
user_prompt = """
|
51
|
+
{question}
|
52
|
+
"""
|
53
|
+
prompt = ChatPromptTemplate.from_messages([("system", system_prompt), ("user", user_prompt)])
|
54
|
+
log.info("Filling tool's prompt variable from config")
|
55
|
+
prompt = prompt.partial(programming_language=config.programming_language)
|
56
|
+
tool = prompt | llm
|
57
|
+
log.info('Initialized code generation tool')
|
58
|
+
|
59
|
+
async def _inner(query: str) -> str:
|
60
|
+
log.info('Running code generation tool')
|
61
|
+
response = await tool.ainvoke({"question": query})
|
62
|
+
if config.verbose:
|
63
|
+
log.debug('Tool input was: %s\nTool output is: \n%s', query, response)
|
64
|
+
return response.content
|
65
|
+
|
66
|
+
yield FunctionInfo.from_fn(_inner, description=config.description)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# pylint: disable=unused-import
|
17
|
+
# flake8: noqa
|
18
|
+
# isort:skip_file
|
19
|
+
|
20
|
+
# Import any providers which need to be automatically registered here
|
21
|
+
|
22
|
+
from . import code_generation_tool
|
23
|
+
from . import tavily_internet_search
|
24
|
+
from . import wikipedia_search
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
from nat.builder.builder import Builder
|
17
|
+
from nat.builder.function_info import FunctionInfo
|
18
|
+
from nat.cli.register_workflow import register_function
|
19
|
+
from nat.data_models.function import FunctionBaseConfig
|
20
|
+
|
21
|
+
|
22
|
+
# Internet Search tool
|
23
|
+
class TavilyInternetSearchToolConfig(FunctionBaseConfig, name="tavily_internet_search"):
|
24
|
+
"""
|
25
|
+
Tool that retrieves relevant contexts from web search (using Tavily) for the given question.
|
26
|
+
Requires a TAVILY_API_KEY.
|
27
|
+
"""
|
28
|
+
max_results: int = 3
|
29
|
+
api_key: str = ""
|
30
|
+
|
31
|
+
|
32
|
+
@register_function(config_type=TavilyInternetSearchToolConfig)
|
33
|
+
async def tavily_internet_search(tool_config: TavilyInternetSearchToolConfig, builder: Builder):
|
34
|
+
import os
|
35
|
+
|
36
|
+
from langchain_community.tools import TavilySearchResults
|
37
|
+
|
38
|
+
if not os.environ.get("TAVILY_API_KEY"):
|
39
|
+
os.environ["TAVILY_API_KEY"] = tool_config.api_key
|
40
|
+
# This tavily tool requires an API Key and it must be set as an environment variable (TAVILY_API_KEY)
|
41
|
+
# Refer to create_customize_workflow.md for instructions of getting the API key
|
42
|
+
|
43
|
+
async def _tavily_internet_search(question: str) -> str:
|
44
|
+
# Search the web and get the requested amount of results
|
45
|
+
tavily_search = TavilySearchResults(max_results=tool_config.max_results)
|
46
|
+
search_docs = await tavily_search.ainvoke({'query': question})
|
47
|
+
# Format
|
48
|
+
web_search_results = "\n\n---\n\n".join(
|
49
|
+
[f'<Document href="{doc["url"]}"/>\n{doc["content"]}\n</Document>' for doc in search_docs])
|
50
|
+
return web_search_results
|
51
|
+
|
52
|
+
# Create a Generic AIQ Toolkit tool that can be used with any supported LLM framework
|
53
|
+
yield FunctionInfo.from_fn(
|
54
|
+
_tavily_internet_search,
|
55
|
+
description=("""This tool retrieves relevant contexts from web search (using Tavily) for the given question.
|
56
|
+
|
57
|
+
Args:
|
58
|
+
question (str): The question to be answered.
|
59
|
+
"""),
|
60
|
+
)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
from nat.builder.builder import Builder
|
17
|
+
from nat.builder.function_info import FunctionInfo
|
18
|
+
from nat.cli.register_workflow import register_function
|
19
|
+
from nat.data_models.function import FunctionBaseConfig
|
20
|
+
|
21
|
+
|
22
|
+
# Wikipedia Search tool
|
23
|
+
class WikiSearchToolConfig(FunctionBaseConfig, name="wiki_search"):
|
24
|
+
"""
|
25
|
+
Tool that retrieves relevant contexts from wikipedia search for the given question.
|
26
|
+
"""
|
27
|
+
max_results: int = 2
|
28
|
+
|
29
|
+
|
30
|
+
# Wiki search
|
31
|
+
@register_function(config_type=WikiSearchToolConfig)
|
32
|
+
async def wiki_search(tool_config: WikiSearchToolConfig, builder: Builder):
|
33
|
+
from langchain_community.document_loaders import WikipediaLoader
|
34
|
+
|
35
|
+
async def _wiki_search(question: str) -> str:
|
36
|
+
# Search the web and get the requested amount of results
|
37
|
+
search_docs = await WikipediaLoader(query=question, load_max_docs=tool_config.max_results).aload()
|
38
|
+
wiki_search_results = "\n\n---\n\n".join([
|
39
|
+
f'<Document source="{doc.metadata["source"]}" '
|
40
|
+
f'page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>' for doc in search_docs
|
41
|
+
])
|
42
|
+
return wiki_search_results
|
43
|
+
|
44
|
+
# Create an AIQ Toolkit wiki search tool that can be used with any supported LLM framework
|
45
|
+
yield FunctionInfo.from_fn(
|
46
|
+
_wiki_search,
|
47
|
+
description=("""This tool retrieves relevant contexts from wikipedia search for the given question.
|
48
|
+
|
49
|
+
Args:
|
50
|
+
question (str): The question to be answered.
|
51
|
+
"""),
|
52
|
+
)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: nvidia-nat-langchain
|
3
|
+
Version: 1.2.0a20250813
|
4
|
+
Summary: Subpackage for LangChain and LangGraph integration in NeMo Agent toolkit
|
5
|
+
Keywords: ai,rag,agents
|
6
|
+
Classifier: Programming Language :: Python
|
7
|
+
Requires-Python: <3.13,>=3.11
|
8
|
+
Description-Content-Type: text/markdown
|
9
|
+
Requires-Dist: nvidia-nat==v1.2.0a20250813
|
10
|
+
Requires-Dist: langchain-aws~=0.2.1
|
11
|
+
Requires-Dist: langchain-core~=0.3.7
|
12
|
+
Requires-Dist: langchain-nvidia-ai-endpoints~=0.3.5
|
13
|
+
Requires-Dist: langchain-milvus~=0.1.5
|
14
|
+
Requires-Dist: langchain-openai~=0.3.5
|
15
|
+
Requires-Dist: langgraph~=0.2.50
|
16
|
+
Requires-Dist: langchain-milvus~=0.1.8
|
17
|
+
|
18
|
+
<!--
|
19
|
+
SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
20
|
+
SPDX-License-Identifier: Apache-2.0
|
21
|
+
|
22
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
23
|
+
you may not use this file except in compliance with the License.
|
24
|
+
You may obtain a copy of the License at
|
25
|
+
|
26
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
27
|
+
|
28
|
+
Unless required by applicable law or agreed to in writing, software
|
29
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
30
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
31
|
+
See the License for the specific language governing permissions and
|
32
|
+
limitations under the License.
|
33
|
+
-->
|
34
|
+
|
35
|
+

|
36
|
+
|
37
|
+
# NVIDIA NeMo Agent Toolkit Subpackage
|
38
|
+
This is a subpackage for LangChain and LangGraph integration in NeMo Agent toolkit.
|
39
|
+
|
40
|
+
For more information about the NVIDIA NeMo Agent toolkit, please visit the [NeMo Agent toolkit GitHub Repo](https://github.com/NVIDIA/NeMo-Agent-Toolkit).
|
@@ -0,0 +1,17 @@
|
|
1
|
+
nat/meta/pypi.md,sha256=jxJ0L4icshSNDFo-5xV1OQrSqK9R31Lx4K6Tg3oXP44,1135
|
2
|
+
nat/plugins/langchain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
nat/plugins/langchain/embedder.py,sha256=81LER6jIwmbD2QATH4G-DuovOkQd1890bl5A8DZb99w,1727
|
4
|
+
nat/plugins/langchain/llm.py,sha256=i_DffRmQ9PEELuXFYR2ouU0LRkPKAjwZi1z65xGrxws,3293
|
5
|
+
nat/plugins/langchain/register.py,sha256=UwxFY-HsZ5n32XPpqDtLvBamiw1Pdavtf2oYSK_XGtY,938
|
6
|
+
nat/plugins/langchain/retriever.py,sha256=SWbXXOezEUuPACnmSSU497NAmEVEMj2SrFJGodkRg34,2644
|
7
|
+
nat/plugins/langchain/tool_wrapper.py,sha256=dLK09a8lrmytNkIuhTaSByuLdW23aVmIcr3REyuJTMA,2156
|
8
|
+
nat/plugins/langchain/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
nat/plugins/langchain/tools/code_generation_tool.py,sha256=qL3HBiOQzVPLw4EiUOWeswckuVX8ynG2UQXYBLxR_gI,2724
|
10
|
+
nat/plugins/langchain/tools/register.py,sha256=3cf4RH2tQ_qOtZviwXQUqK5dKiVUJQYach4djxGpcOU,921
|
11
|
+
nat/plugins/langchain/tools/tavily_internet_search.py,sha256=0zGMRb4pVkDtvaDFpycRHM9GgWZcxwXkQC9N0pnyB9w,2620
|
12
|
+
nat/plugins/langchain/tools/wikipedia_search.py,sha256=SBWiGz1j8qpiGvJXsVqY9kbrowZKdbaSccR99JKrKFA,2206
|
13
|
+
nvidia_nat_langchain-1.2.0a20250813.dist-info/METADATA,sha256=Ft-Hlm5VGXfYZrPRFSdzUF2048-gOqlQH4PbSnWBAyw,1746
|
14
|
+
nvidia_nat_langchain-1.2.0a20250813.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
15
|
+
nvidia_nat_langchain-1.2.0a20250813.dist-info/entry_points.txt,sha256=4deXsMn97I012HhDw0UjoqcZ8eEoZ7BnqaRx5QmzebY,123
|
16
|
+
nvidia_nat_langchain-1.2.0a20250813.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
|
17
|
+
nvidia_nat_langchain-1.2.0a20250813.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
nat
|