Oracle APEX and Cohere: Configure Generative AI Service for Smarter Apps


Before using AI-assisted development or creating AI-powered smart apps in APEX, the first step is to configure the Generative AI service in Oracle APEX to choose an AI provider. Generative AI Services simplifies the Oracle APEX integration with the popular commercial Generative AI providers.
Starting with Oracle APEX 24.1, there is built-in support for three AI providers: OCI Generative AI Service, OpenAI, and Cohere. These options are available by default, allowing you to seamlessly configure and leverage AI capabilities within your applications.
In this article, I'll walk you through the steps to use Cohere AI service as the AI provider in Oracle APEX. This will enable AI-assisted development within the APEX builder to create smart AI applications.
Step 1: Generate Cohere API key.
To configure the Cohere AI service, you need to generate an API key.
Go to the Cohere Dashboard and log in to your account. Once logged in, navigate to the API keys section and click on + New Trial Key.
In the popup that appears, enter a name for the key and click on Generate Trial Key. A new trial key will be generated. Copy this key, as you will need it to create web credentials in APEX.
Step 2: Create Web Credentials
Web credentials in Oracle APEX are used to authenticate connection to external REST services, or REST Enabled SQL services from APEX. Creating Web Credentials securely stores and encrypts authentication credentials for use by Oracle APEX components and APIs. Credentials cannot be retrieved back in clear text. Credentials are stored at the workspace level and therefore are visible to all applications.
To create a Web Credential in Oracle APEX:
From the App Builder, navigate to App Builder > Workspace Utilities > All Workspace Utilities
Select Web Credentials.
Click Create.
Enter the Web Credential Information:
Fill out the fields as shown:
Name: Cohere AI Credentials.
Static ID: COHERE_AI_CRED.
Authentication Type: Select HTTP Header.
Credential Name: Enter Authorization (this is the header that Cohere’s API expects).
Credential Secret:
The Credential Secret should be entered as 'Bearer <Cohere API Key>'. Remember to include a space after the word Bearer and before the token.
For example: Bearer 4f3c2b1a5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c
- Click Create.
Step 3: Create Generative AI Service
From the App Builder, navigate to App Builder > Workspace Utilities > All Workspace Utilities
Select Generative AI.
Click Create to configure a Generative AI Service.
Enter the Generative AI Service Information:
Fill out the fields as shown:
AI Provider: Select Cohere from dropdown
Name: Cohere Gen AI
Static ID: COHERE_GEN_AI
Used by App Builder: Turn the toggle button to ON to use this AI service as an AI provider in the APEX builder for AI-Assisted development.
- Note: You can create as many Generative AI services as you want in APEX, but only one API service can be enabled for use by the App Builder.
Base URL: https://api.cohere.ai/v1
- This is autogenerate field.
Credential: Select “COHERE_AI_CRED” from the dropdown we created in the previous step.
AI Model: command-r-08-2024
The models provided by the AI service provider may change over time. To learn more about all the currently available models in Cohere, check this documentation.
In APEX 24.2, a new feature allows you to test the connection directly from the builder. After filling out all the fields, click on Test Connection. If everything is set up correctly, you will see the "Connection Succeeded" message.
If you encounter a Network ACL error, you need to create a Network ACL for the Cohere API. Execute the code below using your database admin user.
BEGIN dbms_network_acl_admin.append_host_ace( host => 'api.cohere.ai', ace => xs$ace_type(privilege_list => xs$name_list('http'), principal_name => '<Your Schema>', principal_type => xs_acl.ptype_db) ); END;
Conclusion
By following the steps in this guide, you can easily set up Cohere as your AI provider. This will enable AI-assisted development within the APEX builder and help you create smarter, AI-powered apps.
Subscribe to my newsletter
Read articles from Rutvik Prajapati directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
