MOVR
44
Had the issue running an Google Colab Notebook with LangChain 0.0.331.
As default it ran with openai 1.1.1. and that is producing the error
/usr/local/lib/python3.10/dist-packages/langchain/embeddings/openai.py
...
AttributeError: module 'openai' has no attribute 'Embedding'
1 Like
Sanceo
45
hey, are you interested in helping out, got that problem.
kydebro
46
Hero! Thanks for this. Can confirm this was the issue.
Thank you so much!!! I was searching for a solution from so my time
Hi, I’m currently using openai-1.1.1 version. But I’m still getting this error. module ‘openai’ has no attribute ‘ChatCompletion’
sps
49
Welcome to the OpenAI community, @spoorthyan20!
Here’s how you can do chat completions with OpenAI Python v1.1.1:
from openai import OpenAI
client = OpenAI(
# api_key defaults to os.environ.get("OPENAI_API_KEY")
api_key="My API Key",
)
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Say this is a test",
}
],
model="gpt-3.5-turbo",
)
source
2 Likes
thanks, do you have the API Reference or some examples in the documentation?
This: OpenAI Platform is a little sparse and I’d love to understand the new api better.
1 Like
sps
51
Hi @ollibolli
Welcome to the community.
Here are some resources for you:
Unfoftunetly dont work in Googke Colab notebook. Any othrr ideas?
totyped
53
However, if one tries to get the chatbot response using:
response['choices'][0]['message']['content'] as describes here OpenAI Platform
One gets: TypeError: ‘ChatCompletion’ object is not subscriptable
I would like to mention, that this should be fixed din the documentation to:
content = response.choices[0].message.content
3 Likes
It works in in Google Colab. Try:
from openai import OpenAI
client = OpenAI(
api_key=“Your API KEY”,
)
chat_completion = client.chat.completions.create(
messages=[
{
“role”: “user”,
“system”: “xxxxx”,
“content”:“xxxxxx”
}
],
model=“gpt-XXXX”,
max_tokens= XXXX,
)
print(chat_completion.choices[0].message.content)
1 Like
Thanks it work for me pip install openai==0.27.8
1 Like
Guys could someone help me with this?
I’m getting this now! AttributeError: module ‘openai’ has no attribute ‘Completion’
I fixed this issue by uninstalling OpenAI:
pip3 uninstall openai
Then reinstalling it:
pip3 install openai
simon26
59
Getting this error just today, worked yesterday without issues.
1 Like
Came to this issue on Google Colab. The following works:
!pip3 install openai
from openai import OpenAI
from google.colab import userdata
client = OpenAI(
api_key=userdata.get('OPENAI_API_KEY'),
)
def llm_response(prompt):
response = client.chat.completions.create(
model='gpt-3.5-turbo',
messages=[{'role':'user','content':prompt}],
temperature=0
)
return response.choices[0].message.content
prompt = '''
Classify the following review
as having either a positive or
negative sentiment:
The banana pudding was really tasty!
'''
response = llm_response(prompt)
print(response)
_j
61
Perhaps when posting in this thread someone could spend thirty seconds of reading, install “openai classic”, and press the thanks button for the answer above…
pip install "openai<1.0.0"
Or alternately code for the new methods of the API library changes.
If OpenAI had given anyone a heads up instead of jumping from 1.0.0beta2 all the way to 1.1.1 internal and dumping wheels on those millions of developers, maybe a generous person could have written and put in a pull request for another cookbook notebook to be put up “how this all works without paying for a 3rd party code-conversion service, all the way from simple calls up to asyncio streaming multimodal multi-client with token-counting chat history client management”
5 Likes
I had the same problem, while using skll library
The only solution was to install openai version 0.28.1
pip install openai==0.28.1
1 Like
thanks…this works for me…i m using ubuntu on wsl2 and vscode