I've changed the OpenAiChatClient to support function calling (in addition to plain queries) and have added a test that calls my custom library of functions (potentially private). There's a test also that answers this query:

Message systemMessage = new SystemMessage(
        "I live in the US, so use the units of temperature and currency that are applicable for Americans.");
UserMessage userMessage = new UserMessage("I love playing golf when it's not too cold or hot. I live in Pittsburgh, PA and can travel anywhere in the country to play. Where should I go where it is pleasant and economical based on airfares?");

Here's a sample output that is returned in one invocation:

14:13:36.770 [main] DEBUG o.s.a.o.m.support.MyFunctionService - Calling getWeatherForLocation with location Pittsburgh, PA
14:14:06.019 [main] DEBUG o.s.ai.openai.OpenAiChatClient - Response: Since you love playing golf in pleasant weather and you're currently in Pittsburgh where it's 60°F and cloudy, let's find a destination with similar or slightly warmer temperatures and clear skies. Additionally, we will consider the airfares to ensure the destination is economical. I will find a few different destinations with their current weather and airfare prices from Pittsburgh, so you can choose where to go. One moment while I gather this information.
14:14:06.019 [main] DEBUG o.s.a.o.m.support.MyFunctionService - Calling getWeatherForLocation with location Orlando, FL
14:14:06.019 [main] DEBUG o.s.a.o.m.support.MyFunctionService - Calling getWeatherForLocation with location Phoenix, AZ
14:14:06.019 [main] DEBUG o.s.a.o.m.support.MyFunctionService - Calling getWeatherForLocation with location San Diego, CA
14:14:06.019 [main] DEBUG o.s.a.o.m.support.MyFunctionService - Calling getAirfareForLocation with destination Orlando, FL
14:14:06.019 [main] DEBUG o.s.a.o.m.support.MyFunctionService - Calling getAirfareForLocation with destination Phoenix, AZ
14:14:06.020 [main] DEBUG o.s.a.o.m.support.MyFunctionService - Calling getAirfareForLocation with destination San Diego, CA
14:14:15.132 [main] DEBUG o.s.ai.openai.OpenAiChatClient - Response: Based on the current weather and airfares, here are your options for a pleasant and economical golf trip:

1. Orlando, FL: The weather is sunny with a temperature of 75°F, which is ideal for playing golf. The airfare from Pittsburgh, PA to Orlando is $300 USD.

2. Phoenix, AZ: The weather is also sunny with a temperature of 78°F, very suitable for a day on the green. The airfare for this destination is $305 USD.

3. San Diego, CA: Although the weather is gloomy with a temperature of 40°F, which might not be as pleasant for golfing, the airfare is the most economical at $150 USD.

Considering both weather and airfare, Orlando, FL and Phoenix, AZ offer the best conditions for golf, with Orlando being slightly cooler. San Diego, CA has the lowest airfare but the weather might not be as conducive for golfing. Depending on your preference for slightly cooler or warmer sunny weather, you should choose between Orlando and Phoenix.
14:14:15.141 [main] DEBUG o.s.a.openai.chat.OpenAiChatClientIT - Final Answer: {
  "metadata" : {
    "contentFilterMetadata" : null,
    "finishReason" : "STOP"
  },
  "output" : {
    "content" : "Based on the current weather and airfares, here are your options for a pleasant and economical golf trip:\n\n1. Orlando, FL: The weather is sunny with a temperature of 75°F, which is ideal for playing golf. The airfare from Pittsburgh, PA to Orlando is $300 USD.\n\n2. Phoenix, AZ: The weather is also sunny with a temperature of 78°F, very suitable for a day on the green. The airfare for this destination is $305 USD.\n\n3. San Diego, CA: Although the weather is gloomy with a temperature of 40°F, which might not be as pleasant for golfing, the airfare is the most economical at $150 USD.\n\nConsidering both weather and airfare, Orlando, FL and Phoenix, AZ offer the best conditions for golf, with Orlando being slightly cooler. San Diego, CA has the lowest airfare but the weather might not be as conducive for golfing. Depending on your preference for slightly cooler or warmer sunny weather, you should choose between Orlando and Phoenix.",
    "properties" : {
      "role" : "ASSISTANT"
    },
    "messageType" : "ASSISTANT"
  }
}

Comment From: markpollack

Hi, I appreciate the PR. This was a topic that we also had some implementations for and just pushed that into main branch for the upcoming 0.8.0 release. Please check out that PR and offer any comments based on your experience or another PR that improves it in some areas. Sorry, that I can't just 'merge' this, but I really do appreciate the effort. See https://docs.spring.io/spring-ai/reference/api/clients/functions/openai-chat-functions.html for more information.

Comment From: pankajtandon

Thank you @markpollack I can totally understand your hesitation! The work that has been done especially around FunctionCallbackWrapper is top notch and much superior to what I had put out! I did end up using the current classes and created https://github.com/pankajtandon/vacationplanner It's amazing how little I had to write to get it to work!

Thank you!