Error in writing AI code using template

Here’s the code:
import openai
import os
import sys

openai.api_key = os.environ[‘OPENAI_API_KEY’]
if openai.api_key == “”:
sys.stderr.write(“”"
You haven’t set up your API key yet.

If you don’t have an API key yet, visit:

https://platform.openai.com/signup

  1. Make an account or sign in
  2. Click “View API Keys” from the top right menu.
  3. Click “Create new secret key”

Then, open the Secrets Tool and add OPENAI_API_KEY as a secret.
“”")
exit(1)

response = openai.chat.completions.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”,

Summary

This text will be hidden

    "content":
    "The Los Angeles Dodgers won the World Series in 2020."
}, {
    "role": "user",
    "content": "Where was it played?"
}])

print(response)

This is what the Console area shows when i click Run:
Traceback (most recent call last):
File “/home/runner/SariyaAITemp/main.py”, line 22, in
response = openai.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/_utils/_utils.py”, line 303, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/resources/chat/completions.py”, line 598, in create
return self._post(
^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py”, line 1088, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py”, line 853, in request
return self._request(
^^^^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py”, line 916, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py”, line 958, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py”, line 916, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py”, line 958, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File “/home/runner/SariyaAITemp/.pythonlibs/lib/python3.11/site-packages/openai/_base_client.py”, line 930, in _request
raise self._make_status_error_from_response(err.response) from None
openai.RateLimitError: Error code: 429 - {‘error’: {‘message’: ‘You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.’, ‘type’: ‘insufficient_quota’, ‘param’: None, ‘code’: ‘insufficient_quota’}}

Screenshot is attatched.

Help me out please.

Hi @wajid24,

Update the first line of your code to

from boltiotai import openai

and try to run the code

Ensure that you’ve obtained the API key and got the access, as well as installed the boltiotai library.
If you haven’t completed these steps yet, please refer to the relevant sections in Module 1:

  1. “Getting access to the API Key” to get the API access
  2. “Install the boltiotai library”

Then, you can proceed with the topics to build the Artificial Intelligence projects covered in the training. If you encounter any further issues, feel free to reach out, and we’ll assist you accordingly.

1 Like

Hello sir,
It is saying:
from boltiotai import openai
ModuleNotFoundError : No module named ‘boltiot’

Hi @aparna.kulkarni99

Please check if you have installed the boltiotai library. If you have not installed , please install it by using the following command:

pip install boltiotai

Also do share a screenshot of the error you are getting.

Thanks! I did that and Run the code again but now it shows this

I even created a new API key and tried again but it isn’t working.

Hi @wajid24

Can you share a screenshot of the code and the secrets section so that we can verify the import statements and variable name. In the secret section , you can share a screenshot of the secret key variable with the api key hidden.

Thanks for your reply.
Here’s the code:

It doesn’t always ay missing or invalid api key. Sometimes it just remains blank.
Like this

This is the secrets area.

Hello
Where do we write that code:
pip install boltiotai

You write that in the shell area
image
like this

Hi @wajid24

Your code seems correct and the secret variable also seems correct. We have verified in our system and we see that you have not generate the boltiot api key which is needed for this project. To generate the api key please go to https://trainings.boltiot.com/ApiUsage and click on generate api key.

After the api key is generate copy and paste that api key in the secrets tab in Replit.

If you have done all these steps correctly your project should work when you click on the run button.

Do try this and let us know. If you still face any issues, please feel free to get back to us

Thank you so much! :grin: It worked!

1 Like

Hello
It is still showing the same thing

Hi @aparna.kulkarni99

Please do the following steps to resolve the issue
In your REPL, click on the “shell” tab and run the following command to install the library

pip install boltiotai

Next in your code, change the following the first line import openai to

from boltiotai import openai

Copy the API key generate from bolt training and paste it in the secrets tab in Replit. Then RUN the code again.

If you have all these steps correctly your program should work. If you still face any issues, please feel free to get back to us.

Hello,
In your REPL, click on the “shell” tab and run the following command to install the library
pip install boltiotai
Next in the code, write the following line
from boltiotai import openai

Copy the API key generate from bolt IoT training and paste it in the secrets tab in Replit.

I did the following steps but it is showing this:

@aparna.kulkarni99
Can you open the shell tab and run the below command and send me the screenshot of the output of it. So that I can verify if the library is installed correctly.
pip install boltiotai

Also do run the code after the above step to check if your code is working.

Hello sir,
Sorry for responding late, I had gone out.
This is the screenshot

Hi @aparna.kulkarni99

I see that your issue has not been resolved. Can you please share your repl to support@boltiot.com.

To share a Repl, click on the invite button at the top right corner and enter the email id support@boltiot.com.

If you still face any issue, please feel free to get back to us.

Hi @aparna.kulkarni99

Run your after installing the boltiotai library. to install boltai libray go to the shell tab and type pip install boltiotai and press "ENTER: Then run your code.

Let me know if this solves the issue.