#Error 400, bad request on completion task

16 messages · Page 1 of 1 (latest)

sharp vector
#

Does the prompt contain prohibited characters? My API key works with the OpenAI-CLI "say test" request, but I can't get it to work with this JS script.


const finalPrompt = "Given a list of words, 'run, eat, sleep, pay', generate a JSON as follows: {'run': ['run', 'ran', 'run', 'runs', 'running'], 'eat': ['eat', ate', 'eaten', 'eats', 'eating'], 'sleep': ['sleep', 'slept', 'slept', 'sleeps', 'sleeping' ], 'pay': ['pay', 'paid', 'paid', 'pays', 'paying' ],}. Each word's array entry is [present, past, perfect, third person singular, continuous]. List: have, go, be, say, do, will, could, use, would, can, see, work, come, take, make, think, like, get, know, call, tell, want, give, find, mean ->"
const response = await openai.createCompletion({
        model: 'text-davinci-003',
        prompt: finalPrompt,
        temperature: 0,
        max_tokens: 4000,
      })

Request failed with status code 400

#

Error 400, bad request on completion task

formal gust
#

Try sending the prompt as a raw string and also change the single quotes to double for the model maybe?

sharp vector
#

Looks like it's the prompt. I sent a basic short prompt without a problem.

formal gust
#

Yes send it as a multi line raw string

#

I think it's `

#

For multi line in js

sharp vector
#

I'm wondering if there's a specific way to do it when working with dynamically created strings? The above was a simplification. I have 2-3 strings that I need to concatenate into the prompt.

#

I took one concatenated instance, made it a raw string, and ran it on that, but no luck.

#

I went on playground and saw the code it called. I need to only use ", and use \.

sharp vector
#

Solution, for posterity:

  1. If in doubt about prompt formatting, check https://beta.openai.com/playground?
  2. max_tokens is for the completed text, not both it and prompt text, so you can't set it as high as 4000 unless your prompt is less than 96 tokens (4096-4000). Try lowering your max tokens.
formal gust
#

@sharp vector Yes...convert it into a raw string...

#

Using / to concat each line is the same as just using ``

#

Additionally, using ` allows you yo create a template string with variables

let b = "George",
a = `
This is ${b}
`
sharp vector
#

I did like you said, but it still produced errors. But that’s because the real problem was that I set max_token too high, and there weren’t enough tokens left for the long prompt. I don’t think raw/normal string matter to the openai module, in the end.

formal gust
#

That's strange. I'm pretty sure the max accepted would be 4096