Another one AI-assistant: GPT-based schedule generator

Alexandr Dzhumurat
5 min readAug 7, 2023

--

Microservice with FastAPI and React Interface — Let ChatGPT Do It For You!

It occurred to me to create an application that solves the problem of planning out-of-work hours: how to create a diverse and beneficial schedule, especially in a city where you are relatively new? This problem is faced by anyone who has recently relocated. In this article, I will walk you through the process of building such an AI assistant. At every application development stage, I will utilize ChatGPT for maximum development speed. The goal is to create the application within a weekend!

First, check the app: eventrecommender.art (works only for Cyprus, Limassol).

App workflow

I couldn’t find any ready-made applications; the market niche is wide open!

I came up with the following algorithm:

  1. The user goes through a short onboarding process, answering a few questions about their leisure preferences (for example, whether they want to include activities for children in the plan — vital information!)
  2. Based on the onboarding responses, a list of activities is generated.
  3. For each activity, we find a suitable place where it can be carried out. For example, for the “shopping” activity, we immediately offer the nearest shopping mall.

Great! Let’s start with the interface where the user goes through the onboarding process. React JS code generated based on the following prompt:

​​Please provide me with a code for a React JS app
that functions as a chat application with three questions:
"Would you like to start your day in the morning?",
"Will you take your kids with you?", and "Should I add an evening in the plan?"
Each question should appear after the user answers the previous one.
Once the last question is answered, the app should make a POST request to localhost:8000/search,
passing the user responses as GET parameters.

The result looks pretty good

Next, you need to create a backend with FastAPI. The following prompt will be suitable for that:

Develop a FastAPI backend that handles incoming requests from the React JS frontend.
The backend should have an endpoint that receives the user's onboarding responses and processes the data accordingly.
I need an endpoint /search that accepts a POST parameter named query and forwards the query to the Google Maps API.

Test the created frontend and backend. What to do if not all the functionality is working? Simply ask ChatGPT to fix the erroneous code!

Now, there is a question of how to generate schedules. The schedule should be diverse (which will positively impact the engagement metrics of our application) and aligned with the user’s onboarding preferences.

To solve this problem, we will leverage ChatGPT! We will dynamically generate schedules based on the user’s interests gathered during the onboarding process. Prompt:

pythdef generate_options() -> dict:
keys = ['kids_option', 'evening_option', 'daystart_option']
mapping = {
'kids_option': {'No': 'no', 'Yes': 'a'},
'evening_option': {'No': "don't", 'Yes': ''},
'daystart_option': {'No': "'t", 'Yes': ''}
}
options = {}
for k in keys:
user_answer = np.random.choice(['Yes', 'No'])
options[k] = {'value': mapping[k][user_answer], 'answer': user_answer}

return options

def promt_generation(user_query: str, options: dict):
# 'user_query' needs for promt generation
morning_snippet = ''
if options['daystart_option']['answer'] == 'Yes':
morning_snippet = 'The morning should start at 08:30 AM, 09:00 AM, 09:30 AM, or 10:00 AM.'
daystart_snippet = ''
else:
daystart_snippet = 'Day should start from lunch'
if options['evening_option']['answer'] == 'Yes':
evening_snippet = 'The evening should start at 07:30 PM, 08:00 PM, 08:30 PM, or 09:00 PM.'
else:
evening_snippet = 'Plan should ends at 04:00 PM, 04:30 PM, 05:00 PM, or 05:30 PM'
promt = f"""
Generate a plan for one day.
Day should{options['daystart_option']['value']} start from breakfast. {daystart_snippet}
I have {options['kids_option']['value']} children.
One line per activity. Line should starts wit a time slot
Add start time and end time for every activity.
{morning_snippet}
The lunch should start at 12:00 PM, 12:30 PM, 13:00 PM, or 13.30 PM.
I {options['evening_option']['value']} need the evening. {evening_snippet}
Plan:
"""
return promt

The example of a schedule that we get.

Event Time Slot      Event Name
08:30 AM - 09:00 AM BreakfastCafe Calma
09:00 AM - 10:30 AM Morning workout at the gym
10:30 AM - 11:00 AM Shower and get ready for the day
11:00 AM - 12:00 PM Run errands and do some grocery shopping
12:00 PM - 01:00 PM Lunch at a local cafe or restaurant
01:00 PM - 03:30 PM Relax and enjoy some leisure time at home (read a book, watch a movie, etc.)
03:30 PM - 05:00 PM Outdoor activity such as hiking or biking
05:00 PM - 06.30 PM Visit a museum or art galler
06.30 PM - 07.30 PM Dinner at a new restaurant in town
07.30 PM - 09.00 PM Attend a live music concert or theater performance

Looks very promising! To increase the value of this AI assistant for users, let’s add specific places for each activity where it can be carried out. Currently, users search for such places on Google Maps themselves — let’s do this work for them! We will use the Google Maps API for this purpose. The result will be:

The last step is to make the application available to users — for this, we need to deploy two Docker containers on the server, configure the domain name, set up HTTPS certificates… Boring! Let’s delegate this task to ChatGPT.

I need an Nginx configuration for two domains, eventrecommender.art and api.eventrecommender.art.
The first domain should link to a React JS app running on localhost:3000, and the second domain`
should link to a FastAPI backend running on localhost:8000. `
Please provide separate Nginx configuration files for each domain, and do not use the default Nginx configuration. `
No need CSL

Finally, let’s add HTTPS support. ChatGPT will generate instructions for free CSL certificates, which will be sufficient for the MVP of our service.

Revise the Nginx configurations to enable HTTPS support. Step-by-step instruction.

Done! We have created the backend, added the user interface, and brought to life a helpful AI assistant that solves the problem of finding activities for out-of-office hours. Enjoy it on eventrecommender.art. Currently, support is available only for the city of Cyprus, Limassol.

--

--