Python OpenAI (ChatGPT) Service SSE for Qlik

September 22, 2023 · View on GitHub

REQUIREMENTS

  • Assuming prerequisite: [Python with Qlik Sense AAI – Environment Setup]
    • This is not mandatory and is intended for those who are not as familiar with Python to setup a virtual environment. Feel free to follow the below instructions flexibly if you have experience.
  • Qlik Sense February 2018+
  • Python 3.5.3 64 bit (tested in 3.6.8)
  • Python Libraries: ..../requirements_gpt.txt file (pip install -r requirements_chatgpt.txt)
  • Get your own ChatGPT API key from https://platform.openai.com/account/api-keys (registration required)

LAYOUT

PREPARE YOUR PROJECT DIRECTORY

ALERT

Virtual environments are not necessary, but are frequently considered a best practice when handling multiple Python projects.
  1. Open a command prompt

  2. Make a new project folder called QlikSenseAAI, where all of our projects will live that leverage the QlikSenseAAI virtual environment that we’ve created. Let’s place it under ‘C:\Users{Your Username}’. If you have already created this folder in another guide, simply skip this step.

  3. We now want to leverage our virtual environment. If you are not already in your environment, enter it by executing:

$ workon QlikSenseAAI
  1. Now, ensuring you are in the ‘QlikSenseAAI’ folder that you created (if you have followed another guide, it might redirect you to a prior working directory if you've set a default, execute the following commands to create and navigate into your project’s folder structure:
$ cd QlikSenseAAI
$ mkdir ChatGPT
$ cd ChatGPT
  1. Optionally, you can bind the current working directory as the virtual environment’s default. Execute (Note the period!):
$ setprojectdir .
  1. We have now set the stage for our ChatGPT environment. To navigate back into this project in the future, simply execute:
$ workon QlikSenseAAI

This will take you back into the environment with the default directory that we set above. To change the directory for future projects within the same environment, change your directory to the desired path and reset the working directory with ‘setprojectdir .’

INSTALL PYTHON LIBRARIES AND REQUIRED SOFTWARE

  1. Open a command prompt or continue in your current command prompt, ensuring that you are currently within the virtual environment—you will see (QlikSenseAAI) preceding the directory if so. If you are not, execute:
$ workon QlikSenseAAI
  1. Execute the following commands. If you have followed a previous guide, you have more than likely already installed grpcio):
$ pip install -r requirements_chatgpt.txt

SET UP AN AAI CONNECTION IN THE QMC

  1. Navigate to the QMC and select ‘Analytic connections’
  2. Fill in the Name, Host, and Port parameters -- these are mandatory.
    • Name is the alias for the analytic connection. For the example qvf to work without modifications, name it 'PythonChatGPT'
    • Host is the location of where the service is running. If you installed this locally, you can use 'localhost'
    • Port is the target port in which the service is running. This module is setup to run on 50058, however that can be easily modified by searching for ‘-port’ in the ‘__main__.py’ file and changing the ‘default’ parameter to an available port.
  3. Click ‘Apply’, and you’ve now created a new analytics connection.

PREPARE AND START SERVICES

  1. At this point the setup is complete, and we now need to start the sentiment extension service. To do so, navigate back to the command prompt. Please make sure that you are inside of the virtual environment.
  2. Once at the command prompt and within your environment, execute (note two underscores on each side):
$ python __main__.py
  1. We now need to restart the Qlik Sense engine service so that it can register the new AAI service. To do so, navigate to windows Services and restart the ‘Qlik Sense Engine Service’
  2. You should now see in the command prompt that the Qlik Sense Engine has registered the functions ChatGPT() from the extension service over port 50058, or whichever port you’ve chosen to leverage.

LEVERAGE ChatGPT for Sales ANALYSIS FROM WITHIN QLIK

https://github.com/gsa999/Qlik-Sense-ChatGPT-SSE/blob/470963604732edf781062d329d785c940ffe1d41/Sales%20App%20-%20Chat%20GPT.qvf