nvidia-nat-langchain 1.4.0a20260113__py3-none-any.whl → 1.5.0a20251223__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.
Potentially problematic release.
This version of nvidia-nat-langchain might be problematic. Click here for more details.
- nat/meta/pypi.md +1 -1
- nat/plugins/langchain/embedder.py +1 -1
- nat/plugins/langchain/llm.py +2 -66
- nat/plugins/langchain/register.py +1 -2
- nat/plugins/langchain/retriever.py +1 -1
- nat/plugins/langchain/tool_wrapper.py +1 -1
- nat/plugins/langchain/tools/code_generation_tool.py +1 -1
- nat/plugins/langchain/tools/register.py +1 -1
- nat/plugins/langchain/tools/tavily_internet_search.py +2 -3
- nat/plugins/langchain/tools/wikipedia_search.py +1 -1
- {nvidia_nat_langchain-1.4.0a20260113.dist-info → nvidia_nat_langchain-1.5.0a20251223.dist-info}/METADATA +12 -14
- nvidia_nat_langchain-1.5.0a20251223.dist-info/RECORD +19 -0
- nat/plugins/langchain/langgraph_workflow.py +0 -225
- nvidia_nat_langchain-1.4.0a20260113.dist-info/RECORD +0 -20
- {nvidia_nat_langchain-1.4.0a20260113.dist-info → nvidia_nat_langchain-1.5.0a20251223.dist-info}/WHEEL +0 -0
- {nvidia_nat_langchain-1.4.0a20260113.dist-info → nvidia_nat_langchain-1.5.0a20251223.dist-info}/entry_points.txt +0 -0
- {nvidia_nat_langchain-1.4.0a20260113.dist-info → nvidia_nat_langchain-1.5.0a20251223.dist-info}/licenses/LICENSE-3rd-party.txt +0 -0
- {nvidia_nat_langchain-1.4.0a20260113.dist-info → nvidia_nat_langchain-1.5.0a20251223.dist-info}/licenses/LICENSE.md +0 -0
- {nvidia_nat_langchain-1.4.0a20260113.dist-info → nvidia_nat_langchain-1.5.0a20251223.dist-info}/top_level.txt +0 -0
nat/meta/pypi.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
SPDX-FileCopyrightText: Copyright (c) 2025
|
|
2
|
+
SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2025
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
nat/plugins/langchain/llm.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
import logging
|
|
18
18
|
from collections.abc import Sequence
|
|
19
|
-
from typing import Any
|
|
20
19
|
from typing import TypeVar
|
|
21
20
|
|
|
22
21
|
from nat.builder.builder import Builder
|
|
@@ -30,7 +29,6 @@ from nat.llm.aws_bedrock_llm import AWSBedrockModelConfig
|
|
|
30
29
|
from nat.llm.azure_openai_llm import AzureOpenAIModelConfig
|
|
31
30
|
from nat.llm.dynamo_llm import DynamoModelConfig
|
|
32
31
|
from nat.llm.dynamo_llm import create_httpx_client_with_dynamo_hooks
|
|
33
|
-
from nat.llm.huggingface_llm import HuggingFaceConfig
|
|
34
32
|
from nat.llm.litellm_llm import LiteLlmModelConfig
|
|
35
33
|
from nat.llm.nim_llm import NIMModelConfig
|
|
36
34
|
from nat.llm.openai_llm import OpenAIModelConfig
|
|
@@ -144,7 +142,7 @@ async def azure_openai_langchain(llm_config: AzureOpenAIModelConfig, _builder: B
|
|
|
144
142
|
by_alias=True,
|
|
145
143
|
exclude_none=True,
|
|
146
144
|
exclude_unset=True),
|
|
147
|
-
api_version=llm_config.api_version,
|
|
145
|
+
api_version=llm_config.api_version,
|
|
148
146
|
)
|
|
149
147
|
|
|
150
148
|
yield _patch_llm_based_on_config(client, llm_config)
|
|
@@ -263,65 +261,3 @@ async def litellm_langchain(llm_config: LiteLlmModelConfig, _builder: Builder):
|
|
|
263
261
|
exclude={"type", "thinking", "api_type"}, by_alias=True, exclude_none=True, exclude_unset=True))
|
|
264
262
|
|
|
265
263
|
yield _patch_llm_based_on_config(client, llm_config)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
@register_llm_client(config_type=HuggingFaceConfig, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
|
|
269
|
-
async def huggingface_langchain(llm_config: HuggingFaceConfig, _builder: Builder):
|
|
270
|
-
|
|
271
|
-
import asyncio
|
|
272
|
-
|
|
273
|
-
from langchain_core.callbacks.manager import AsyncCallbackManagerForLLMRun
|
|
274
|
-
from langchain_core.messages import BaseMessage
|
|
275
|
-
from langchain_huggingface import ChatHuggingFace
|
|
276
|
-
from langchain_huggingface import HuggingFacePipeline
|
|
277
|
-
from transformers import pipeline
|
|
278
|
-
|
|
279
|
-
from nat.llm.huggingface_llm import get_cached_model
|
|
280
|
-
|
|
281
|
-
cached = get_cached_model(llm_config.model_name)
|
|
282
|
-
|
|
283
|
-
if cached is None:
|
|
284
|
-
raise ValueError(f"HuggingFace model '{llm_config.model_name}' not loaded. "
|
|
285
|
-
"The provider should have loaded it first.")
|
|
286
|
-
|
|
287
|
-
model_param = next(cached.model.parameters())
|
|
288
|
-
|
|
289
|
-
# Avoid passing an explicit device when the model is sharded via accelerate;
|
|
290
|
-
# transformers raises if device is provided alongside an accelerate-loaded model.
|
|
291
|
-
extra_kwargs = {}
|
|
292
|
-
if getattr(cached.model, "hf_device_map", None) is None:
|
|
293
|
-
extra_kwargs["device"] = model_param.device
|
|
294
|
-
|
|
295
|
-
pipe = pipeline("text-generation",
|
|
296
|
-
model=cached.model,
|
|
297
|
-
tokenizer=cached.tokenizer,
|
|
298
|
-
dtype=model_param.dtype,
|
|
299
|
-
max_new_tokens=llm_config.max_new_tokens,
|
|
300
|
-
do_sample=llm_config.temperature > 0,
|
|
301
|
-
temperature=llm_config.temperature if llm_config.temperature > 0 else None,
|
|
302
|
-
pad_token_id=cached.tokenizer.eos_token_id,
|
|
303
|
-
**extra_kwargs)
|
|
304
|
-
|
|
305
|
-
llm = HuggingFacePipeline(pipeline=pipe)
|
|
306
|
-
|
|
307
|
-
class AsyncChatHuggingFace(ChatHuggingFace):
|
|
308
|
-
"""Adds async support for local HuggingFacePipeline-backed chat models."""
|
|
309
|
-
|
|
310
|
-
async def _agenerate(self,
|
|
311
|
-
messages: list[BaseMessage],
|
|
312
|
-
stop: list[str] | None = None,
|
|
313
|
-
run_manager: AsyncCallbackManagerForLLMRun | None = None,
|
|
314
|
-
stream: bool | None = None,
|
|
315
|
-
**kwargs: Any):
|
|
316
|
-
return await asyncio.to_thread(
|
|
317
|
-
self._generate,
|
|
318
|
-
messages,
|
|
319
|
-
stop,
|
|
320
|
-
run_manager.get_sync() if run_manager else None,
|
|
321
|
-
stream,
|
|
322
|
-
**kwargs,
|
|
323
|
-
)
|
|
324
|
-
|
|
325
|
-
client = AsyncChatHuggingFace(llm=llm)
|
|
326
|
-
|
|
327
|
-
yield _patch_llm_based_on_config(client, llm_config)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2025
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
# Import any providers which need to be automatically registered here
|
|
20
20
|
|
|
21
21
|
from . import embedder
|
|
22
|
-
from . import langgraph_workflow
|
|
23
22
|
from . import llm
|
|
24
23
|
from . import tool_wrapper
|
|
25
24
|
from . import retriever
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2025
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2025
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2025
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2025
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -30,8 +30,7 @@ class TavilyInternetSearchToolConfig(FunctionBaseConfig, name="tavily_internet_s
|
|
|
30
30
|
Requires a TAVILY_API_KEY.
|
|
31
31
|
"""
|
|
32
32
|
max_results: int = 3
|
|
33
|
-
api_key: SerializableSecretStr = Field(
|
|
34
|
-
description="The API key for the Tavily service.")
|
|
33
|
+
api_key: SerializableSecretStr = Field(default="", description="The API key for the Tavily service.")
|
|
35
34
|
|
|
36
35
|
|
|
37
36
|
@register_function(config_type=TavilyInternetSearchToolConfig)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2025
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nvidia-nat-langchain
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0a20251223
|
|
4
4
|
Summary: Subpackage for LangChain/LangGraph integration in NeMo Agent toolkit
|
|
5
5
|
Author: NVIDIA Corporation
|
|
6
6
|
Maintainer: NVIDIA Corporation
|
|
@@ -16,22 +16,20 @@ Requires-Python: <3.14,>=3.11
|
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE-3rd-party.txt
|
|
18
18
|
License-File: LICENSE.md
|
|
19
|
-
Requires-Dist: nvidia-nat==v1.
|
|
20
|
-
Requires-Dist: langchain~=
|
|
21
|
-
Requires-Dist: langchain-aws~=
|
|
22
|
-
Requires-Dist: langchain-
|
|
23
|
-
Requires-Dist: langchain-
|
|
24
|
-
Requires-Dist: langchain-
|
|
25
|
-
Requires-Dist: langchain-
|
|
26
|
-
Requires-Dist: langchain-
|
|
27
|
-
Requires-Dist: langchain-
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Requires-Dist: langchain-tavily~=0.2.16
|
|
30
|
-
Requires-Dist: langgraph~=1.0.5
|
|
19
|
+
Requires-Dist: nvidia-nat==v1.5.0a20251223
|
|
20
|
+
Requires-Dist: langchain~=0.3.27
|
|
21
|
+
Requires-Dist: langchain-aws~=0.2.31
|
|
22
|
+
Requires-Dist: langchain-core~=0.3.75
|
|
23
|
+
Requires-Dist: langchain-litellm~=0.2.3
|
|
24
|
+
Requires-Dist: langchain-milvus~=0.2.1
|
|
25
|
+
Requires-Dist: langchain-nvidia-ai-endpoints~=0.3.17
|
|
26
|
+
Requires-Dist: langchain-openai~=0.3.32
|
|
27
|
+
Requires-Dist: langchain-tavily~=0.2.11
|
|
28
|
+
Requires-Dist: langgraph~=0.6.7
|
|
31
29
|
Dynamic: license-file
|
|
32
30
|
|
|
33
31
|
<!--
|
|
34
|
-
SPDX-FileCopyrightText: Copyright (c) 2025
|
|
32
|
+
SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
35
33
|
SPDX-License-Identifier: Apache-2.0
|
|
36
34
|
|
|
37
35
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
nat/meta/pypi.md,sha256=T_KFtTXVxhFM8Y6K3OlNByA5sTXLQuqqUpHgNOCvZBU,1120
|
|
2
|
+
nat/plugins/langchain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
nat/plugins/langchain/embedder.py,sha256=Ie-J4N4lvygW0zNKklKZVSYxYFcRW6p_QlRdcz0WxcE,3607
|
|
4
|
+
nat/plugins/langchain/llm.py,sha256=JBeYfhD0IGS6W-Jl6vfDqUR8Pdji5zYua2cp3fr_vyw,10950
|
|
5
|
+
nat/plugins/langchain/register.py,sha256=jgq6wSJoGQIZFJhS8RbUs25cLgNJjCkFu4M6qaWJS_4,906
|
|
6
|
+
nat/plugins/langchain/retriever.py,sha256=SWbXXOezEUuPACnmSSU497NAmEVEMj2SrFJGodkRg34,2644
|
|
7
|
+
nat/plugins/langchain/tool_wrapper.py,sha256=Zgb2_XB4bEhjPPeqS-ZH_OJT_pcQmteX7u03N_qCLfc,2121
|
|
8
|
+
nat/plugins/langchain/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
nat/plugins/langchain/tools/code_generation_tool.py,sha256=f5pna0WMOx3QOS4WnaMFKD7tBZ1-tS0PfI0IMYobtTQ,2723
|
|
10
|
+
nat/plugins/langchain/tools/register.py,sha256=uemxqLxcNk1bGX4crV52oMphLTZWonStzkXwTZeG2Rw,889
|
|
11
|
+
nat/plugins/langchain/tools/tavily_internet_search.py,sha256=W5sdZ9hobPc3xbnWPSbtFBClIn14EM8xT0XUVF2HpWo,2928
|
|
12
|
+
nat/plugins/langchain/tools/wikipedia_search.py,sha256=431YwLsjoC_mdvMZ_gY0Q37Uqaue2ASnAHpwr4jWCaU,2197
|
|
13
|
+
nvidia_nat_langchain-1.5.0a20251223.dist-info/licenses/LICENSE-3rd-party.txt,sha256=fOk5jMmCX9YoKWyYzTtfgl-SUy477audFC5hNY4oP7Q,284609
|
|
14
|
+
nvidia_nat_langchain-1.5.0a20251223.dist-info/licenses/LICENSE.md,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
|
15
|
+
nvidia_nat_langchain-1.5.0a20251223.dist-info/METADATA,sha256=ayzOmzetXYLrz8Go5tJJWkroOOVQgGnsQDW3mYhjqIE,2263
|
|
16
|
+
nvidia_nat_langchain-1.5.0a20251223.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
+
nvidia_nat_langchain-1.5.0a20251223.dist-info/entry_points.txt,sha256=4deXsMn97I012HhDw0UjoqcZ8eEoZ7BnqaRx5QmzebY,123
|
|
18
|
+
nvidia_nat_langchain-1.5.0a20251223.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
|
|
19
|
+
nvidia_nat_langchain-1.5.0a20251223.dist-info/RECORD,,
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2026, 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 importlib.util
|
|
17
|
-
import logging
|
|
18
|
-
import os
|
|
19
|
-
import sys
|
|
20
|
-
import uuid
|
|
21
|
-
from collections.abc import AsyncGenerator
|
|
22
|
-
from collections.abc import Callable
|
|
23
|
-
from pathlib import Path
|
|
24
|
-
from types import NoneType
|
|
25
|
-
from typing import Any
|
|
26
|
-
|
|
27
|
-
from dotenv import load_dotenv
|
|
28
|
-
from langchain_core.messages import BaseMessage
|
|
29
|
-
from langchain_core.messages import MessageLikeRepresentation
|
|
30
|
-
from langchain_core.messages.utils import convert_to_messages
|
|
31
|
-
from langchain_core.prompt_values import PromptValue
|
|
32
|
-
from langchain_core.runnables import RunnableConfig
|
|
33
|
-
from langgraph.graph.state import CompiledStateGraph
|
|
34
|
-
from langgraph.graph.state import StateGraph
|
|
35
|
-
from pydantic import BaseModel
|
|
36
|
-
from pydantic import ConfigDict
|
|
37
|
-
from pydantic import DirectoryPath
|
|
38
|
-
from pydantic import Field
|
|
39
|
-
from pydantic import FilePath
|
|
40
|
-
|
|
41
|
-
from nat.builder.builder import Builder
|
|
42
|
-
from nat.builder.framework_enum import LLMFrameworkEnum
|
|
43
|
-
from nat.builder.function import Function
|
|
44
|
-
from nat.cli.register_workflow import register_function
|
|
45
|
-
from nat.data_models.function import FunctionBaseConfig
|
|
46
|
-
|
|
47
|
-
GraphDefType = Callable[[RunnableConfig], CompiledStateGraph | StateGraph] | CompiledStateGraph
|
|
48
|
-
|
|
49
|
-
logger = logging.getLogger(__name__)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
class LanggraphWrapperInput(BaseModel):
|
|
53
|
-
"""Input model for the LangGraph wrapper."""
|
|
54
|
-
|
|
55
|
-
model_config = ConfigDict(extra="allow")
|
|
56
|
-
|
|
57
|
-
messages: list[MessageLikeRepresentation] | PromptValue
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
class LanggraphWrapperOutput(BaseModel):
|
|
61
|
-
"""Output model for the LangGraph wrapper."""
|
|
62
|
-
|
|
63
|
-
model_config = ConfigDict(extra="allow")
|
|
64
|
-
|
|
65
|
-
messages: list[BaseMessage]
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
class LanggraphWrapperConfig(FunctionBaseConfig, name="langgraph_wrapper"):
|
|
69
|
-
"""Configuration model for the LangGraph wrapper."""
|
|
70
|
-
|
|
71
|
-
model_config = ConfigDict(extra="forbid")
|
|
72
|
-
|
|
73
|
-
description: str = ""
|
|
74
|
-
dependencies: list[DirectoryPath] = Field(default_factory=list)
|
|
75
|
-
graph: str
|
|
76
|
-
env: FilePath | dict[str, str] | None = None
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
class LanggraphWrapperFunction(Function[LanggraphWrapperInput, NoneType, LanggraphWrapperOutput]):
|
|
80
|
-
"""Function for the LangGraph wrapper."""
|
|
81
|
-
|
|
82
|
-
def __init__(self, *, config: LanggraphWrapperConfig, description: str | None = None, graph: CompiledStateGraph):
|
|
83
|
-
"""Initialize the LangGraph wrapper function.
|
|
84
|
-
|
|
85
|
-
Args:
|
|
86
|
-
config: The configuration for the LangGraph wrapper.
|
|
87
|
-
description: The description of the LangGraph wrapper.
|
|
88
|
-
graph: The graph to wrap.
|
|
89
|
-
"""
|
|
90
|
-
|
|
91
|
-
super().__init__(config=config, description=description, converters=[LanggraphWrapperFunction.convert_to_str])
|
|
92
|
-
|
|
93
|
-
self._graph = graph
|
|
94
|
-
|
|
95
|
-
def _convert_input(self, value: Any) -> LanggraphWrapperInput:
|
|
96
|
-
|
|
97
|
-
# If the value is not a list, wrap it in a list to be compatible with the graph input and use the normal
|
|
98
|
-
# conversion logic
|
|
99
|
-
if (not isinstance(value, list)):
|
|
100
|
-
value = [value]
|
|
101
|
-
|
|
102
|
-
# Convert the value to message format using LangChain utils. Ensures is compatible with the message format
|
|
103
|
-
messages = convert_to_messages(value)
|
|
104
|
-
|
|
105
|
-
return LanggraphWrapperInput(messages=messages)
|
|
106
|
-
|
|
107
|
-
async def _ainvoke(self, value: LanggraphWrapperInput) -> LanggraphWrapperOutput:
|
|
108
|
-
|
|
109
|
-
try:
|
|
110
|
-
# Check if the graph is an async context manager (e.g., from @asynccontextmanager)
|
|
111
|
-
if hasattr(self._graph, '__aenter__') and hasattr(self._graph, '__aexit__'):
|
|
112
|
-
logger.info("Graph is an async context manager")
|
|
113
|
-
async with self._graph as graph:
|
|
114
|
-
output = await graph.ainvoke(value.model_dump())
|
|
115
|
-
else:
|
|
116
|
-
output = await self._graph.ainvoke(value.model_dump())
|
|
117
|
-
return LanggraphWrapperOutput.model_validate(output)
|
|
118
|
-
except Exception as e:
|
|
119
|
-
raise RuntimeError(f"Error in LangGraph workflow: {e}") from e
|
|
120
|
-
|
|
121
|
-
async def _astream(self, value: LanggraphWrapperInput) -> AsyncGenerator[LanggraphWrapperOutput, None]:
|
|
122
|
-
try:
|
|
123
|
-
|
|
124
|
-
if hasattr(self._graph, '__aenter__') and hasattr(self._graph, '__aexit__'):
|
|
125
|
-
logger.info("Graph is an async context manager")
|
|
126
|
-
async with self._graph as graph:
|
|
127
|
-
async for output in graph.astream(value.model_dump()):
|
|
128
|
-
yield LanggraphWrapperOutput.model_validate(output)
|
|
129
|
-
else:
|
|
130
|
-
async for output in self._graph.astream(value.model_dump()):
|
|
131
|
-
yield LanggraphWrapperOutput.model_validate(output)
|
|
132
|
-
except Exception as e:
|
|
133
|
-
raise RuntimeError(f"Error in LangGraph workflow: {e}") from e
|
|
134
|
-
|
|
135
|
-
@staticmethod
|
|
136
|
-
def convert_to_str(value: LanggraphWrapperOutput) -> str:
|
|
137
|
-
"""Convert the output to a string."""
|
|
138
|
-
if not value.messages:
|
|
139
|
-
return ""
|
|
140
|
-
|
|
141
|
-
return value.messages[-1].text
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
@register_function(config_type=LanggraphWrapperConfig, framework_wrappers=[LLMFrameworkEnum.LANGCHAIN])
|
|
145
|
-
async def register(config: LanggraphWrapperConfig, b: Builder):
|
|
146
|
-
|
|
147
|
-
# Process the dependencies. This is a list of either paths or names of packages to add to the env. For now, we only
|
|
148
|
-
# support paths.
|
|
149
|
-
added_paths = []
|
|
150
|
-
try:
|
|
151
|
-
for dependency in config.dependencies:
|
|
152
|
-
if os.path.exists(dependency) and os.path.isdir(dependency):
|
|
153
|
-
# Add the dependency to the environment
|
|
154
|
-
sys.path.append(dependency)
|
|
155
|
-
added_paths.append(dependency)
|
|
156
|
-
else:
|
|
157
|
-
raise ValueError(f"Dependency '{dependency}' (from langgraph_wrapper.dependencies) is not a "
|
|
158
|
-
"valid directory. At the moment, we only support directories. Packages "
|
|
159
|
-
"need to be installed in the environment before they can be used.")
|
|
160
|
-
|
|
161
|
-
# Process the env. This is a path to a .env file to load into the environment or a list of environment variables
|
|
162
|
-
# to set.
|
|
163
|
-
if config.env is not None:
|
|
164
|
-
if isinstance(config.env, Path):
|
|
165
|
-
if os.path.exists(config.env) and os.path.isfile(config.env):
|
|
166
|
-
load_dotenv(config.env, override=True)
|
|
167
|
-
else:
|
|
168
|
-
raise ValueError(
|
|
169
|
-
f"Env '{config.env}' is not a valid file. At the moment, we only support .env files.")
|
|
170
|
-
elif isinstance(config.env, dict):
|
|
171
|
-
for key, value in config.env.items():
|
|
172
|
-
os.environ[key] = value
|
|
173
|
-
else:
|
|
174
|
-
raise ValueError(
|
|
175
|
-
f"Env '{config.env}' is not a valid type. At the moment, we only support strings and dictionaries.")
|
|
176
|
-
|
|
177
|
-
# Now process the graph.
|
|
178
|
-
# Check that config.graph contains exactly one colon
|
|
179
|
-
if config.graph.count(":") != 1:
|
|
180
|
-
raise ValueError(
|
|
181
|
-
f"Graph definition path '{config.graph}' must contain exactly one colon to split module and name "
|
|
182
|
-
f"(e.g., '/path/to/module.py:graph_name'). Found {config.graph.count(':')}.")
|
|
183
|
-
|
|
184
|
-
# Split the graph path into module and name
|
|
185
|
-
module_path, name = config.graph.rsplit(":", 1)
|
|
186
|
-
|
|
187
|
-
unique_module_name = f"langgraph_workflow_{uuid.uuid4().hex[:8]}"
|
|
188
|
-
|
|
189
|
-
spec = importlib.util.spec_from_file_location(unique_module_name, module_path)
|
|
190
|
-
|
|
191
|
-
if spec is None:
|
|
192
|
-
raise ValueError(f"Spec not found for module: {module_path}")
|
|
193
|
-
|
|
194
|
-
module = importlib.util.module_from_spec(spec)
|
|
195
|
-
|
|
196
|
-
if module is None:
|
|
197
|
-
raise ValueError(f"Module not found for module: {module_path}")
|
|
198
|
-
|
|
199
|
-
sys.modules[unique_module_name] = module
|
|
200
|
-
|
|
201
|
-
if spec.loader is not None:
|
|
202
|
-
spec.loader.exec_module(module)
|
|
203
|
-
else:
|
|
204
|
-
raise ValueError(f"Loader not found for module: {module_path}")
|
|
205
|
-
|
|
206
|
-
graph_def: GraphDefType = getattr(module, name)
|
|
207
|
-
|
|
208
|
-
if isinstance(graph_def, CompiledStateGraph):
|
|
209
|
-
graph = graph_def
|
|
210
|
-
elif callable(graph_def):
|
|
211
|
-
graph = graph_def(RunnableConfig())
|
|
212
|
-
|
|
213
|
-
if isinstance(graph, StateGraph):
|
|
214
|
-
graph = graph.compile()
|
|
215
|
-
else:
|
|
216
|
-
raise ValueError(
|
|
217
|
-
f"Graph definition {name} is not a valid graph definition. It must be a CompiledStateGraph or a "
|
|
218
|
-
f"callable that returns a CompiledStateGraph. Got {type(graph_def)}.")
|
|
219
|
-
|
|
220
|
-
yield LanggraphWrapperFunction(config=config, description=config.description, graph=graph)
|
|
221
|
-
finally:
|
|
222
|
-
# Remove only the paths we've added to sys.path to restore sys.path to its original state
|
|
223
|
-
for dependency in added_paths:
|
|
224
|
-
if dependency in sys.path:
|
|
225
|
-
sys.path.remove(dependency)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
nat/meta/pypi.md,sha256=2-Iz2utuG3Ou2A9JgWK0iBFmYfoYnTHfGQ72K8H7-YY,1125
|
|
2
|
-
nat/plugins/langchain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
nat/plugins/langchain/embedder.py,sha256=qg5SRBYl2L84vQ0DlFB_W6JfjSDrJLtyyDyueIXr2ck,3612
|
|
4
|
-
nat/plugins/langchain/langgraph_workflow.py,sha256=rcdyLLNAw5iGgY3Y-ec0hGGur0VYnp2zzfx8r4cXsoA,9234
|
|
5
|
-
nat/plugins/langchain/llm.py,sha256=bKr4HvhBtEeNxUP-tgZjdEUd_4JiM7wwoHZLTrCaBzM,13544
|
|
6
|
-
nat/plugins/langchain/register.py,sha256=N0ZlhiztDRJ8CEZfMB4aKUu-KlS-fz-mubg5JuYBm9s,944
|
|
7
|
-
nat/plugins/langchain/retriever.py,sha256=c2bZuAWYGN-zFypCsF_xirP3BJw1RuISrtBsRZFsxYs,2649
|
|
8
|
-
nat/plugins/langchain/tool_wrapper.py,sha256=5Ily-4V81et29M1Vdw6hp_jaK_xpVvPRlTtUa8YBMlk,2126
|
|
9
|
-
nat/plugins/langchain/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
nat/plugins/langchain/tools/code_generation_tool.py,sha256=jAs6vmTOJMha-UMcrBQdSSdJFCNNBjG3n8VpRGjViRE,2728
|
|
11
|
-
nat/plugins/langchain/tools/register.py,sha256=RKUjEgtoc37bL5F9C5dizaSHaisesLT8A5QcMFnm8HI,894
|
|
12
|
-
nat/plugins/langchain/tools/tavily_internet_search.py,sha256=bVcz_xYDtoKe8DlsCdys_bMUWZVGm3MzL1aspQImLHU,3010
|
|
13
|
-
nat/plugins/langchain/tools/wikipedia_search.py,sha256=uVB-lYT9meafThom1bvax87QKr-E1NEiY_bm4RIAa-4,2202
|
|
14
|
-
nvidia_nat_langchain-1.4.0a20260113.dist-info/licenses/LICENSE-3rd-party.txt,sha256=fOk5jMmCX9YoKWyYzTtfgl-SUy477audFC5hNY4oP7Q,284609
|
|
15
|
-
nvidia_nat_langchain-1.4.0a20260113.dist-info/licenses/LICENSE.md,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
|
16
|
-
nvidia_nat_langchain-1.4.0a20260113.dist-info/METADATA,sha256=6M8v1AzeE-A0YY1bUe54vMW3Az-ffTAcu_rGCWwQ1OE,2347
|
|
17
|
-
nvidia_nat_langchain-1.4.0a20260113.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
18
|
-
nvidia_nat_langchain-1.4.0a20260113.dist-info/entry_points.txt,sha256=4deXsMn97I012HhDw0UjoqcZ8eEoZ7BnqaRx5QmzebY,123
|
|
19
|
-
nvidia_nat_langchain-1.4.0a20260113.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
|
|
20
|
-
nvidia_nat_langchain-1.4.0a20260113.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|