microsoft/generative-ai-for-beginners

APIConnectionError in the first Jupyter notebook, lesson 4

webr5214 opened this issue · 6 comments

I forked the repository to run in GitHub Codespaces. I am loading my API key from a codespaces secret into the .env file. When I run the first code cell that uses the openai module in lesson 4, I get an http error. I tested with a print statement to make sure the OpenAI client is receiving my API key.

I tested with a curl command to see if I could access the openai api from within Codespaces and received the expected result.

curl https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer API_KEY " -d '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7}'

Which makes me think it's a Jupyter environment problem.

Here's the error message:
codespaces_lesson4

👋 Thanks for contributing @webr5214! We will review the issue and get back to you soon.

Hello, i have got same issue when run Exercise 2,
Ex2-error
I used latest openai package version 1.61.
I have checked the requirements.txt and downgrade openai from 1.61 to 0.28.0 and got another error. with below picture
Ex2-error-openai0 28 0
Do you have any idea?

Thanks for reporting, will take a look and let you know if we need any additional information!

I just walked through the notebook for Lesson 4 right now. I believe that has been updated now to use the Azure OpenAI provider key/endpoint vs. OpenAI which might be a reason why the call to the OpenAI API works from command-line, but the code fails.

I believe there is an OpenAI-specific set of exercises planned for the lessons. But for now, you will need to use an Azure OpenAI endpoint. If you have issues with that, can you please update this with new details?

Here is what the successful run looks like:

image

image

cc @koreyspace