|
13 | 13 | # See the License for the specific language governing permissions and
|
14 | 14 | # limitations under the License.
|
15 | 15 | from unittest.mock import MagicMock, Mock, patch
|
16 |
| -from typing import Any, cast |
17 | 16 |
|
18 | 17 | import openai
|
19 | 18 | import pytest
|
@@ -88,9 +87,9 @@ def test_openai_llm_with_message_history_happy_path(mock_import: Mock) -> None:
|
88 | 87 | assert res.content == "openai chat response"
|
89 | 88 | message_history.append({"role": "user", "content": question})
|
90 | 89 | # Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
|
91 |
| - cast(Any, llm.client.chat.completions.create).assert_called_once() |
| 90 | + llm.client.chat.completions.create.assert_called_once() |
92 | 91 | # Check call arguments individually
|
93 |
| - call_args = cast(Any, llm.client.chat.completions.create).call_args[ |
| 92 | + call_args = llm.client.chat.completions.create.call_args[ |
94 | 93 | 1
|
95 | 94 | ] # Get the keyword arguments
|
96 | 95 | assert call_args["messages"] == message_history
|
@@ -124,9 +123,9 @@ def test_openai_llm_with_message_history_and_system_instruction(
|
124 | 123 | messages.extend(message_history)
|
125 | 124 | messages.append({"role": "user", "content": question})
|
126 | 125 | # Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
|
127 |
| - cast(Any, llm.client.chat.completions.create).assert_called_once() |
| 126 | + llm.client.chat.completions.create.assert_called_once() |
128 | 127 | # Check call arguments individually
|
129 |
| - call_args = cast(Any, llm.client.chat.completions.create).call_args[ |
| 128 | + call_args = llm.client.chat.completions.create.call_args[ |
130 | 129 | 1
|
131 | 130 | ] # Get the keyword arguments
|
132 | 131 | assert call_args["messages"] == messages
|
@@ -241,9 +240,9 @@ def test_openai_llm_invoke_with_tools_with_message_history(
|
241 | 240 | # Verify the correct messages were passed
|
242 | 241 | message_history.append({"role": "user", "content": question})
|
243 | 242 | # Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
|
244 |
| - cast(Any, llm.client.chat.completions.create).assert_called_once() |
| 243 | + llm.client.chat.completions.create.assert_called_once() |
245 | 244 | # Check call arguments individually
|
246 |
| - call_args = cast(Any, llm.client.chat.completions.create).call_args[ |
| 245 | + call_args = llm.client.chat.completions.create.call_args[ |
247 | 246 | 1
|
248 | 247 | ] # Get the keyword arguments
|
249 | 248 | assert call_args["messages"] == message_history
|
@@ -298,9 +297,9 @@ def test_openai_llm_invoke_with_tools_with_system_instruction(
|
298 | 297 | messages = [{"role": "system", "content": system_instruction}]
|
299 | 298 | messages.append({"role": "user", "content": "my text"})
|
300 | 299 | # Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
|
301 |
| - cast(Any, llm.client.chat.completions.create).assert_called_once() |
| 300 | + llm.client.chat.completions.create.assert_called_once() |
302 | 301 | # Check call arguments individually
|
303 |
| - call_args = cast(Any, llm.client.chat.completions.create).call_args[ |
| 302 | + call_args = llm.client.chat.completions.create.call_args[ |
304 | 303 | 1
|
305 | 304 | ] # Get the keyword arguments
|
306 | 305 | assert call_args["messages"] == messages
|
@@ -385,9 +384,9 @@ def test_azure_openai_llm_with_message_history_happy_path(mock_import: Mock) ->
|
385 | 384 | assert res.content == "openai chat response"
|
386 | 385 | message_history.append({"role": "user", "content": question})
|
387 | 386 | # Use assert_called_once() instead of assert_called_once_with() to avoid issues with overloaded functions
|
388 |
| - cast(Any, llm.client.chat.completions.create).assert_called_once() |
| 387 | + llm.client.chat.completions.create.assert_called_once() |
389 | 388 | # Check call arguments individually
|
390 |
| - call_args = cast(Any, llm.client.chat.completions.create).call_args[ |
| 389 | + call_args = llm.client.chat.completions.create.call_args[ |
391 | 390 | 1
|
392 | 391 | ] # Get the keyword arguments
|
393 | 392 | assert call_args["messages"] == message_history
|
|
0 commit comments