Skip to content

Commit

Permalink
added chat and call tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonalaird committed Mar 16, 2024
1 parent e4935c2 commit 3611045
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,39 @@ def test_generate_with_mock(openai_llm_mock): # noqa: F811
)


@pytest.mark.parametrize(
"openai_llm_mock", ["mocked response"], indirect=["openai_llm_mock"]
)
def test_chat_with_mock(openai_llm_mock): # noqa: F811
llm = OpenAILLM()
response = llm.chat([{"role": "user", "content": "test prompt"}])
assert response == "mocked response"
openai_llm_mock.chat.completions.create.assert_called_once_with(
model="gpt-4-turbo-preview",
messages=[{"role": "user", "content": "test prompt"}],
)


@pytest.mark.parametrize(
"openai_llm_mock", ["mocked response"], indirect=["openai_llm_mock"]
)
def test_call_with_mock(openai_llm_mock): # noqa: F811
llm = OpenAILLM()
response = llm("test prompt")
assert response == "mocked response"
openai_llm_mock.chat.completions.create.assert_called_once_with(
model="gpt-4-turbo-preview",
messages=[{"role": "user", "content": "test prompt"}],
)

response = llm([{"role": "user", "content": "test prompt"}])
assert response == "mocked response"
openai_llm_mock.chat.completions.create.assert_called_with(
model="gpt-4-turbo-preview",
messages=[{"role": "user", "content": "test prompt"}],
)


@pytest.mark.parametrize(
"openai_llm_mock",
['{"Parameters": {"prompt": "cat"}}'],
Expand Down

0 comments on commit 3611045

Please sign in to comment.