nvidia-nat-llama-index 1.3.0a20250826__py3-none-any.whl → 1.3.0a20250828__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.
@@ -13,33 +13,70 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ from collections.abc import Sequence
17
+ from typing import TypeVar
18
+
16
19
  from nat.builder.builder import Builder
17
20
  from nat.builder.framework_enum import LLMFrameworkEnum
18
21
  from nat.cli.register_workflow import register_llm_client
22
+ from nat.data_models.llm import LLMBaseConfig
19
23
  from nat.data_models.retry_mixin import RetryMixin
24
+ from nat.data_models.thinking_mixin import ThinkingMixin
20
25
  from nat.llm.aws_bedrock_llm import AWSBedrockModelConfig
21
26
  from nat.llm.azure_openai_llm import AzureOpenAIModelConfig
22
27
  from nat.llm.nim_llm import NIMModelConfig
23
28
  from nat.llm.openai_llm import OpenAIModelConfig
29
+ from nat.llm.utils.thinking import BaseThinkingInjector
30
+ from nat.llm.utils.thinking import FunctionArgumentWrapper
31
+ from nat.llm.utils.thinking import patch_with_thinking
24
32
  from nat.utils.exception_handlers.automatic_retries import patch_with_retry
33
+ from nat.utils.type_utils import override
25
34
 
35
+ ModelType = TypeVar("ModelType")
26
36
 
27
- @register_llm_client(config_type=AWSBedrockModelConfig, wrapper_type=LLMFrameworkEnum.LLAMA_INDEX)
28
- async def aws_bedrock_llama_index(llm_config: AWSBedrockModelConfig, _builder: Builder):
29
37
 
30
- from llama_index.llms.bedrock import Bedrock
38
+ def _patch_llm_based_on_config(client: ModelType, llm_config: LLMBaseConfig) -> ModelType:
31
39
 
32
- kwargs = llm_config.model_dump(exclude={"type", "max_tokens"}, by_alias=True)
40
+ from llama_index.core.base.llms.types import ChatMessage
33
41
 
34
- llm = Bedrock(**kwargs)
42
+ class LlamaIndexThinkingInjector(BaseThinkingInjector):
43
+
44
+ @override
45
+ def inject(self, messages: Sequence[ChatMessage], *args, **kwargs) -> FunctionArgumentWrapper:
46
+ new_messages = [ChatMessage(role="system", content=self.system_prompt)] + list(messages)
47
+ return FunctionArgumentWrapper(new_messages, *args, **kwargs)
48
+
49
+ if isinstance(llm_config, ThinkingMixin) and llm_config.thinking_system_prompt is not None:
50
+ client = patch_with_thinking(
51
+ client,
52
+ LlamaIndexThinkingInjector(
53
+ system_prompt=llm_config.thinking_system_prompt,
54
+ function_names=[
55
+ "chat",
56
+ "stream_chat",
57
+ "achat",
58
+ "astream_chat",
59
+ ],
60
+ ))
35
61
 
36
62
  if isinstance(llm_config, RetryMixin):
37
- llm = patch_with_retry(llm,
38
- retries=llm_config.num_retries,
39
- retry_codes=llm_config.retry_on_status_codes,
40
- retry_on_messages=llm_config.retry_on_errors)
63
+ client = patch_with_retry(client,
64
+ retries=llm_config.num_retries,
65
+ retry_codes=llm_config.retry_on_status_codes,
66
+ retry_on_messages=llm_config.retry_on_errors)
67
+
68
+ return client
69
+
70
+
71
+ @register_llm_client(config_type=AWSBedrockModelConfig, wrapper_type=LLMFrameworkEnum.LLAMA_INDEX)
72
+ async def aws_bedrock_llama_index(llm_config: AWSBedrockModelConfig, _builder: Builder):
73
+
74
+ from llama_index.llms.bedrock import Bedrock
41
75
 
42
- yield llm
76
+ # LlamaIndex uses context_size instead of max_tokens
77
+ llm = Bedrock(**llm_config.model_dump(exclude={"type", "top_p"}, by_alias=True), )
78
+
79
+ yield _patch_llm_based_on_config(llm, llm_config)
43
80
 
44
81
 
45
82
  @register_llm_client(config_type=AzureOpenAIModelConfig, wrapper_type=LLMFrameworkEnum.LLAMA_INDEX)
@@ -47,17 +84,9 @@ async def azure_openai_llama_index(llm_config: AzureOpenAIModelConfig, _builder:
47
84
 
48
85
  from llama_index.llms.azure_openai import AzureOpenAI
49
86
 
50
- kwargs = llm_config.model_dump(exclude={"type"}, by_alias=True)
51
-
52
- llm = AzureOpenAI(**kwargs)
53
-
54
- if isinstance(llm_config, RetryMixin):
55
- llm = patch_with_retry(llm,
56
- retries=llm_config.num_retries,
57
- retry_codes=llm_config.retry_on_status_codes,
58
- retry_on_messages=llm_config.retry_on_errors)
87
+ llm = AzureOpenAI(**llm_config.model_dump(exclude={"type"}, by_alias=True))
59
88
 
60
- yield llm
89
+ yield _patch_llm_based_on_config(llm, llm_config)
61
90
 
62
91
 
63
92
  @register_llm_client(config_type=NIMModelConfig, wrapper_type=LLMFrameworkEnum.LLAMA_INDEX)
@@ -65,20 +94,9 @@ async def nim_llama_index(llm_config: NIMModelConfig, _builder: Builder):
65
94
 
66
95
  from llama_index.llms.nvidia import NVIDIA
67
96
 
68
- kwargs = llm_config.model_dump(exclude={"type"}, by_alias=True)
69
-
70
- if ("base_url" in kwargs and kwargs["base_url"] is None):
71
- del kwargs["base_url"]
72
-
73
- llm = NVIDIA(**kwargs)
97
+ llm = NVIDIA(**llm_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
74
98
 
75
- if isinstance(llm_config, RetryMixin):
76
- llm = patch_with_retry(llm,
77
- retries=llm_config.num_retries,
78
- retry_codes=llm_config.retry_on_status_codes,
79
- retry_on_messages=llm_config.retry_on_errors)
80
-
81
- yield llm
99
+ yield _patch_llm_based_on_config(llm, llm_config)
82
100
 
83
101
 
84
102
  @register_llm_client(config_type=OpenAIModelConfig, wrapper_type=LLMFrameworkEnum.LLAMA_INDEX)
@@ -86,17 +104,6 @@ async def openai_llama_index(llm_config: OpenAIModelConfig, _builder: Builder):
86
104
 
87
105
  from llama_index.llms.openai import OpenAI
88
106
 
89
- kwargs = llm_config.model_dump(exclude={"type"}, by_alias=True)
90
-
91
- if ("base_url" in kwargs and kwargs["base_url"] is None):
92
- del kwargs["base_url"]
93
-
94
- llm = OpenAI(**kwargs)
95
-
96
- if isinstance(llm_config, RetryMixin):
97
- llm = patch_with_retry(llm,
98
- retries=llm_config.num_retries,
99
- retry_codes=llm_config.retry_on_status_codes,
100
- retry_on_messages=llm_config.retry_on_errors)
107
+ llm = OpenAI(**llm_config.model_dump(exclude={"type"}, by_alias=True, exclude_none=True))
101
108
 
102
- yield llm
109
+ yield _patch_llm_based_on_config(llm, llm_config)
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nvidia-nat-llama-index
3
- Version: 1.3.0a20250826
3
+ Version: 1.3.0a20250828
4
4
  Summary: Subpackage for Llama-Index integration in NeMo Agent toolkit
5
5
  Keywords: ai,rag,agents
6
6
  Classifier: Programming Language :: Python
7
7
  Requires-Python: <3.13,>=3.11
8
8
  Description-Content-Type: text/markdown
9
- Requires-Dist: nvidia-nat==v1.3.0a20250826
9
+ Requires-Dist: nvidia-nat==v1.3.0a20250828
10
10
  Requires-Dist: llama-index-core~=0.12.21
11
11
  Requires-Dist: llama-index-embeddings-azure-openai~=0.3.1
12
12
  Requires-Dist: llama-index-embeddings-nvidia~=0.3.1
@@ -1,11 +1,11 @@
1
1
  nat/meta/pypi.md,sha256=s9C3pgWB0HLIXTx5QPryNOWN0O2fIRIap0p9_zCHlTs,1112
2
2
  nat/plugins/llama_index/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  nat/plugins/llama_index/embedder.py,sha256=6US_DR4dWwHuhRnf2KlN8TVIV7wk7NHTDFyBwgMyEQc,3093
4
- nat/plugins/llama_index/llm.py,sha256=PtXibAiZWCv1pjEeP5A77Tyi-rVUGCHc81jEoIdy3p8,3949
4
+ nat/plugins/llama_index/llm.py,sha256=_aQ1hgM-YR7GleotwlSe6Dw4Of0wdwKRLCYZMN2VcIU,4454
5
5
  nat/plugins/llama_index/register.py,sha256=1x_b8u6cuQwh4Iz_7TcIFWXvLIL9IIKUPE-zR9d6ug8,859
6
6
  nat/plugins/llama_index/tool_wrapper.py,sha256=VFKMIIeLdWqHwW2Ax11E2w-_9w3ow6Iuhra1Hk78RYM,1387
7
- nvidia_nat_llama_index-1.3.0a20250826.dist-info/METADATA,sha256=FmUGKqn6BuxmgR9v0Z-xaIOBe-U2iIENV-CnUG9ox0o,1916
8
- nvidia_nat_llama_index-1.3.0a20250826.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- nvidia_nat_llama_index-1.3.0a20250826.dist-info/entry_points.txt,sha256=2LqRRju5448P2v8B3y6TSPnk-nOd5T3AmV5JibCnoQc,68
10
- nvidia_nat_llama_index-1.3.0a20250826.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
11
- nvidia_nat_llama_index-1.3.0a20250826.dist-info/RECORD,,
7
+ nvidia_nat_llama_index-1.3.0a20250828.dist-info/METADATA,sha256=kOatcvdy8DXcTz8hVEsiU84unXu3vcgFZ9By_bY6G_M,1916
8
+ nvidia_nat_llama_index-1.3.0a20250828.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ nvidia_nat_llama_index-1.3.0a20250828.dist-info/entry_points.txt,sha256=2LqRRju5448P2v8B3y6TSPnk-nOd5T3AmV5JibCnoQc,68
10
+ nvidia_nat_llama_index-1.3.0a20250828.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
11
+ nvidia_nat_llama_index-1.3.0a20250828.dist-info/RECORD,,