Authentication error regarding the api key again

I was running my project for bolt internship , and I came across this error on webpage multiple times can you please let me know what problem might be,it is about the api key.

also about answering forum question for internship how exactly should I![error|690x324](upload://6O2iM8qz93qG4REO6OxQKziopF1.png) do it

Hi @fatakkc21.instru

The screenshot you have attached is not visible. Kindly attach the screenshot using the attach image option while you draft the forum query. Also can you elaborate on the error you are getting?

Regarding the forum question for internship, here is how you go about it:

  1. For Training completion exam, Answer any 2 forum queries on this forum page (forums.boltiot.com) and copy paste the link when you are answering the exam.

  2. For the internship tasks, answer any 4 forum queries on this forum page (forums.boltiot.com) and copy paste the link in the form when you submit the project.

Do attach the screenshot and let us know if you have any more queries.

I am really sorry for such oversight , I have attached the screenshot of the error I had gotten, I completed both my projects for bolt internship, I was testing them for recording my code explanation but I came across this error .

can you please help me with how can I solve this error ,it says it is a Authentication error and that API key is incorrect i generated two API keys, still got same error

  1. For Training completion exam, Answer any 2 forum queries on this forum page (forums.boltiot.com) and copy paste the link when you are answering the exam.

here in this point you mentioned I have already given the examination and got my certificate as well ,I wasn’t really asked to perform this task you mentioned here.

can you please guide me about this as well
2. For the internship tasks, answer any 4 forum queries on this forum page (forums.boltiot.com) and copy paste the link in the form when you submit the project.

also about answering on the forum for internship, many of the post have already been replied so am I supposed to answer the question still ,like what should I do, please kindly guide me through this

Hi @fatakkc21.instru

Can you share screenshot of your code? This will help us to provide you with a better solution

from flask import Flask, render_template_string, request
import openai
import os

Helper function to generate health advice

def generate_health_advice(messages):
openai.api_key = os.environ.get(“API_KEY”)
if not openai.api_key:
return “You have not set the OpenAI API key.”

response = openai.chat.completions.create(model="gpt-3.5-turbo",
                                          messages=messages)

if  not  response.choices or len(response.choices) == 0:
    return "Sorry, unable to provide health advice at the moment. Please try again later."

output = response.choices[0].message.content
return output

Create a Flask web application object named app

app = Flask(name)

Initialize messages

messages = [{
“role”:
“system”,
“content”:
“You are a helpful assistant providing health-related advice. You need to interactively assist users with either diet plans or illness information based on their input.”
}]

@app.route(‘/’, methods=[‘GET’, ‘POST’])
def home():
global messages
user_input = “”
response = “”

if request.method == 'POST':
    user_input = request.form['query']
    messages.append({"role": "user", "content": user_input})

    if user_input.lower() == 'd':
        response = "Please provide your age, gender, weight, and height separated by commas (e.g., 25, male, 70kg, 175cm):"
    elif user_input.lower() == 'i':
        response = "What disease can I help with?"
    else:
        # Handle inputs for age, gender, weight, height for diet or disease details
        last_message = messages[-2]['content']
        if last_message.startswith("Please provide your age"):
            age, gender, weight, height = [
                x.strip() for x in user_input.split(',')
            ]
            messages.append({
                "role":
                "user",
                "content":
                f"Age: {age}, Gender: {gender}, Weight: {weight}, Height: {height}"
            })
            user_input = f"I need a diet plan for a {gender} aged {age} with a weight of {weight} and height of {height}."
        elif last_message == "What disease can I help with?":
            messages.append({
                "role": "user",
                "content": f"Disease: {user_input}"
            })

        response = generate_health_advice(messages)

    messages.append({"role": "assistant", "content": response})

return render_template_string('''<!DOCTYPE html>
Personal Health Assistant

YOUR PERSONAL HEALTH ASSISTANT

{% for message in messages %} {% if message.role == 'user' %}
You:
{{ message.content }}
{% else %}
Assistant:
{{ message.content }}
{% endif %} {% endfor %}
How may I help you?:
Submit
''', messages=messages)

Start the Flask application if the script is being run directly

if name == ‘main’:
app.run(host=‘0.0.0.0’, port=8080, debug=True)
this is the code, ALSO PLEASE HELP ME WITH MY OTHER MENTIONED PROBLEMS

Hi @fatakkc21.instru
Please do the following:

  1. install the boltiot library using pip install boltiotai
  2. Change the import statement to from boltiotai import openai
  3. generate the API key from bolt trainings page. Paste the key in the secrets tab in Replit’
  4. Make sure that the Key variables are matching in the code and in the secrets section
    5.Run the code again

If you have followed these steps correctly, your project should work fine. If you still face any issue, please feel free to get back to us.

1.i followed all the instructions but still i am getting the same error

this is the code(main):
from boltiotai import openai
from flask import Flask, render_template_string, request
import openai
import os

Helper function to generate health advice

def generate_health_advice(messages):
openai.api_key = os.environ.get(“API_KEY_o”)
if not openai.api_key:
return “You have not set the OpenAI API key.”

response = openai.chat.completions.create(model="gpt-3.5-turbo",
                                          messages=messages)

if  not  response.choices or len(response.choices) == 0:
    return "Sorry, unable to provide health advice at the moment. Please try again later."

output = response.choices[0].message.content
return output

Create a Flask web application object named app

app = Flask(name)

Initialize messages

messages = [{
“role”:
“system”,
“content”:
“You are a helpful assistant providing health-related advice. You need to interactively assist users with either diet plans or illness information based on their input.”
}]

@app.route(‘/’, methods=[‘GET’, ‘POST’])
def home():
global messages
user_input = “”
response = “”

if request.method == 'POST':
    user_input = request.form['query']
    messages.append({"role": "user", "content": user_input})

    if user_input.lower() == 'd':
        response = "Please provide your age, gender, weight, and height separated by commas (e.g., 25, male, 70kg, 175cm):"
    elif user_input.lower() == 'i':
        response = "What disease can I help with?"
    else:
        # Handle inputs for age, gender, weight, height for diet or disease details
        last_message = messages[-2]['content']
        if last_message.startswith("Please provide your age"):
            age, gender, weight, height = [
                x.strip() for x in user_input.split(',')
            ]
            messages.append({
                "role":
                "user",
                "content":
                f"Age: {age}, Gender: {gender}, Weight: {weight}, Height: {height}"
            })
            user_input = f"I need a diet plan for a {gender} aged {age} with a weight of {weight} and height of {height}."
        elif last_message == "What disease can I help with?":
            messages.append({
                "role": "user",
                "content": f"Disease: {user_input}"
            })

        response = generate_health_advice(messages)

    messages.append({"role": "assistant", "content": response})

return render_template_string('''<!DOCTYPE html>
Personal Health Assistant

YOUR PERSONAL HEALTH ASSISTANT

{% for message in messages %} {% if message.role == 'user' %}
You:
{{ message.content }}
{% else %}
Assistant:
{{ message.content }}
{% endif %} {% endfor %}
How may I help you?:
Submit
''', messages=messages)

Start the Flask application if the script is being run directly

if name == ‘main’:
app.run(host=‘0.0.0.0’, port=8080, debug=True)
this is the css file:body {
font-family: Arial, sans-serif;
background: url(“…/images/image.jpg”) no-repeat center center fixed;
background-size: cover;
margin: 0;
padding: 0;
color: #ffffff;
}

.container {
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: rgba(0, 0, 0, 0.7);
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

h1 {
text-align: center;
color: #ffffff;
}

form {
background: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.form-label {
font-weight: bold;
color: #ffffff;
}

.form-control {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border-radius: 4px;
border: 1px solid #ffffff;
background: rgba(255, 255, 255, 0.2);
color: #ffffff;
}

.form-control::placeholder {
color: #cccccc;
}

.btn {
display: inline-block;
font-weight: 400;
color: #ffffff;
text-align: center;
vertical-align: middle;
user-select: none;
background-color: #007bff;
border: 1px solid #007bff;
padding: 10px 20px;
font-size: 16px;
line-height: 1.5;
border-radius: 4px;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.btn-primary:hover {
background-color: #0056b3;
border-color: #004085;
}

.chat-box {
margin-top: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
}

.user-query, .assistant-response {
display: flex;
flex-direction: column;
margin-bottom: 10px;
}

.user-label, .assistant-label {
font-weight: bold;
color: #00ffcc;
}

.user-text, .assistant-text {
background: rgba(255, 255, 255, 0.2);
padding: 10px;
border-radius: 4px;
border: 1px solid #ffffff;
color: #ffffff;
}
PLEASE KINDLY HELP WITH THIS

Hi @fatakkc21.instru

Please share your Repl to support@boltiot.com. To share the Repl, click on the invite option on the top right corner in Replit and enter the email id : support@boltiot.com. I will debug the issue and provide you with the solution.

I have invited you for by prgram question as you said but , I also wasn’t cleared anything on my query i am mentioning below , my internship deadline is 26 June, so it would be great if i get your guidance.

  1. For Training completion exam, Answer any 2 forum queries on this forum page (forums.boltiot.com) and copy paste the link when you are answering the exam.

here in this point you mentioned I have already given the examination and got my certificate as well ,I wasn’t really asked to perform this task you mentioned here.

can you please guide me about this as well
2. For the internship tasks, answer any 4 forum queries on this forum page (forums.boltiot.com) and copy paste the link in the form when you submit the project.

also about answering on the forum for internship, many of the post have already been replied so am I supposed to answer the question still ,like what should I do, please kindly guide me through this

@fatakkc21.instru

We checked both your Repl’s. In the health REPL, you had one incorrect import. Also the syntax of the response object was incorrect. After making the corrections the REPL is working.

For the recipe generator, the correct API key was not present in the secrets section. After adding the correct API key and updating the variable in your code, it started work. You can RUN and check both REPLs.

Regarding your forum post query, you can reply to existing forum posts as well. Your reply can improve upon the existing replies in the thread or provide alternative solutions.

The screenshot you have attached is not visible. Kindly attach the screenshot using the attach image option while you draft the forum query. Also can you elaborate on the error you are getting?

Regarding the forum question for internship, here is how you go about it:

  1. For Training completion exam, Answer any 2 forum queries on this forum page (forums.boltiot.com ) and copy paste the link when you are answering the exam.
  2. For the internship tasks, answer any 4 forum queries on this forum page (forums.boltiot.com ) and copy paste the link in the form when you submit the project.

Do attach the screenshot and let us know if you have any more queries.