I am taking the Intro to AI Engineering course.
I set up and triple-checked my ENV variables. All are correct.
Nothing happens in the console when I try to run.
I attached screenshots of my setup.
Even more annoyingly, the run buttons circles green and then greys out. Nothing appears in console.
I tried this on Chrome.
PLease help.
(import OpenAI from "openai"
import { checkEnvironment } from "./utils.js"
const openai = new OpenAI({
apiKey: process.env.AI_KEY,
baseURL: process.env.AI_URL,
dangerouslyAllowBrowser: true
})
checkEnvironment();
/**
- Challenge: Modify the prompt
- Run the code, then update the prompt so the AI suggests gifts for:
-
- you, or
-
- someone you actually know
- Run it again and observe how the output changes.
*/
const prompt = "give me some basic gift ideas for me as a runner";
console.log("Prompt:", prompt);
console.log("Making AI request...");
try {
const response = await openai.chat.completions.create({
model: process.env.AI_MODEL,
messages: [
{
role: "user",
content: prompt,
},
],
});
console.log("AI response:");
console.log(response.choices[0].message.content);
} catch (error) {
if (error.status === 401 || error.status === 403) {
console.error(
"Authentication error: Check your AI_KEY and make sure it’s valid."
);
} else if (error.status >= 500) {
console.error(
"AI provider error: Something went wrong on the provider side. Try again shortly."
);
} else {
console.error(
"Unexpected error:",
error.message || error
);
}
}
)