Disclaimer: Before diving into the exciting world of AI-driven apps, it's crucial to note the importance of having a minimal backend setup in production environments. This approach is not only a best practice for maintaining security but also essential to safeguard your API keys from being exposed to clients.
As a developer with a penchant for culinary adventures, I have always been fascinated by the intersection of technology and cooking. This interest led me to experiment with an application I affectionately named "AI Chef". The core idea was simple yet ambitious: create an app that generates unique recipes based on user-inputted ingredients. The realization of this idea, however, was anything but simple.
The game-changer for AI Chef was the introduction of the Function Calling feature in ChatGPT on July 20, 2023. This feature allowed me to structure the API responses in highly specific ways, tailoring the AI's output to fit the unique needs of my app. Imagine inputting ingredients like chicken, basil, and tomatoes, and receiving a detailed recipe for a delicious Tuscan Chicken Skillet - all curated by AI.
Here is a glimpse into the technical magic behind AI Chef:
const completion = await openai.chat.completions.create({ messages: [ { role: 'system', content: SYSTEM__PROMPT__START }, { role: 'user', content: USER__PROMPT__INGREDIENTS } ], model: 'gpt-3.5-turbo-0613', functions: [ { name: 'get_recipes', description: 'Suggest at least 5 recipes based on the ingredients you have', parameters: { type: "object", properties: { recipes: { type: "array", description: "The recipes that can be made with the ingredients", items: { type: 'object', properties: { name: { type: 'string', description: 'The name of the recipe', }, ingredients: { type: 'array', description: 'The ingredients needed for the recipe', items: { type: 'string', description: 'The name of the ingredient', }, }, instructions: { type: 'string', description: 'Detailed instructions on how to make the recipe', }, serving: { type: 'string', description: 'The number of people the recipe serves', }, } } }, } }, required: ["recipes"], }, ], function_call: { name: 'get_recipes' }, });
This code snippet demonstrates the integration of ChatGPT's Function Calling feature into AI Chef. By defining a custom function get_recipes, the app leverages AI to suggest at least five recipes based on the inputted ingredients, complete with names, ingredients, instructions, and servings.
Implementing ChatGPT as the backend of AI Chef came with its set of challenges, though. The most notable was the response time. While the AI's ability to generate recipes was impressive, the wait time for these responses sometimes tested the patience of users. As an experimental app, this was an acceptable trade-off, but it highlighted the need for optimization in real-world applications.
Despite these hurdles, the journey of building AI Chef has been incredibly rewarding. It's a testament to the potential of AI in creative domains like cooking. The Function Calling feature of ChatGPT not only made this possible but also opened up a plethora of opportunities for developers to explore new horizons in app development.
In conclusion, AI Chef might be a small step in the vast landscape of AI applications, but it represents a giant leap in how we perceive and utilize AI in our daily lives. It's a vivid example of how a simple idea, backed by powerful technology like ChatGPT, can lead to deliciously innovative outcomes.