I’ve been experimenting with Spring AI to see how what it can do for Spring applications.
Here is a simple demo that uses Spring AI, OpenAI and OpenWeather to look up weather conditions for a city using a natural language prompt.
You can give it a query like
What’s the weather like in Rome today?
and it will return with a result, in JSON format, like this:
{"main":{"temp":23.67,"feels_like":24.16,"temp_min":22.49,"temp_max":24.31,"pressure":1019,
"humidity":79,"sea_level":1019,"grnd_level":992},
"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"name":"Rome"}
The code is here
Note despite the repo name this is not a model context protocol server - yet.
There are 2 key parts:
- an OpenWeather client
- a ChatClient
The first of these is a standard REST API call to OpenWeather, given a city name.
The ChatClient is of most interest here, it is the primary interface to whatever AI provider you are using (in this case OpenAI).
You can see that with such little code it is straightfoward to include AI support in your Spring apps.