Develop an AI Chatbot App in 5 minutes with APEX 24.1
Oracle recently released the latest APEX, version 24.1, with a focus on AI capabilities. It is now really simple to add a chatbot to your application that allows you to interact with data through natural language, in the context of your application and your data!
Moreover, you can leverage the same AI capabilities as a (citizen) developer to construct the SQL queries of your APEX application when building new applications, so no need for expert SQL knowledge to build engaging applications.
How to get started?
The easiest way is to obtain a free APEX workspace and then run through the ”Build an Innovative Q&A Interface” LiveLab. This will provide you a 24.1 version out of the box, but of course you can also download the latest APEX version and install it on your preferred environment, or get a free Oracle Cloud account where you can spin up an APEX environment.
One requirement for this LiveLab is to have an account on either Oracle OCI, OpenAI or Cohere with access to GenAI capabilities. The LiveLab describes the steps to use OpenAI, but I used my OCI account and that works just as well, only the authentication parameters are different.
In the setup described above your APEX environment is running at Oracle, but of course the described functionalities are available in any APEX environment, either in an on-premises or Cloud deployment. The only requirement is access to the URL of your chosen GenAI provider.
Walking through the Lab
In the Q& A lab I referred you to, you’ll walk through a series of steps, but actually you can take a few shortcuts to dive straight into the AI part.
In “Lab1: Create an APEX App” you will download an example data set containing a few hundred high-schools around New York. Based on this data it is easy to generate an vanilla APEX App, and beautify it a bit as described in the lab. As a result, you’ll have a “Cards” type of presentation of the data. You need to execute this step completely.
“Lab 2: Visualize Schools on a Map” is all about presenting these schools on a map. Although this is a pretty nice example of representing Geo data, this is unrelated to the AI functionality, so feel free to skip this step and advance directly to Lab 3.
So let’s focus on “Step3: Build a Conversational Inquiry using Generative AI”, where we’ll actually build the chatbot to interact with our data!
In Task 1 of the lab you’ll connect the APEX instance to your chosen GenAI service provider. If you prefer using the OCI service instead of OpenAI, you’ll select “OCI Generative AI Service” as the AI provider, and you’ll have to provide a series of parameters to authenticate as you can see in the picture below:
- Compartment ID, User ID and Tenancy ID
- Region — Frankfurt and UK South are now available!
- OCI Private Key & corresponding Public key Fingerprint
Also make sure to toggle “On” the “Used by App Builder” in order to be able to use the SQL Query Assistant as an App Builder.
Next you’ll add an extra button to the Cards interface to look at extra info on a specific school, using the chat interface. You do this through an Action with Action type “Open AI Assistant”. You can see some of the basic prompt engineering that is done in order to control the result of the user chat, with for example the instruction to respond with “Information not Found” if the question is not related to the actual data in the context information.
This is where you should experiment and make sure you adapt your prompt to be in line with the expected business behaviour of your application !
At the end of Lab 3 be sure to run the application and observe the result: a functioning chat window, answering questions on a specific school that you have selected:
And voila ! You have created an actual AI contextual chatbot in 5 minutes flat!
Using the APEX Assistant
Instead of continuing the sequence of the lab, I would suggest the next thing to try is the APEX Code assistant, helping you to formulate SQL queries to base screens and reports on. As an example I created a new page in my application, selected the “Highschools” table as a source, and then switched the source from Table to SQL Query.
Once in the Code Editor, you can activate the APEX Assistant, either in “General Assistance” mode or in “Query Builder” mode. You can then ask textual questions, for example to only select schools that have the text “Compute” in their name — this will generate a suggestion that you can simply copy over to your actual code.
As you can see you might have to do some follow-up tuning, for example to make the query case-independent — just ask for it, the chat will maintain the context:
Conclusions
So you’ve seen the 2 major AI use-cases of APEX in this short experiment:
- Implement a chatbot that is part of your application, leveraging the in-context data you are managing in the application. Combining this with the Database 23ai Vector search I described in my previous article allows you even more powerful applications!
- Leverage the Code Assistant inside of APEX to build SQL queries, allowing a broader population to do more with APEX.
Stay tuned for more experiments with Oracle AI technology.