|
| 1 | +# (C) 2024 GoodData Corporation |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | +from pprint import pprint |
| 6 | + |
| 7 | +import gooddata_api_client |
| 8 | +import pytest |
| 9 | +from gooddata_api_client.api import smart_functions_api |
| 10 | +from gooddata_api_client.model.chat_history_request import ChatHistoryRequest |
| 11 | +from gooddata_api_client.model.chat_history_result import ChatHistoryResult |
| 12 | +from gooddata_api_client.model.chat_request import ChatRequest |
| 13 | +from gooddata_api_client.model.chat_result import ChatResult |
| 14 | + |
| 15 | +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 16 | + |
| 17 | +from env import HOST, TOKEN, WORKSPACE_ID |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def api_client(): |
| 22 | + configuration = gooddata_api_client.Configuration(host=HOST) |
| 23 | + configuration.access_token = TOKEN |
| 24 | + with gooddata_api_client.ApiClient(configuration) as api_client: |
| 25 | + yield api_client |
| 26 | + |
| 27 | + |
| 28 | +def test_ai_chat(api_client): |
| 29 | + question = "What is the number of Accounts?" |
| 30 | + |
| 31 | + api_instance = smart_functions_api.SmartFunctionsApi(api_client) |
| 32 | + chat_request = ChatRequest(question=question) |
| 33 | + |
| 34 | + try: |
| 35 | + api_response = api_instance.ai_chat(WORKSPACE_ID, chat_request) |
| 36 | + pprint(api_response) |
| 37 | + assert isinstance(api_response, ChatResult), "Response is not of type ChatResult" |
| 38 | + except gooddata_api_client.ApiException as e: |
| 39 | + print(f"Exception when calling SmartFunctionsApi->ai_chat: {e}") |
| 40 | + pytest.fail(f"Exception when calling SmartFunctionsApi->ai_chat: {e}\n") |
| 41 | + |
| 42 | + |
| 43 | +def test_ai_chat_history(api_client): |
| 44 | + api_instance = smart_functions_api.SmartFunctionsApi(api_client) |
| 45 | + chat_history_request = ChatHistoryRequest( |
| 46 | + chat_history_interaction_id=100, |
| 47 | + user_feedback="POSITIVE", |
| 48 | + ) |
| 49 | + |
| 50 | + try: |
| 51 | + api_response = api_instance.ai_chat_history(WORKSPACE_ID, chat_history_request) |
| 52 | + pprint(api_response) |
| 53 | + assert isinstance(api_response, ChatHistoryResult), "Response is not of type ChatHistoryResult" |
| 54 | + except gooddata_api_client.ApiException as e: |
| 55 | + print(f"Exception when calling SmartFunctionsApi->ai_chat_history: {e}") |
| 56 | + print(f"Status Code: {e.status}") |
| 57 | + print(f"Reason: {e.reason}") |
| 58 | + print(f"HTTP response headers: {e.headers}") |
| 59 | + print(f"HTTP response body: {e.body}") |
| 60 | + pytest.fail(f"Exception when calling SmartFunctionsApi->ai_chat_history: {e}\n") |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + pytest.main() |
0 commit comments