Spring Boot AI + Azure OpenAI + Function Callback Example

Also in another previous tutorial we had implemented Spring Boot + Azure OpenAI + RAG to provide reference text using vector database to openai.
We use RAG (Retrieval-Augmented Generation) for -
- Augmenting the LLM's knowledge by retrieving relevant external information before generating a response
- Helping expand the model's contextual knowledge beyond its training data
- Typically used to provide up-to-date or domain-specific information
- Focuses on improving the content and accuracy of the generated response
Video
This tutorial is explained in the below Youtube Video.We use callbacks for -
- Provide a way to intercept and modify the LLM's generation process
- Allow for real-time monitoring, logging, or modification of the model's output
- Enable additional processing or side effects during generation
Implementation
Download the source code we had implemented for Spring Boot + Azure OpenAI Hello World Example. If we start this example and ask it the question - How is Bitcoin performing today? we do not get proper response as we can see that openai does not have currect data about bitcoin.
For this first we will need to create an account for Coin Market Cap. Once account is created log in and get the api key.

We can now use coinmarketcap to get crypto real time data as follows-

Use this in the properties file as follows-
azure.openai.api.key=66T7YqY4CaqXB9fdfdfD6q1RTz9p45goTXeVAJPpWKERdclRxRLgJQQJ99BBACYeBjFXJ3w3AAABACOGmCSx azure.openai.endpoint=https://javainuse-service.openai.azure.com/ azure.openai.deployment.model.id=gpt-4o azure.openai.embedding.model.id=text-embedding-3-small coinmarketcap.api.key=5a5537c70-t7ac-4b40-a8da-1fb7dsdsdbc3458