openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

AttributeError: module 'openai' has no attribute 'openai_response'

Open kaanbursa opened this issue 2 years ago • 3 comments

Describe the bug

Just ran the documentation code on Jupyter notebook and got in python3.9/site-packages/openai/util.py:112 if isinstance(resp, openai.openai_response.OpenAIResponse): 113 organization = resp.organization 114 response_ms = resp.response_ms

AttributeError: module 'openai' has no attribute 'openai_response'

To Reproduce

pip install -U openai in jupyter notebook

Code snippets

import openai

openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who won the world series in 2020?"},
        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
        {"role": "user", "content": "Where was it played?"}
    ]
)

OS

macOS m1

Python version

Python v3.9.12

Library version

openai-python v0.27.0

kaanbursa avatar Mar 01 '23 19:03 kaanbursa

Can you share a link to the code you are referencing?

logankilpatrick avatar Mar 02 '23 02:03 logankilpatrick

this is the link of the code snippet (Chat Completion Introduction): https://platform.openai.com/docs/guides/chat/introduction

ank05b avatar Mar 02 '23 07:03 ank05b

@kaanbursa I had the same issue after installing openai v0.27.0. Try to restart jupyter notebook kernel. It helped me. Another variant is to run python script instead of jupyter notebook

NktBkzn avatar Mar 02 '23 14:03 NktBkzn

Yeah, this code works as is, please try using a virtual environment inside of Jupyter and it should do the trick!

logankilpatrick avatar Mar 03 '23 16:03 logankilpatrick