If you want to use OpenAI models with Oracle databases then Oracle Select AI makes it a breeze to do so. Provided you already have an Oracle autonomous database in OCI, you can use following steps to use OpenAI's model to use natural language to query you database with LLMs from OpenAI.
Oracle Autonomous Database Select AI is a powerful tool that enables you to leverage AI capabilities directly within your database environment, and OpenAI is a leading AI model provider. Also, as OpenAI is a paid option, so you would need to grab your OpenAI's API key from platform.openai.com. By default, Oracle Select AI uses gpt-3.5-turbo (default) from OpenAI but you can select any model from below list:
- gpt-3.5-turbo (default)
- gpt-4o
- gpt-4o-mini
- gpt-4
- gpt-4-0613
- gpt-4-32k
- gpt-4-32k-0613
- gpt-3.5-turbo-0613
- gpt-3.5-turbo-16k
- gpt-3.5-turbo-16k-0613
Lets first create a user:
--
CREATE USER SCOTT IDENTIFIED BY "SelectAI25#TEST";
GRANT RESOURCE TO SCOTT;
GRANT CREATE SESSION TO SCOTT;
GRANT CREATE VIEW TO SCOTT;
GRANT CREATE TABLE TO SCOTT;
GRANT CONNECT TO SCOTT;
--Grants EXECUTE privilege to SCOTT
--
SQL> grant execute on DBMS_CLOUD_AI to SCOTT;
-- Grant Network ACL for OpenAI endpoint
--
SQL> BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'api.openai.com',
ace => xs$ace_type(privilege_list => xs$name_list('http'),
principal_name => 'SCOTT',
principal_type => xs_acl.ptype_db)
);
END;
/
--
-- Create Credential for AI provider
--
EXEC
DBMS_CLOUD.CREATE_CREDENTIAL(
CREDENTIAL_NAME => 'OPENAI_CRED',
username => 'OPENAI',
password => '<OPENAI_API_KEY>');
--
-- Create AI profile
--
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'OPENAI',
attributes =>'{"provider": "openai",
"credential_name": "OPENAI_CRED",
"object_list": [{"owner": "SCOTT", "name": "MYTABLE"},
"conversation": "true"
}');
END;
/
--
-- Enable AI profile in current session
--
SQL> EXEC DBMS_CLOUD_AI.SET_PROFILE('OPENAI');
--
-- Use Select AI
--
SQL> select ai how many rows exist in table;
SQL> select ai how many users in Jakarta are jobless;
-- You can also show the actual SQL with the result:
SQL> select ai showsql how many users in Jakarta are jobless;
No comments:
Post a Comment