@@ -50,7 +50,8 @@ def test_cohere_llm_happy_path(mock_cohere: Mock) -> None:
50
50
def test_cohere_llm_invoke_with_message_history_happy_path (mock_cohere : Mock ) -> None :
51
51
chat_response_mock = MagicMock ()
52
52
chat_response_mock .message .content = [MagicMock (text = "cohere response text" )]
53
- mock_cohere .ClientV2 .return_value .chat .return_value = chat_response_mock
53
+ mock_cohere_client_chat = mock_cohere .ClientV2 .return_value .chat
54
+ mock_cohere_client_chat .return_value = chat_response_mock
54
55
55
56
system_instruction = "You are a helpful assistant."
56
57
llm = CohereLLM (model_name = "something" )
@@ -66,7 +67,7 @@ def test_cohere_llm_invoke_with_message_history_happy_path(mock_cohere: Mock) ->
66
67
messages = [{"role" : "system" , "content" : system_instruction }]
67
68
messages .extend (message_history )
68
69
messages .append ({"role" : "user" , "content" : question })
69
- llm . client . chat .assert_called_once_with (
70
+ mock_cohere_client_chat .assert_called_once_with (
70
71
messages = messages ,
71
72
model = "something" ,
72
73
)
@@ -77,7 +78,8 @@ def test_cohere_llm_invoke_with_message_history_and_system_instruction(
77
78
) -> None :
78
79
chat_response_mock = MagicMock ()
79
80
chat_response_mock .message .content = [MagicMock (text = "cohere response text" )]
80
- mock_cohere .ClientV2 .return_value .chat .return_value = chat_response_mock
81
+ mock_cohere_client_chat = mock_cohere .ClientV2 .return_value .chat
82
+ mock_cohere_client_chat .return_value = chat_response_mock
81
83
82
84
system_instruction = "You are a helpful assistant."
83
85
llm = CohereLLM (model_name = "gpt" )
@@ -93,11 +95,10 @@ def test_cohere_llm_invoke_with_message_history_and_system_instruction(
93
95
messages = [{"role" : "system" , "content" : system_instruction }]
94
96
messages .extend (message_history )
95
97
messages .append ({"role" : "user" , "content" : question })
96
- llm . client . chat .assert_called_once_with (
98
+ mock_cohere_client_chat .assert_called_once_with (
97
99
messages = messages ,
98
100
model = "gpt" ,
99
101
)
100
- assert llm .client .chat .call_count == 1
101
102
102
103
103
104
def test_cohere_llm_invoke_with_message_history_validation_error (
@@ -122,9 +123,12 @@ def test_cohere_llm_invoke_with_message_history_validation_error(
122
123
123
124
@pytest .mark .asyncio
124
125
async def test_cohere_llm_happy_path_async (mock_cohere : Mock ) -> None :
125
- chat_response_mock = AsyncMock ()
126
- chat_response_mock .message .content = [AsyncMock (text = "cohere response text" )]
127
- mock_cohere .AsyncClientV2 .return_value .chat .return_value = chat_response_mock
126
+ chat_response_mock = MagicMock (
127
+ message = MagicMock (content = [MagicMock (text = "cohere response text" )])
128
+ )
129
+ mock_cohere .AsyncClientV2 .return_value .chat = AsyncMock (
130
+ return_value = chat_response_mock
131
+ )
128
132
129
133
llm = CohereLLM (model_name = "something" )
130
134
res = await llm .ainvoke ("my text" )
0 commit comments