AI SMS Outfit Recs with OpenMeteo
Today we will be making a fun script to text us a nice recommendation for outfits based on the weather every morning. It will look something like this at the end:
- Check the weather using the free OpenMeteo API
- Pass the weather info to Telnyx Inference using the model of our choice
- Send the recommendation to the user using Telnyx SMS
Checking the weather with OpenMeteo
OpenMeteo is a great free API that allows you to retrieve the forecast for the current day. They have a ton of options for what you can retrieve, but for this demo, we will stick with just the temperature and weather code (although feel free to experiment with other things like humidity!). The following functions can be used to retrieve a weather_description that we can feed into our Telnyx Inference model:Getting our recommendation text from Telnyx Inference Meta-Llama-3.1-8B
Now that we have the current weather, let’s make a call to Telnyx Inference to generate a text to send to our user. There are many state-of-the-art open source models available through the Telnyx API, so for this one we will select a powerful small model: Meta’s Llama-3.1-8B-Instruct. Let’s write a function to retrieve a good weather recommendation from Telnyx Inference. We will just use therequests library to not add an additional pip requirement, but the Telnyx LLM API is also compatible with the OpenAI Python and JS SDKs, see the OpenAI Migration Guide Here.
TELNYX_API_KEY is set in your environment variables so that they can be loaded with os.getenv(‘TELNYX_API_KEY’). The API spec for chat completions can be found here if you would prefer to use HTTP requests instead of the OpenAI client or want to play around with some of the LLM parameters offered.
The output of this function will be a string with our recommendation, for example:
“Good morning. Perfect day ahead. Why not try a light, pastel-colored short-sleeved shirt, paired with some beige or light-gray shorts? Add some loafers or sneakers, and you’re all set for a sunny day. Have a great one!”
Sending our text to the user
Great! Now that we have our weather and text recommendation, we can send the text to the user. Sending a message with Telnyx SMS is easy, follow the tutorial here if you have not set up a Telnyx number yet. We can use the following snippet to send a text using Telnyx:Putting it all together
Now that we have all the pieces in place, let’s run the script! We can use the following sequence to chain everything together:cronjob or the task scheduler of your choice. Thanks for following along!