This utility can take unstructured prompts written by the user and convert them into a request body like the one shown below:
User Prompt: "I am planning to order the BMW M8 with a sunroof or panorama glass roof sky lounge, and the M Sport Package on 12th April 2018. Is this configuration possible?"
Request Body:
[
{
"modelTypeCodes": ["DZ01"],
"booleanFormulas": ["+(S403A/S407A)+P337A"],
"dates": ["2018-04-12"]
}
]
The utility works in the following way:
- Read messages from the console
- Call ChatGPT with 3 different setups in order to extract the date, car model and additional configuration.
- Parse ChatGPT output with regex in order to extract the necessary substrings for the request body.
- Assemble a request body from the extracted information.
Run the following commands from the project root.
sudo apt-get install python3.11-dev python3.11-venv
python3.11 -m venv venv
source venv/bin/activate
pip install -e .
Set the openAI API key to builder.py before running!
The free version of ChatGPT allows only 3 requests per minute. Therefore, the utility can only process one message per minute.
build-requests \
"My son wants a car with a Panorama Glass Roof Sky Lounge in a month" \
"Hello, is the X7 available without a panorama glass roof and with the EU Comfort Package. I need the vehicle on the 8th of November 2024."
This example shows that among other things, the utility can operate with the relative dates ("in a month") and with the vaguely worded statement ("model X7" -> "21EM, 21EN").
The utility a set of string as an argument. Run the following command to receive a help message
build-requests -h
The free version of ChatGPT allows only 3 requests per minute. Therefore, the test takes about 5 minutes.
cd tests
python -m unittest discover
-
Write tests to ensure the application works as expected.
✅ The instruction on how to run the tests is given above. -
Add error handling and validation to ensure the prompts entered by the user are valid.
✅ If the utility argument can not be converted to a list of string, the program ends, printing a message with instructions on how to call it correctly. -
Allow the user to modify the request body before sending the request.
✅ The user can modify the request in the console. -
Allow the user to enter multiple prompts and generate a request body for each one.
✅ The can pass a list of prompts to the utility.