Receive empty response for API even though playground has proper answer

Hello there, I have been having issues with using API. Here is my prompt and code

   error_message = """
    Generate an explanation and a step-by-step solution for the following error message:

    #### Error message:
    NameError: name 'scanpy' is not defined

    #### Solution:
    1. Import the scanpy library at the beginning of your code: `import scanpy`.
    2. Ensure that the scanpy library is installed in your environment using `pip install scanpy`.
    3. Retry running the code after these steps.

    Please provide a detailed explanation and solution.
    """

    response = openai.Completion.create(
        model="text-davinci-003",
        prompt=error_message,
        temperature=0,
        max_tokens=182,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0,
        stop=["###"]
    )

and the reponse is empty as shown below:

{
  "warning": "This model version is deprecated. Migrate before January 4, 2024 to avoid disruption of service. Learn more https://platform.openai.com/docs/deprecations",
  "id": "cmpl-7tU4gMYvHEs2mOEgxCRsVwQfiwNgY",
  "object": "text_completion",
  "created": 1693458002,
  "model": "text-davinci-003",
  "choices": [
    {
      "text": "\n    ",
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 115,
    "completion_tokens": 3,
    "total_tokens": 118
  }
}

The exactly same code and same prompt used in playground works: OpenAI Platform

I am not sure why and how to fix it. Thanks!

Welcome to the community @annashen199949

The non-useful response is the result of combination of your prompt and:

Here’s what the model responds with if the stop sequence is removed:

{
  "warning": "This model version is deprecated. Migrate before January 4, 2024 to avoid disruption of service. Learn more https://platform.openai.com/docs/deprecations",
  "id": "cmpl-********************************57SiI",
  "object": "text_completion",
  "created": 1693459175,
  "model": "text-davinci-003",
  "choices": [
    {
      "text": "\n    #### Explanation:\n    The NameError occurs when a variable or function is referenced before it has been defined. In this case, the error is caused by referencing the scanpy library before it has been imported. To fix this error, you need to import the scanpy library at the beginning of your code and ensure that it is installed in your environment. \n    \n    #### Solution:\n    To solve this error, follow these steps:\n    \n    1. Import the scanpy library at the beginning of your code by adding the line `import scanpy`.\n    2. Ensure that the scanpy library is installed in your environment by running `pip install scanpy`.\n    3. Retry running the code after these steps.",
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 115,
    "completion_tokens": 158,
    "total_tokens": 273
  }
}

Likely because it’s generating the markdown formatting with ####, encounters ### mid-generation and stops the generation.

Also as the warning says, this model is deprecated, instead use gpt-3.5-turbo or other chat completion models.

4 Likes

@annashen199949 Feel free to mark it as solution if it’s solved.

1 Like