scrimba
AI Engineering
AI Agents
OpenAI Functions Agent - Part 8 - Adding arguments
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

OpenAI Functions Agent - Part 8 - Adding arguments
AboutCommentsNotes
OpenAI Functions Agent - Part 8 - Adding arguments
Expand for more info
tools.js
run
preview
console
export async function getCurrentWeather() {
const weather = {
temperature: "75",
unit: "F",
forecast: "sunny"
}
return JSON.stringify(weather)
}

export async function getLocation() {
return "San Diego, CA"
}

export const tools = [
{
type: "function",
function: {
name: "getCurrentWeather",
description: "Get the current weather",
parameters: {
type: "object",
properties: {}
}
}
},
{
type: "function",
function: {
name: "getLocation",
description: "Get the user's current location",
parameters: {
type: "object",
properties: {}
}
}
},
]
Console
"Iteration #1"
,
{index:
0
, message:
{role:
"assistant"
, content:
null
, tool_calls:
[
{id:
"call_bnKaiRx2Brt1SIEAVenGtZeC"
, type:
"function"
, function:
{name:
"getCurrentWeather"
, arguments:
"{"city": "Tokyo"}"
}
}
,
{id:
"call_YoZodKHKmMdxWM5VWOXXbzYi"
, type:
"function"
, function:
{name:
"getCurrentWeather"
, arguments:
"{"city": "New York City"}"
}
}
,
{id:
"call_jExY4kQqWaYUjJfqeJxz8fsw"
, type:
"function"
, function:
{name:
"getCurrentWeather"
, arguments:
"{"city": "Oslo"}"
}
}
]
}
, finish_reason:
"tool_calls"
}
,
"{"temperature":"75","unit":"F","forecast":"sunny"}"
,
"{"temperature":"75","unit":"F","forecast":"sunny"}"
,
"{"temperature":"75","unit":"F","forecast":"sunny"}"
,
"Iteration #2"
,
{index:
0
, message:
{role:
"assistant"
, content:
"The current weather in Tokyo, New York City, and Oslo is as follows: - Tokyo: 75°F, sunny - New York City: 75°F, sunny - Oslo: 75°F, sunny"
}
, finish_reason:
"stop"
}
,
"The current weather in Tokyo, New York City, and Oslo is as follows: - Tokyo: 75°F, sunny - New York City: 75°F, sunny - Oslo: 75°F, sunny"
,
"AGENT ENDING"
,
/index.html
-6:49