#Getting error in esaay app

61 messages · Page 1 of 1 (latest)

vivid lotus
#

I was making a web app that can generate essay but it seems i am encountering this error POST https://cors-anywhere.herokuapp.com/https://api.openai.com/v1/text-davinci/questions 404 (Not Found) sendTopicAndWordCount @ index.html:24 onclick @ index.html:13
This is the code `<!DOCTYPE html>
<html>
<head>
<title>Essay Generator</title>
</head>
<body>
<h1>Essay Generator</h1>
<form>
<label for="topic">Topic:</label><br>
<input type="text" id="topic" name="topic"><br>
<label for="wordCount">Word Count:</label><br>
<input type="number" id="wordCount" name="wordCount"><br><br>
<button type="button" onclick="sendTopicAndWordCount()">Generate Essay</button>
</form>
<div id="response"></div>

<script>
function sendTopicAndWordCount() {
// Get the topic and word count from the form
var topic = document.getElementById("topic").value;
var wordCount = document.getElementById("wordCount").value;

  // Make the API request using a CORS proxy
  fetch("https://cors-anywhere.herokuapp.com/https://api.openai.com/v1/text-davinci/questions", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": "Bearer api key"
    },
    body: JSON.stringify({
      "prompt": "Write a essay on " + topic,
      "max_tokens": wordCount
    })
  })
  .then(response => response.json())
  .then(response => {
    // Display the API's response in the div
    document.getElementById("response").innerHTML = response.text;
  });
}

</script>
</body>
</html>`

vivid lotus
#

Failed to load resource: the server responded with a status of 404 (Not Found) index.html:24 POST https://cors-anywhere.herokuapp.com/https://api.openai.com/v1/text-davinci/questions 404 (Not Found) sendTopicAndWordCount @ index.html:24 onclick @ index.html:13 This is the error that am getting

edgy wyvern
#

uhhh

#

I dont know

#

sorryyy

vivid lotus
#

ok

#

i replaced the url but still error https://api.openai.com/v1/completions index.html:24 POST https://cors-anywhere.herokuapp.com/https://api.openai.com/v1/completions 400 (Bad Request) sendTopicAndWordCount @ index.html:24 onclick @ index.html:13

cerulean mist
#

You don’t have some of the required fields being sent in your request. You’re only sending max_tokens as a post parameter, you need other things such as model, look at the API docs for the required fields

vivid lotus
#

still the same error

#
  "prompt": "essay on" + topic,
  "max_tokens": wordCount,
  "temperature": 0.1```
vivid lotus
#

POST https://api.openai.com/v1/completions 429
This is my code

<html>
<head>
  <title>Essay Generator</title>
</head>
<body style="background-color: crimson;">
  <h1 style="text-align: center;">Essay Generator</h1>
  <form style="background-color: aqua; text-align: center; border-color: rgb(16, 30, 221); border-radius: 10cm;">
    <label for="topic">Topic:</label><br>
    <input type="text" id="topic" name="topic"><br>
    <label for="wordCount">Word Count:</label><br>
    <input type="number" id="wordCount" name="wordCount"><br><br>
    <button type="button" onclick="sendTopicAndWordCount()">Generate Essay</button>
  </form> 
  <div id="response" style="text-align: center;"></div>

  <script>
    function sendTopicAndWordCount() {
      // Get the topic and word count from the form
      var topic = document.getElementById("topic").value;
      var wordCount = document.getElementById("wordCount").value;

      // Make the API request using a CORS proxy
      fetch("https://api.openai.com/v1/completions", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": "Bearer key"
        },
        body: JSON.stringify({
          "model": "text-davinci-003",
          "prompt": "essay on" + topic,
         "max_tokens": wordCount,
          "temperature": 0.1
        })
      })
      .then(response => response.json())
      .then(response => {
        // Display the API's response in the div
        document.getElementById("response").innerHTML = response.text;
      });
      // https://cors-anywhere.herokuapp.com/https://api.openai.com/v1/completions
      //https://api.openai.com/v1/text-davinci/questions
    }
  </script>
</body>
</html>```
cerulean mist
#

Isn't an endpoint

vivid lotus
cerulean mist
vivid lotus
#

I have this url in my code only

cerulean mist
#

hmm

#

That's not what the text u sent above shows?

#

I see that it's in your html code below but that one gave a 404

#

For error 429, that means you're being sending messages too fast, so check if your code is spamming the API

#

It can also mean that the server is overloaded, the API returns 429 sometimes

vivid lotus
#

Yes i am getting 429 error but i am only requesting for 50 words essay on a "topic".

mint frigate
#

Bear in mind your input tokens count towards your max tokens too, so you probably want to add some maths into your max-tokens calculation.

#

@vivid lotus

#

Http 429 error is too many requests ^

vivid lotus
#

Max token is number of word count i input

#

Topic is Battle of Waterloo

#

Word count is 50

#

50 word essay is too many request?

vivid lotus
mint frigate
#

prompt: essay on $num$num
max_tokens: $num

vivid lotus
#

yes

#

I just added wordCount in prompt

#

I even changed Api key with different account but i am still getting 429 error.

vivid lotus
earnest delta
#

Did u try using chatGPT?

vivid lotus
#

I tried to ask it to solve this error but it was no help.

vivid lotus
#

Hello

#

?

vivid lotus
#

?

vivid lotus
#

?

earnest delta
#

ayo

#

u should have "replied" to my message or tagged me

vivid lotus
#

@earnest delta do you have any solution?

earnest delta
#

Unfortunately no

mint frigate
#

Rather than a prompt with a ? each day @vivid lotus consider showing others what you're doing to solve the problem yourself and you may find others more willing to help

vivid lotus
#

Actually I solved this error but now i am not getting any response back but when i go to my account in open AI it's showing that i made requests. @mint frigate

#

I changed my code to this ``` <!DOCTYPE html>
<html>
<head>
<title>Essay Generator</title>
</head>
<body style="background-color: crimson;">
<h1 style="text-align: center;">Essay Generator</h1>
<form style="background-color: aqua; text-align: center; border-color: rgb(16, 30, 221); border-radius: 10cm;">
<label for="topic">Topic:</label><br>
<input type="text" id="topic" name="topic"><br>
<label for="wordCount">Word Count:</label><br>
<input type="number" id="wordCount" name="wordCount"><br><br>
<button type="button" onclick="sendTopicAndWordCount()">Generate Essay</button>
</form>
<div id="response" style="text-align: center;"></div>

<script>
function sendTopicAndWordCount() {
// Get the topic and word count from the form
var topic = document.getElementById("topic").value;
var wordCount = document.getElementById("wordCount").value;

  // Make the API request using a CORS proxy
  fetch("https://api.openai.com/v1/completions", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": "Bearer myapi"
    },
    body: JSON.stringify({
      "model": "text-davinci-003",
      "prompt": "essay on " + topic ,
     "max_tokens": parseInt(wordCount),
      "temperature": 0.1
    })
  })
  .then(response => response.json())

.then(response => {
// Display the API's response in the div
document.getElementById("response").innerHTML = response.text;
});
// https://cors-anywhere.herokuapp.com/https://api.openai.com/v1/completions
//https://api.openai.com/v1/text-davinci/questions
}
</script>
</body>
</html>```

#

I changed max_token word count to ParseInt()

#

I also used another api after creating new account

#

It seems that i am sending a request to my api and i am probably getting a response back because in my account it's showing that i made request to api but the result is not being displayed somehow.

#

5:25 PM
Local time: Jan 1, 2023, 10:55 PM
text-davinci, 1 request
8 prompt + 50 completion = 58 tokens
5:30 PM
Local time: Jan 1, 2023, 11:00 PM
text-davinci, 1 request
7 prompt + 40 completion = 47 tokens

vivid lotus
mint frigate
#

Make it simpler.

Reduce your code and test it without the variables. Enter some plain text in your prompt - Do you get a better response?

If so, the problem is further up your code in your variable definition.