is the empty response problem persistent with different prompts or specific to this one ? and can you share the response object ?

1 Like

Maybe consider a different Python OpenAI lib?

:slight_smile:

@dhiaeddine.khalfalla if I use a different prompt, the empty response problem doesn’t persist. The response variable is shared.

@ruby_coder I am using openai package

Then, if that is the case, your basic params look like this:

completion = openai.Completion.create(model="text-davinci-003", prompt="Hello world")

As mentioned by @dhiaeddine.khalfalla

There is no engine param. That cannot work.

Your Original Post @lee19619

Did you use ChatGPT to write that code for you, @lee19619 ?

:slight_smile:

@ruby_coder yes, the code is generated by ChatGPT. But I have tried using model instead of engine and it doesn’t work.

Yes, but the code generated by ChatGPT is wrong. So you should go to the GitHub page and follow the code examples there, first (and please stop using ChatGPT to write code for you if you are not going to verify it):

ChatGPT writes very bad OpenAI API code based on long (close to two years) deprecated libs.

As a “novice” software developer, it’s best, I assure you, to code from the current docs of the libs you are using.

:slight_smile:

@ruby_coder is my code correct now?

My code:

response = openai.Completion.create(
    model="text-davinci-003",
    prompt=prompt,
    max_tokens=256,
    n=1,
    stop=None,
    temperature=0.0,
)

Yes, but you should add a stop for good measure, something like "####".

Also, you should print your completion response as follows, per the Python docs:

# print the completion
print(response.choices[0].text)

HTH

:slight_smile:


Note: If you still get a blank response, please post your prompt you are using so I can test it for you. My code works fine so it’s easy to test and I’m happy to test if for you.

OR

You can first try this to see if there is an error message (also wisely suggested by @dhiaeddine.khalfalla earlier, BTW):

print(response)

@ruby_coder this is prompt:

prompt = (
    "Extract the location, category, and keywords from the following sentence:\n\n"
    "{sentence}\n\n"
    "Location: [input location]\n"
    "Categories: {category_options}\n"
    "Keywords: [input keywords]"
)
category_options = "|".join(categories)
prompt = prompt.format(sentence=sentence, category_options=category_options)

After my tests, if I change the prompt to this, it doesn’t return blank:

prompt = (
    "Extract the location, category, and keywords from the following sentence:\n\n"
    "{sentence}\n\n"
    "Location: [input location]\n"
    "Categories: [input categories]\n"
    "Keywords: [input keywords]"
)
prompt = prompt.format(sentence=sentence)

Assuming that the test above is your single prompt (not sure that it is, but that’s another topic), I do not get a blank reply:

Appendix: Completion Setup

@Rube_coder your test code will not respond blank (second code). Try the first code (above the code you tested).

Additionally, the categories variable is a list of category strings.

I am not following you. I need your prompt text only, not the Python variable which stores your prompt.

Please post only the prompt. No python code. THE PROMPT :slight_smile: NO CODE, no Python variables :slight_smile:

Thanks.

@ruby_coder ok here’s the prompt:

Extract the location, category, and keywords from the following sentence:

I'm looking for a good italian restaurant in New York City.

Location: [input location]
Categories: Abruzzo Restaurant|Accessories|Accountant|Acupuncturist|Aerospace Company|Afghan Restaurant|African Restaurant|Agricultural Service|Agriculture|Airline Company|…
Keywords: [input keywords]

You can add more categories to your tests.

It’s ok… this is what I got… which seems like what you were looking for.

Appendix: Set up

@ruby_coder sorry, I don’t understand seeing those images. What’s the result?

The result is called “the completion”, BTW…

1 Like

@ruby_coder why does it succeed but mine doesn’t? Do you have any idea?

Well, I’m a great coder, (hahaha) and wrote a test lab which does the entire OpenAI API so I can help folks here who have problems and need “real” help in a public OpenAI developer community (like you) :slight_smile:

First of all you started off with OpenAI API code written by ChatGPT, that was a mistake.

Second, you did not follow @dhiaeddine.khalfalla correct advice to print your entire response out so others can see what the entire response looks like (part of debugging).

Run your code again and do not use the print line you got from ChatGPT. Use this and post back what you get

print(response)

:slight_smile:

1 Like

I ran into this issue and never figured out the why. But it seems to do something with the question asked after the initial prompt.

In my case I get around this by checking for an empty response, and then have the code request to ask another way, that way the code doesn’t fail in place. Here is an example of how I am passing this with Javascript:

    var s = oJson.choices[0].text;
      // Empty Response Handling	     
        if (s == "") {
    	   txtOutput.value += "Eva: I'm sorry can you please ask me in another way?";
	    } else {
    	   txtOutput.value += "Eva: " + s.trim();
	      }
1 Like