From 60c23d9e3a73e1381f11b88e0b52045c352a3aea Mon Sep 17 00:00:00 2001 From: sabaimran Date: Tue, 21 Nov 2023 23:08:36 -0800 Subject: [PATCH] Add online search chat director tests --- tests/test_gpt4all_chat_director.py | 21 +++++++++++++++++++++ tests/test_openai_chat_director.py | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/test_gpt4all_chat_director.py b/tests/test_gpt4all_chat_director.py index d978fc99..d44a3c07 100644 --- a/tests/test_gpt4all_chat_director.py +++ b/tests/test_gpt4all_chat_director.py @@ -1,5 +1,6 @@ # Standard Packages import urllib.parse +from urllib.parse import quote # External Packages import pytest @@ -54,6 +55,26 @@ def test_chat_with_no_chat_history_or_retrieved_content_gpt4all(client_offline_c ) +# ---------------------------------------------------------------------------------------------------- +@pytest.mark.chatquality +@pytest.mark.django_db(transaction=True) +def test_chat_with_online_content(chat_client): + # Act + q = "/online give me the link to paul graham's essay how to do great work" + encoded_q = quote(q, safe="") + response = chat_client.get(f"/api/chat?q={encoded_q}&stream=true") + response_message = response.content.decode("utf-8") + + response_message = response_message.split("### compiled references")[0] + + # Assert + expected_responses = ["http://www.paulgraham.com/greatwork.html"] + assert response.status_code == 200 + assert any([expected_response in response_message for expected_response in expected_responses]), ( + "Expected assistants name, [K|k]hoj, in response but got: " + response_message + ) + + # ---------------------------------------------------------------------------------------------------- @pytest.mark.chatquality @pytest.mark.django_db(transaction=True) diff --git a/tests/test_openai_chat_director.py b/tests/test_openai_chat_director.py index b4e63364..7b98d4da 100644 --- a/tests/test_openai_chat_director.py +++ b/tests/test_openai_chat_director.py @@ -1,6 +1,7 @@ # Standard Packages import os import urllib.parse +from urllib.parse import quote # External Packages import pytest @@ -54,6 +55,26 @@ def test_chat_with_no_chat_history_or_retrieved_content(chat_client): ) +# ---------------------------------------------------------------------------------------------------- +@pytest.mark.chatquality +@pytest.mark.django_db(transaction=True) +def test_chat_with_online_content(chat_client): + # Act + q = "/online give me the link to paul graham's essay how to do great work" + encoded_q = quote(q, safe="") + response = chat_client.get(f"/api/chat?q={encoded_q}&stream=true") + response_message = response.content.decode("utf-8") + + response_message = response_message.split("### compiled references")[0] + + # Assert + expected_responses = ["http://www.paulgraham.com/greatwork.html"] + assert response.status_code == 200 + assert any([expected_response in response_message for expected_response in expected_responses]), ( + "Expected assistants name, [K|k]hoj, in response but got: " + response_message + ) + + # ---------------------------------------------------------------------------------------------------- @pytest.mark.django_db(transaction=True) @pytest.mark.chatquality