MCQ with OpenAI

Hello,
I’m a student and I’m developing my application on Bubble with the aim of helping students revise, so I’m trying to offer several cool features like an interactive MCQ which would come from the OpenAI API.

I’m currently using the ‘completion’ system, which returns a MCQ with the correct answers but in text, and I can’t manage to identify in my interface what the question is, the proposed answers and the correct answer.

If anyone knows of a way, either using Bubble to recognise the elements of my request or using another OpenAi feature, that would be really great because I’ve been struggling for a while!

Include in your prompt an instruction to structure the question in a syntax (such as CSV with headers that you specify such as question, choice1, choice2, etc.) that you can readily parse using Bubble’s operators like regex and split or even a plugin.

As the previous answer suggested, I would use the API Connector and provide in the instructions to generate a JSON-structured string, then parse it as object through the API connector again and get a list of MCQ answers as array and then you will be able to use a Repeating Group to populate your page with questions/answers.

Thanks for the answer. I’ve juste a question : To get a list of MCQ answers as array, which API would you use ? Because I think OpenAI only responds in text format, don’t you ?

Thank you very much for your reply. I understand the logic, but could you explain it to me in more detail, if possible with screens/videos? I’m not a Bubble expert, so I’m still having a bit of trouble. :sweat_smile:

They all do. You will have to parse the text into JSON.

1 Like

OK, but how do we do that? As I said in a previous message, I’m still a beginner and so don’t necessarily know all the functions! If you could explain in more detail, and if possible with screenshots, I’d be very grateful!

Go ahead and experiment. Add to your AI prompt an instruction to provide the question as JSON, see what you get, and refine from there. Once you have a response comprising the question structured as you like, the question will likely be set off from the rest of the response using markdown syntax, such as ```; once you receive the entire response text in Bubble, you can use regex operators or a JSON parser plugin to extract the question portion as well as the various values from its JSON portion.

Thank you for your advice.
I tested a lot of things and managed to fill my database with Json content. However, given the structure of my database :


I can’t generate a functional MCQ that allows me to change questions, save answers, etc.

So I looked around and came across a video on constructing MCQs that I think is perfect : https://www.youtube.com/watch?v=-8PiT8i8_-c&list=PLWTcM24wu7netH2HCgv1cHylcrelwB-Rx

The problem now is that I can no longer save the response in Json format in this new database :


Capture d’écran 2024-07-08 à 16.07.50
Capture d’écran 2024-07-08 à 16.08.03

So I really need your help to analyse the response in Json format and save it in this new database. The Json response I get looks like this :

{
“question1”: {
“question”: “Quel est le but de la business strategy ?”,
“options”: [
“Créer un avantage concurrentiel”,
“Maximiser les profits”,
“Augmenter la taille de l’entreprise”,
“Réduire les coûts”
],
“reponse”: “Créer un avantage concurrentiel”
},
“question2”: {
“question”: “Qu’est-ce que l’intégration dans une entreprise ?”,
“options”: [
“Externaliser des activités”,
“Internaliser des activités”,
“Partager des activités avec d’autres entreprises”,
“Développer de nouvelles activités”
],
“reponse”: “Internaliser des activités”
},
“question3”: {
“question”: “Quels sont les risques de l’intégration pour une entreprise ?”,
“options”: [
“Dilution des compétences”,
“Augmentation des coûts”,
“Perte de ressources”,
“Toutes les réponses sont correctes”
],
“reponse”: “Toutes les réponses sont correctes”
},
“question4”: {
“question”: “Qu’est-ce que la diversification en termes de stratégie d’entreprise ?”,
“options”: [
“Se concentrer sur un seul domaine d’activité”,
“Se lancer dans de nouveaux domaines d’activité”,
“Externaliser des activités”,
“Partager des activités avec d’autres entreprises”
],
“reponse”: “Se lancer dans de nouveaux domaines d’activité”
},
“question5”: {
“question”: “Quels sont les objectifs de la croissance interne pour une entreprise ?”,
“options”: [
“Développer des compétences distinctives”,
“Augmenter la taille de l’entreprise”,
“Maximiser les profits”,
“Toutes les réponses sont correctes”
],
“reponse”: “Toutes les réponses sont correctes”
}
}