Hello,
The example provided for (Complete tool calling example) under javascript has errors in this link https://platform.openai.com/docs/guides/function-calling
This is the correct code
```
// 1. Define a list of callable tools for the model
const tools = [
{
type: “function”,
name: “get_horoscope”,
description: “Get today’s horoscope for an astrological sign.”,
parameters: {
type: “object”,
properties: {
sign: {
type: “string”,
description: “An astrological sign like Taurus or Aquarius”,
},
},
required: [“sign”],
},
},
];
function get_horoscope(sign) {
return sign + " Next Tuesday you will befriend a baby otter.";
}
// Create a running input list we will add to over time
let input = [
{ role: "user", content: "What is my horoscope? I am an Aquarius." },
];
// 2. Prompt the model with tools defined
let response = await openai.responses.create({
model: “gpt-5”,
tools,
input,
});
console.log(response.output)
input.push(…response.output)
response.output.forEach((item) => {
if (item.type == “function_call”) {
if (item.name == “get_horoscope”){
console.log(JSON.parse(item.arguments).sign)
// 3. Execute the function logic for get_horoscope
const horoscope = get_horoscope(JSON.parse(item.arguments).sign)
// 4. Provide function call results to the model
input.push({
type: “function_call_output”,
call_id: item.call_id,
output: horoscope
})
}
}
});
console.log(“Final input:”);
console.log(JSON.stringify(input, null, 2));
response = await openai.responses.create({
model: “gpt-5”,
instructions: “Respond only with a horoscope generated by a tool.”,
tools,
input,
});
// 5. The model should be able to give a response!
console.log(“Final output:”);
console.log(JSON.stringify(response.output, null, 2));
```