|
| 1 | +# (C) 2024 GoodData Corporation |
| 2 | +import os |
| 3 | +import sys |
| 4 | +from pprint import pprint |
| 5 | + |
| 6 | +import pytest |
| 7 | +from dotenv import load_dotenv |
| 8 | +from gooddata_sdk import GoodDataSdk |
| 9 | + |
| 10 | +SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 11 | +sys.path.append(SCRIPTS_DIR) |
| 12 | + |
| 13 | +# Load environment variables from the .env file |
| 14 | +load_dotenv() |
| 15 | + |
| 16 | +# Create the test_config dictionary with the loaded environment variables |
| 17 | +test_config = {"host": os.getenv("HOST"), "token": os.getenv("TOKEN")} |
| 18 | +workspace_id = os.getenv("WORKSPACE_ID") |
| 19 | + |
| 20 | +questions = ["What is number of order line id ?"] |
| 21 | +sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"]) |
| 22 | + |
| 23 | + |
| 24 | +def test_reset_chat_history(): |
| 25 | + sdk.compute.ai_chat_history_reset(workspace_id) |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.parametrize("question", questions) |
| 29 | +def test_ask_ai(question): |
| 30 | + chat_ai_res = sdk.compute.ai_chat(workspace_id, question=question) |
| 31 | + pprint(chat_ai_res.to_dict()) |
| 32 | + assert chat_ai_res["created_visualizations"] is not None, "Created visualizations should not be None" |
| 33 | + assert chat_ai_res["routing"] is not None, "Routing should not be None" |
| 34 | + |
| 35 | + |
| 36 | +def test_ai_chat_history(): |
| 37 | + chat_ai_res = sdk.compute.ai_chat(workspace_id, question="show me a headline generating net sales and net order") |
| 38 | + chat_ai_res.to_dict() |
| 39 | + chat_history_interaction_id = chat_ai_res["chat_history_interaction_id"] |
| 40 | + pprint(chat_history_interaction_id) |
| 41 | + chat_history_res = sdk.compute.ai_chat_history(workspace_id, chat_history_interaction_id) |
| 42 | + sdk.compute.ai_chat_history_user_feedback(workspace_id, chat_history_interaction_id, "POSITIVE") |
| 43 | + pprint(chat_history_res.to_dict()) |
| 44 | + |
| 45 | + |
| 46 | +def test_get_chat_history(): |
| 47 | + chat_history_res = sdk.compute.ai_chat_history(workspace_id) |
| 48 | + pprint(chat_history_res.to_dict()) |
| 49 | + assert chat_history_res["interactions"] is not None, "Interactions should not be None" |
| 50 | + assert ( |
| 51 | + chat_history_res["interactions"][0]["question"] == "What is number of order line id ?" |
| 52 | + ), "First interaction question should match" |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + pytest.main() |
0 commit comments