Search code examples
pythonopenai-api

Openai api Completion.create not working on my python code


In openai.py the Completion.create is highlighting as alert and also not working.. the error is right down below.. whats the problem with the code

response = openai.Completion.create(
    engine="text-davinci-002",
    prompt="Generate blog topic on: Ethical hacking",
    temperature=0.7,
    max_tokens=256,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
)

$ python openai.py
Traceback (most recent call last):
  File "E:\python\openAI\openai.py", line 2, in <module>
    import openai
  File "E:\python\openAI\openai.py", line 9, in <module>
    response = openai.Completion.create(
AttributeError: partially initialized module 'openai' has no attribute 'Completion' (most likely due to a circular import)

Solution

  • for my fellow doofuses going thru all the above suggestions and wondering why its not working:

    make sure your file is NOT named openai.py. because then it will call itself, because python.

    wasted 2 hours on this nonsense lol.

    relevant link How to fix AttributeError: partially initialized module?