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.
1
15
import pytest
2
16
from langchain_core .messages import AIMessage
3
17
from langchain_core .prompts import ChatPromptTemplate
12
26
@pytest .mark .integration
13
27
@pytest .mark .asyncio
14
28
async def test_nim_langchain_agent ():
15
- """Test NIM LLM with LangChain agent. Requires NVIDIA_API_KEY to be set."""
29
+ """
30
+ Test NIM LLM with LangChain agent. Requires NVIDIA_API_KEY to be set.
31
+ """
16
32
17
33
prompt = ChatPromptTemplate .from_messages ([("system" , "You are a helpful AI assistant." ), ("human" , "{input}" )])
18
34
19
-
20
35
llm_config = NIMModelConfig (model_name = "meta/llama-3.1-70b-instruct" , temperature = 0.0 )
21
36
22
-
23
37
async with WorkflowBuilder () as builder :
24
38
await builder .add_llm ("nim_llm" , llm_config )
25
39
llm = await builder .get_llm ("nim_llm" , wrapper_type = LLMFrameworkEnum .LANGCHAIN )
26
40
27
-
28
41
agent = prompt | llm
29
42
30
-
31
43
response = await agent .ainvoke ({"input" : "What is 1+2?" })
32
44
assert isinstance (response , AIMessage )
33
45
assert response .content is not None
@@ -38,7 +50,9 @@ async def test_nim_langchain_agent():
38
50
@pytest .mark .integration
39
51
@pytest .mark .asyncio
40
52
async def test_openai_langchain_agent ():
41
- """Test OpenAI LLM with LangChain agent. Requires OPENAI_API_KEY to be set."""
53
+ """
54
+ Test OpenAI LLM with LangChain agent. Requires OPENAI_API_KEY to be set.
55
+ """
42
56
prompt = ChatPromptTemplate .from_messages ([("system" , "You are a helpful AI assistant." ), ("human" , "{input}" )])
43
57
44
58
llm_config = OpenAIModelConfig (model_name = "gpt-3.5-turbo" , temperature = 0.0 )
@@ -59,7 +73,11 @@ async def test_openai_langchain_agent():
59
73
@pytest .mark .integration
60
74
@pytest .mark .asyncio
61
75
async def test_aws_bedrock_langchain_agent ():
62
- """Test AWS Bedrock LLM with LangChain agent. Requires AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be set."""
76
+ """
77
+ Test AWS Bedrock LLM with LangChain agent.
78
+ Requires AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be set.
79
+ See https://docs.aws.amazon.com/bedrock/latest/userguide/setting-up.html for more information.
80
+ """
63
81
prompt = ChatPromptTemplate .from_messages ([("system" , "You are a helpful AI assistant." ), ("human" , "{input}" )])
64
82
65
83
llm_config = AWSBedrockModelConfig (model_name = "meta.llama3-3-70b-instruct-v1:0" ,
0 commit comments