Basically you declare to the AI which functions (tools) are available for it to call: https://platform.openai.com/docs/guides/function-calling?api...
Then you handle those function calls in your javascript.
```
if (function_name === 'search_recipes') {
const searchParams = new URLSearchParams();
if (args.name) searchParams.set('name', args.name);
if (args.difficulty) searchParams.set('difficulty', formatDifficulty(args.difficulty));
if (args.min_duration) searchParams.set('minDuration', args.min_duration.toString());
if (args.max_duration) searchParams.set('maxDuration', args.max_duration.toString());
if (args.tag) searchParams.set('tag', args.tag);
// Handle ingredients array correctly - the search page expects ingredients[]
if (args.ingredients && args.ingredients.length > 0) {
// Clear any existing ingredients
searchParams.delete('ingredients[]');
// Add each ingredient individually with the correct array notation
args.ingredients.forEach((ingredient: string) => {
searchParams.append('ingredients[]', ingredient);
});
}
const queryString = searchParams.toString();
const url = queryString ? `/search?${queryString}` : '/search';
navigate(url);
return;
}
// start_cooking function
if (function_name === 'start_cooking') {
// First check if we have an onStartCooking callback registered
if (callbacksRef.current.onStartCooking) {
callbacksRef.current.onStartCooking();
return;
}
}
```