So maybe you guessed it from the topic. I am really into wine and I like pairing food and wine, but there are literally millions of possibilities from various regions and countries, France, Spain, Italy, you name it. So finding the right pairing can be really challenging. But we can build a really simple, hopefully smart, digital sommelier that helps us with finding that perfect pairing.
So let's do that in the next five minutes with the Resell AI SDK and the OpenAI API. So we'll start with a really simple UI. I'm not lying if I tell you that this took the longest to put together. So we have two columns, there is a menu on the left, so the food, and there is a wine list on the right to pair with the food. And on the bottom, you have a small form, a text area where you can add new dishes to the menu.
If you look at the code, it's really simple. We make use of the use chat hook provided by the Resell AI SDK, and it gives us a set of helper functions to interact with large language models. So it does all the heavy lifting, there's not much we need to do here. And we have the form itself, which uses some of these helper functions to send the data off to an API road. That is also actually quite simple. On the server, we have three things, we initiate a client to interact with the OpenAI API, we specify the model. In this case, it's GPT 3.5 TORGO. We provide our OpenAI API key. Unfortunately, it's not free. And that's it.
We read the form data from the request, so the dish in this case we want to pair a wine with, and we send it off to the OpenAI API. What we get back is a streaming response, or a response that we turn into a readable screen that we send back to the client. And here, there's not a lot more to it. Again, we use chat hook to render this streaming response on the screen. And that gives us that nice effect that looks like the AI is actually typing the response. Probably if you use chat GPT, you've seen it before. And that's really all there is to it. Maybe a hundred lines of code. But I think it's a good showcase of what you can do really quickly with open source tools. But let's see if that actually works. So I prepared a little example.
Comments