Forum in maintenance, we will back soon π
Connect Python with OpenAI API install error
Please, I need help, I don't know how to make it work.
I do have a problem connecting Python to OpenAI API.Β
I did:
Open the Terminal, and install OpenAI Package by running the command:
File "c:\Users\10_Pro\chatgpt.py", line 11
return completion.choices[0].message.content
IndentationError: unexpected indent
PS C:\Users\10_Pro> & C:/Users/10_Pro/AppData/Local/Programs/Python/Python312/python.exe c:/Users/10_Pro/chatgpt.py
Traceback (most recent call last):
File "c:\Users\10_Pro\chatgpt.py", line 15, in <module>
response = generate_text_with_openai(prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\10_Pro\chatgpt.py", line 7, in generate_text_with_openai
completions = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\10_Pro\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\lib\_old_api.py", line 39, in __call__
raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the
API.
You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
PS C:\Users\10_Pro> & C:/Users/10_Pro/AppData/Local/Programs/Python/Python312/python.exe c:/Users/10_Pro/chatgpt.py
Traceback (most recent call last):
File "c:\Users\10_Pro\chatgpt.py", line 15, in <module>
response = generate_text_with_openai(prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\10_Pro\chatgpt.py", line 7, in generate_text_with_openai
completions = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\10_Pro\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\lib\_old_api.py", line 39, in __call__
raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the
API.
You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
PS C:\Users\10_Pro> & C:/Users/10_Pro/AppData/Local/Programs/Python/Python312/python.exe c:/Users/10_Pro/chatgpt.py
Traceback (most recent call last):
File "c:\Users\10_Pro\chatgpt.py", line 15, in <module>
response = generate_text_with_openai(prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\10_Pro\chatgpt.py", line 7, in generate_text_with_openai
completions = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\10_Pro\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\lib\_old_api.py", line 39, in __call__
raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the
You can run `openai migrate` to automatically upgrade your codebase to use the 1
Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
PS C:\Users\10_Pro> openai migrate
Error: Windows is not supported yet in the migration CLI
PS C:\Users\10_Pro> & C:/Users/10_Pro/AppData/Local/Programs/Python/Python312/python.exe c:/Users/10_Pro/chatgpt.py
Traceback (most recent call last):
File "c:\Users\10_Pro\chatgpt.py", line 15, in <module>
response = generate_text_with_openai(prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\10_Pro\chatgpt.py", line 7, in generate_text_with_openai
completions = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\10_Pro\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\lib\_old_api.py", line 39, in __call__
raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the
API.
You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
PS C:\Users\10_Pro> & C:/Users/10_Pro/AppData/Local/Programs/Python/Python312/python.exe c:/Users/10_Pro/chatgpt.py
Traceback (most recent call last):
File "c:\Users\10_Pro\chatgpt.py", line 15, in <module>
response = generate_text_with_openai(prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\10_Pro\chatgpt.py", line 7, in generate_text_with_openai
completions = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\10_Pro\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\lib\_old_api.py", line 39, in __call__
raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the
API.
You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
PS C:\Users\10_Pro> & C:/Users/10_Pro/AppData/Local/Programs/Python/Python312/python.exe c:/Users/10_Pro/chatgpt.py
Traceback (most recent call last):
File "c:\Users\10_Pro\chatgpt.py", line 15, in <module>
response = generate_text_with_openai(prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\10_Pro\chatgpt.py", line 7, in generate_text_with_openai
completions = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\10_Pro\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\lib\_old_api.py", line 39, in __call__
raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the
API.
You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
PS C:\Users\10_Pro>
@ionut-antal update your code library with the one provided here https://github.com/hassancs91/PE-Course-codes
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@ssadvisor , sorry, I tried to understand but I don't.Β
Please can you be more specific with a few steps?Β
Thanks a lot for your time and help!
@ionut-antal OpenAI's update changed some structures of the codes. @hasan is working on updating all codes in the course, but for now, you can check the updated codes in @Hasan's GitHub repository @ssadvisor provided: Β https://github.com/hassancs91/PE-Course-codes
Thanks
I am a completely beginner,Β I saw what @ssadvisor provided but I don't understand wich code to use, because there are so many. That's why I asked for some steps.Β
Β
Hi @ionut-antal, what they mean, is just update the code you are using since OpenAI updated.
this code is no longer working, you should use the new one.
you can find all new codes here: https://github.com/hassancs91/PE-Course-codes
@ionut-antal you can use this link to download a zip of the new code. https://github.com/hassancs91/PE-Course-codes/archive/refs/heads/main.zip
Or you can use the command ```git clone https://github.com/hassancs91/PE-Course-codes.git``` if you want to use the proper git command.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
Hi guys,Β
Happy New Year! All the best to everyone!Β
Β
It is not a really a course for a beginner.Β It is not easy to set up the computer right! After 2 weeks of breakΒ I realised that I want to go ahead and learn about this skill because I nearly give up after hours and hoursΒ trying.Β
Also I have to specify that my system is Windows 10 pro.
I don't find a way to connect them.Β Β
I don't want to give up , I want to learn.Β
Every error I had I gave it to Chatgpt and he tried to give me all kind of solutions like:
- pip install --upgrade openai
- Here's a step-by-step guide for setting up and using WSL for this purpose:
- Open a PowerShell or Command Prompt as an administrator and runΒ
wsl --install
. - Restart your computer.
- Open the WSL application.
- In the WSL terminal,Β
cd
Β into the appropriate directory (e.g.,Βcd /mnt/c/Users/Myself/my/code/
) and then run the following commands:curl -fsSL https://docs.grit.io/install | bash grit install grit apply openai
Β
Β Β Β Β Β Then, you can close WSL and go back to using Windows.
Β
- pip install openai==0.28Β (because I had this error in the terminal)
- openai migrate
- pip install multidict
- Install Microsoft Visual C++ Build Tools :
Β Β Β Β
Β Β Β Β Β Β Β Β Β When installing Microsoft Visual C++ Build Tools, you generally need to ensure that the following components are selected:
-
Desktop development with C++:
- This is a broad category that includes the necessary tools and libraries for C++ development.
-
Universal Windows Platform development:
- If you are working with UWP applications, you may need to select this option.
-
C++ CMake tools for Windows:
- If your project uses CMake for building, this component is required.
-
Windows 10 SDK:
- Ensure that you have the Windows 10 SDK installed. The version may vary, but it's generally a good idea to have the latest.
-
C++ ATL for latest v142 build tools (x86 & x64):
- ATL (Active Template Library) is sometimes required for C++ projects
Β
- pip download multidict==5.1.0.
Β
Β Β Β Please guys help me to set this up so I can carry on learning! I am really lost right now ( I hope that I didn't get you lost now :))Β ).
Β
Β
Hi Friend, Happy New Year.
Sometimes ChatGPT hallucinate and give answers that has nothing to do with your problem.Β
and remember that it answers on what is trained on, and this may be a new error due to the last openAI update.
Going back to your error. is this what you are getting:
"You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0"
Still the same error?
If yes, it is just that you need to update the code. you just need to use my latest update, can you please share aΒ screenshot of your code to tell you what to change?
Β
I know if you are totally new to this, it will look a bit hard, but these skills will really help you a lot, not only in business even in your personal life.
just put in some more effort and try to continue.
This is because Openai updated their package. You need to update the code and use: openai.chat.completions.create instead of openai.ChatCompletion in the code.
Is this my script? Or something you created?
if it is mine, please share which one to update and fix
Yes it is your script. I hope that I did the change right.Β
Now I have this result in the terminal.
Thanks for helping me.Β
if you think that I have to learn something else before this , let me know, I do everything just to get this right.
Β
@ionut-antal did you upgrade the course codes with https://github.com/hassancs91/PE-Course-codes?
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@ssadvisor Yes. Actually, can you give me thatΒ specific code? because you have been asking me so many times about it, maybe I don't get the right code. Thanks
@ionut-antal the link I gave you has a zip file you can download. If you can't find it maybe you need a 1-on-1 to help?
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack