Using the Davinci API provides a different explanation of text than the same prompt entered into GPT4

Here is the code I am using:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Example</title>
    <script type="text/javascript">
      function showExplanation(prompt) {
        const apiUrl = "https://api.openai.com/v1/engines/davinci/completions";
        const apiKey = "YOUR_API_KEY_HERE";

        fetch(apiUrl, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${apiKey}`
          },
          body: JSON.stringify({
            prompt: prompt,
            max_tokens: 1024,
            n: 1,
            stop: "\n",
          })
        })
          .then(response => response.json())
          .then(output => {
            const explanation = output.choices[0].text;
            alert(explanation);
          })
          .catch(error => console.log(error));
      }
    </script>
  </head>
  <body>
    <a href="#" onclick="showExplanation('What does this sentence mean?')">When push comes to shove in a situation defined by opposition deemed as evil according to the way the opponent dismisses any honor you show you must not expect that what corners you will let up for any premature retreat you make becomes bound to come back as a weakened ability to fight off attacks made on you.</a>
  </body>
</html>

The response provided by davinci is nonsense and is entirely different from the same prompt + sentence entered in GPT4. How can I correct this issue so that the sentence explanation provided is identical to that being produced by GPT4?

They are entirely different systems and models, it wouldn’t be expected that they would be the same.

You’ll get closer if you use GPT3.5 on chat completion endpoint, and can apply for GPT4 API access

1 Like

Welcome @marcigneri

prompting for davinci is done for completions.

Here’s docs on prompt design for completions

2 Likes

does anyone know how I could specify gpt-3.5-turbo using the chat completions instead of the davinci completion?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Example</title>
    <script type="text/javascript">
      function showExplanation(prompt) {
        const apiUrl = "https://api.openai.com/v1/chat/completions";
        const apiKey = "YOUR_API_KEY_HERE";

        fetch(apiUrl, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${apiKey}`
          },
          body: JSON.stringify({
            prompt: prompt,
            max_tokens: 1024,
            n: 1,
            stop: "\n",
          })
        })
          .then(response => response.json())
          .then(output => {
            const explanation = output.choices[0].text;
            alert(explanation);
          })
          .catch(error => console.log(error));
      }
    </script>
  </head>
  <body>
    <a href="#" onclick="showExplanation('What does this sentence mean?')">When push comes to shove in a situation defined by opposition deemed as evil according to the way the opponent dismisses any honor you show you must not expect that what corners you will let up for any premature retreat you make becomes bound to come back as a weakened ability to fight off attacks made on you.</a>
  </body>
</html>

here is the code, I just need a way to specify the gpt-3.5-turbo model… anyone know how I could modify the above code to reflect this?

API Reference page has code examples, change the language in the little dropdown

the example provided is for node.js - I don’t want to set up a node environment for My project therefore am hoping to just adapt the code that I provided. All I’m looking for help with is where to insert the “model”: “gpt-3.5-turbo”, line. I am getting the error “can’t find variable: gpt” when adding this code:

parameters: {
model: gpt-3.5-turbo,
},

Anyone have any ideas?

It needs to be a string:

model: "gpt-3.5-turbo",

(Also ChatGPT is pretty good at translating a code snippet to whatever other language/library you want)

I was able to get the text explanations working with the following code for anyone interested:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Example</title>
<script type="text/javascript">
      function showExplanation(element) {
        const apiUrl = "https://api.openai.com/v1/chat/completions";
        const apiKey = "YOUR_API_KEY_HERE";

        const prompt = element.textContent.trim();

        fetch(apiUrl, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${apiKey}`
          },
          body: JSON.stringify({
            messages: [
              { role: "system", content: "What does this sentence mean?" },
              { role: "user", content: prompt }
            ],
            max_tokens: 1024,
            temperature: 0.2,
            model: "gpt-3.5-turbo"
          })
        })
          .then(response => response.json())
          .then(output => {
            const explanation = output.choices[0].message.content;
            alert(explanation);
          })
          .catch(error => console.log(error));
      }
    </script>
  </head>
  <body>
    <p onclick="showExplanation(this)">When push comes to shove in a situation defined by opposition deemed as evil according to the way the opponent dismisses any honor you show you must not expect that what corners you will let up for any premature retreat you make becomes bound to come back as a weakened ability to fight off attacks made on you.</p>
  </body>
</html>