GPT-3 responding with blank text

I’m trying to set up the GPT-3 API on Bubble, but keep getting an empty text response in return to my calls.

I’ve added my key to the header and the content-type is set to application/json. I’m passing the following sample JSON (from the docs) via a POST to https://api.openai.com/v1/completions

{
  "model": "text-davinci-003",
  "prompt": "Say this is a test",
  "max_tokens": 7,
  "temperature": 0,
  "top_p": 1,
  "n": 1,
  "stream": false,
  "logprobs": null,
  "stop": "\n"
}

but when I initialize the call this is the response I get with a blank text response

Returned Values:

{
    "id": "cmpl-6......YXhL4y",
    "object": "text_completion",
    "created": 1673992522,
    "model": "text-davinci-003",
    "choices": [
        {
            "text": "",
            "index": 0,
            "logprobs": null,
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 5,
        "total_tokens": 5
    }
}

Does anyone have any suggestions? I’ve tried reaching out to OpenAI support but I guess they are super backed up.

1 Like

Just a guess but your tokens are set to 7, try going to 100. Also, if that doesn’t work, your stop is ‘\n’ so put a \n at the end of the prompt.

1 Like

You might consider starting with the defaults and see what happens, and then refine your API query from there:

{
  "model": "text-davinci-003",
  "prompt": "Say this is a test",
}

Or maybe, this:

{
  "model": "text-davinci-003",
  "prompt": "Say this is a test",
  "max_tokens": 1024,
}

Then, you can receive the response and refine your query from there.

HTH.

@adrianneestone did you end up figuring this out? I’m having the same issue, but I’ve already increased my max tokens to 2048.

It’s probably this…

You’re telling it to stop with a line break…

And when it starts the output, it starts with… a line-break…

Hope this helps…

I ended up getting it to work with "stop": ["\\n"]

I was getting super frustrated though because the code I was using came from the “Create Completion” dang example in the docs!

2 Likes

I was doing some more experimenting, and it turns out that slight edits to my prompt will result in one of two scenarios of incompletion. To give a little more context, I’m providing the same prompt multiple times, but subbing in the text that I want GPT3 to deal with. In some iterations of my prompt, I get the scenario that we’ve been talking about here, where all predictions are empty. However, for some iterations of my prompt, I get a few documents with predictions, and many others that are also null. Do folks have thoughts about why that may be? I haven’t changed the stop character yet.

Examples of my prompt for each case:

prompt = ('Extract the biological relationships from '
'the following text as (Subject, Predicate, Object) triples, and '
'include the index of the sentence from which the triple is extracted: '
f'{abstract_txt}.\nExample relationship triple:\n("Protein 1", '
'"regulates", "Protein 2", "Sentence 0")')

This prompt gets some responses.

This prompt, on the other hand, gets none:

prompt = ('Extract the biological relationships from '
'the following text as (Subject, Predicate, Object) triples, and '
'include the index of the sentence from which the triple is '
'extracted: '
f'{abstract_txt}.\nExample relationship triple:\n("Protein 1", '
'"regulates", "Protein 2"), "Sentence 0"')

In all cases, the {abstract_txt} variable is a list with one element, which is a string containing the text of a scientific abstract.

I’m wondering if there’s something else going on that just happens to correlate with me changing my prompts, or if it’s the prompts themselves? Why does such a small change result in no output, and why don’t I get output for all abstracts in either case?

EDIT: formatting

I had the same problem and your solution solved mine as well… Any idea why this seemingly random stop signal solved it?

1 Like

Thanks for your suggestion …It worked with “stop”: [“\n”]

1 Like

This is because you simply have removed the newline from your STOP because:

["\\n"] 

Is not a valid newline char because when you escape the newline as you have done, there is no longer a newline stop.

All you have done @adrianneestone is, by accident, removed the newline stop and your stop is now the literal “backslash n” instead of a newline.

In other words:

This is a newline stop

["\n"] 

This is NOT a newline stop (because you escaped the newline)

["\\n"] 

HTH

:slight_smile:

Appendix

From the Ruby console you can see clearly that when you put a backslash in front of a newline, the newline is escaped and is no longer a newline:

irb(main):008:0> a = "hello world\\n"
=> "hello world\\n"
irb(main):009:0> puts a
hello world\n

irb(main):010:0> a = "hello world\n"
=> "hello world\n"
irb(main):011:0> puts a
hello world