Openai.chat.completions.create(

I basically want Chat-GPT to work

I keep getting an error pointing to chat.completions line
I’m trying to recopy a tutorial I’m learning online

Code Sample:
def generate_description(input):
messages = [
{“role”: “system”,
“content”: “Generae multip paragraph rich text product description with emojis from information”}
]
messages.append({“role”: “user”, “content”: f"{input}"})
response = openai.chat.completions.create(
model= “gpt-4”,
messages=messages
)
reply = response.choices[0].message.content
return reply

Clone link:
share a copy of your app

It is impossible to answer this question because… there is no question.

You didn’t say what you are doing, what you expect as a result, what you are getting instead, what error you are getting and at what line, and the code you provide is not well formatted.

Please try to provide more information, and someone will (more likely) help you: How to ask a good question

Sorry, I’m def a rookie.
I’m adding Chat GPT to my website using a tutorial " Build AI Web app with Custon UI using Python, Anvil and ChatGPT API" by [Pradip Nichite].
When I click the Generate button, I get an AttributeError: module ‘openai’ has no attribute ‘chat’ at ServerModule1, line 25.
Points to this line “response = openai.chat.completions.create(”

Try the url directly instead of the python objects, it’s working well for me:

question = "your question"
headers = {
    "Content-Type": "application/json",
    "Authorization": "your token",
  }
  payload = {
    "model": "text-davinci-003",
    "prompt": question,
    "temperature": 1.0,
  }
  try:
    return requests.get(url="https://api.openai.com/v1/completions", headers=headers, params=payload).json()
  except Exception as e:
    return f"Error querying ChatGPT: {e}"

thanks, but I figured it out by asking Bing GPT why the particular line of code didn’t work. And I got this:

Turns out the code I used was no longer supported, so I had to update the code with new lines.

I’m sorry to hear that you’re having trouble with openai.chat.completions.create(). According to a Stack Overflow post, this error message is displayed when you try to access openai.ChatCompletion, which is no longer supported in openai>=1.0.0. The post suggests that you can replace the function with something else to work on your version. You can also try upgrading or downgrading your installation of openai using pip.

If you’re still encountering issues, I recommend posting a question on a relevant forum or community to get more help from experts.

1: python - OpenAI API error: "You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0" - Stack Overflow