I can't seem to form a prompt to get a response with three questions and answers

so I am tryig to build a form that takes in a term paper (say about the life of Ben Franklin) and simply return three questions and an answer key about the user input and i have this code…

<!DOCTYPE html>
<html lang="en">
    <title>Chatbot Example</title>
    <h2>Chatbot Example</h2>
    <form method="post" action="chat_ai_response.php">
        <input type="text" name="user_message" placeholder="Type your message here">
        <button type="submit">Send</button>

    <h2> AI Response </h2>
    if ($_SERVER["REQUEST_METHOD"] === "POST") {
        $apiKey = "*****************************";
        $userMessage = $_POST["user_message"];

        // Call the OpenAI API to get questions based on user input
        $data = array(
            "prompt" => $userMessage . "\n\nQ:",
            "max_tokens" => 1000, // Adjust as needed
            "temperature" => 0.6, // Adjust as needed
            "stop" => "\n\nQ:"

        $headers = array(
            "Content-Type: application/json",
            "Authorization: Bearer $apiKey"

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/engines/text-davinci-003/completions");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $response = curl_exec($ch);

        $botResponse = json_decode($response, true)["choices"][0]["text"];
        echo $botResponse;
  1. when i simply ask it for 3 questions about the user input it gives me the questions
  2. when i simply ask it for 3 questions and answer key for the user input it gives me one question, and one answer, when i form the prompt like this…
Please generate three questions and answers based on the following text:

[...text from Ben Franklin paper here.....]

Q1: []

Q2: []

Q3: []

it still gives me one question, and one answer. Does anyone have any suggestions? Thanks in advance


Here you’re telling it to stop if it generates two line breaks then Q:

It sounds like it’s doing what you asked…


When it reaches /n/nQ: it’s stopping as you requested…

Here’s a working prompt…

System Prompt:

You are a test designer. You read in a bunch of text then come up with questions and answers. Specifically, you generate three questions about the text. Each question will have four answers, only one of which is correct. Follow the pattern given with the text. You highlight the correct answer in your output.

35-turbo output…

Q1: What is Benjamin Franklin best known for?

A1: Being a writer
A2: Being a scientist
A3: Being a politician
A4: Being a printer
Correct answer: Being a scientist

Q2: Where was Benjamin Franklin born?

A1: Philadelphia, Pennsylvania
A2: Boston, Massachusetts
A3: New York City, New York
A4: Washington, D.C.
Correct answer: Boston, Massachusetts

Q3: How did Benjamin Franklin become a fugitive?

A1: He ran away from home at a young age
A2: He broke the law and escaped from jail
A3: He left his apprenticeship without permission
A4: He was falsely accused of a crime
Correct answer: He left his apprenticeship without permission


GPT-3.5-turbo will be far better at creating long responses and following instructions than davinci, at lower price. It takes a different type of input, a list of messages, and possibly a different php library to access the chat endpoint (although your php is named chat_ai_response.php).

You can practice a single prompt in ChatGPT, where a generic system message is used.

Massive 2500-token text dump of Ben Franklin bio to go along with a simple system message instruction to make the quiz:

We go for essay answers instead of multiple choice above, with this system prompt that makes the AI a quiz-maker:

From the text passage provided, create four exam questions requiring a paragraph of answer, and also an answer key with example answer for each.

1 Like

The stop would seem to do nothing; it would terminate if “Q:” is produced, which is not the template provided to make “Q1:”.


Thanks for the adivce Paul! I will implement, and tell you how it works out.

Thank you for the response. I will follow you and Paul’s instruction, and tell you what happened and what I learned.

Ah, you’re right. Long day. Forgot the “2” in there…

As we’ve both shown, though, it should be relatively easy even on a smaller model…

Thanks for the correction!

ETA: Seems like I got lucky and it was the solution? heh…

Yes! I commented out the “stop” => “\n\nQ:” line and it gave me what I was looking for. Thank you so very much!!!

1 Like

I commited out the “stop” => “\n\nQ:” line and everything worked correctly. I am now looking into the GPT-3.5-turbo that you recommended. Thank You Reg!!!