Module 2 – First OpenAI API call
Exercise
Exercise: first AI chat
Exercise: first AI chat
In this exercise you build a concrete part of FirmAssist through the 'Exercise: first AI chat' scenario so that you finish with a working artifact, not just theory.
You now bootstrap FirmAssist: API key, folder structure, and the first PHP call that returns a model response.
Task
- Create a `.env` file and load the API key only on the server.
- Add a small PHP endpoint that receives a question.
- Send the first prompt to the model and return JSON.
- Render the answer in a simple HTML interface.
- Handle empty input and provider failures.
- Store one sample request/response pair for debugging.
Practical example
Starter skeleton for the practical exercise.
$exercise = [
'slug' => 'vezba-prvi-ai-chat',
'target' => 'first chat endpoint',
'project' => 'FirmAssist',
'done' => false,
];
print_r($exercise);Goal: The goal is to leave this exercise with a small but usable block of FirmAssist that you can extend later.
