A simple Python project that uses the OpenAI API to test that you can connect to an OpenAI or Azure-hosted GPT LLM, send a simple prompt, and receive a text completion response.
-
Ensure you have an OpenAI or Azure OpenAI GPT model accessible along with appropriate API keys / credentials.
-
Ensure you have installed Python 3 and PIP on your workstation.
-
In a terminal on your workstation, from the root folder of this project, run the following command to copy an example environment configuration file to a new file into the same root folder called
.env
, and then edit the values for the properties shown in this new.env
file to reflect your specific environment settings:cp 'EXAMPLE.env' '.env'
-
In the terminal, initialise the required Python environment for you to be able to execute the application correctly.
python3 -m pip install --user virtualenv python3 -m venv my-test-env source my-test-env/bin/activate python -m pip install --upgrade pip python -m pip install -r requirements.txt
From the terminal, execute the followwing command:
python test-gpt-conn.py