scrimba
Learn AI Agents
Build action functions
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Build action functions
AboutCommentsNotes
Build action functions
Expand for more info
index.js
run
preview
console
import OpenAI from "openai"

export const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
dangerouslyAllowBrowser: true
})

/**
* Goal - build an agent that can get the current weather at my current location
* and give me some localized ideas of activities I can do.
*/

const response = await openai.chat.completions.create({
model: "gpt-4",
messages: [
{
role: "user",
content: "Give me a list of activity ideas based on my current location and weather"
}
]
})

console.log(response.choices[0].message.content)
// As an AI, I'm unable to access your current location or weather details...
Console
/index.html
-3:36