Skip to content

Commit 3e92546

Browse files
committed
init
1 parent 256e6d5 commit 3e92546

17 files changed

+452
-412
lines changed

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/bin/bash
22

3+
source env.properties
4+
35
mvn clean package

env.properties

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
#export OPENAI_KEY="mykeyvalue"
66
#export OCICONFIG_FILE=~/.oci/config
77
#export OCICONFIG_PROFILE=DEFAULT
8+
#only set region to override the default found in OCI config, eg if using a feature only avaiable in a certain region
9+
#export REGION="US_CHICAGO_1"
810
#export COMPARTMENT_ID="ocid1.compartment.oc1..mycompartmentvalue"
911
#export OBJECTSTORAGE_NAMESPACE="myobjectstorenamespacename"
1012
#export OBJECTSTORAGE_BUCKETNAME="myobjectstorebucketname"
1113
#export ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE="myordsendpoint"
12-
#export ORDS_ENDPOINT_ANALYZE_IMAGE_INLINE="myordsendpoint"
13-
#export OCI_VISION_SERVICE_ENDPOINT="https://vision.aiservice.us-ashburn-1.oci.oraclecloud.com"
14+
#export ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL="myordsendpoint"
15+
#export OCI_VISION_SERVICE_ENDPOINT="https://vision.aiservice.us-chicago-1.oci.oraclecloud.com"
1416

1517
## The following are only applicable when using Kubernetes...
1618
#export KUBECONFIG=~/.kube/config-mykubeconfig
17-
#export DOCKER_REGISTRY=us-ashburn-1.ocir.io/myocirnamespacename/myocirfolder
19+
#export DOCKER_REGISTRY=us-myregion-1.ocir.io/myocirnamespacename/myocirfolder
20+

run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
source env.properties
4+
5+
mvn clean package ; java -jar target/oracleai-0.0.1-SNAPSHOT.jar
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
create or replace FUNCTION call_analyze_audio_api_objectstore (
2+
p_endpoint VARCHAR2,
3+
p_compartment_ocid VARCHAR2,
4+
p_namespaceName VARCHAR2,
5+
p_bucketName VARCHAR2,
6+
p_objectName VARCHAR2,
7+
p_featureType VARCHAR2,
8+
p_label VARCHAR2
9+
) RETURN CLOB IS
10+
resp DBMS_CLOUD_TYPES.resp;
11+
json_response CLOB;
12+
BEGIN
13+
resp := DBMS_CLOUD.send_request(
14+
credential_name => 'OCI_KEY_CRED',
15+
uri => p_endpoint || '/20220125/actions/analyzeImage',
16+
method => 'POST',
17+
body => UTL_RAW.cast_to_raw(
18+
JSON_OBJECT(
19+
'features' VALUE JSON_ARRAY(
20+
JSON_OBJECT('featureType' VALUE p_featureType)
21+
),
22+
'image' VALUE JSON_OBJECT(
23+
'source' VALUE 'OBJECT_STORAGE',
24+
'namespaceName' VALUE p_namespaceName,
25+
'bucketName' VALUE p_bucketName,
26+
'objectName' VALUE p_objectName
27+
),
28+
'compartmentId' VALUE p_compartment_ocid
29+
)
30+
)
31+
);
32+
33+
json_response := DBMS_CLOUD.get_response_text(resp);
34+
dbms_output.put_line('json_response: ' || json_response);
35+
INSERT INTO aispeech_results VALUES (SYS_GUID(), SYSTIMESTAMP, p_label, json_response );
36+
RETURN json_response;
37+
EXCEPTION
38+
WHEN OTHERS THEN
39+
-- Handle exceptions if needed and return an error message or raise
40+
RAISE;
41+
END call_analyze_audio_api_objectstore;
42+
/
43+
44+
BEGIN
45+
ORDS.ENABLE_OBJECT(
46+
P_ENABLED => TRUE,
47+
P_SCHEMA => 'AIUSER',
48+
P_OBJECT => 'CALL_ANALYZE_AUDIO_API_OBJECTSTORE',
49+
P_OBJECT_TYPE => 'FUNCTION',
50+
P_OBJECT_ALIAS => 'call_analyze_audio_api_objectstore',
51+
P_AUTO_REST_AUTH => FALSE
52+
);
53+
COMMIT;
54+
END;

sql/dbms_sendrequest_visionai_call_objectstore_function.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ create or replace FUNCTION call_analyze_image_api_objectstore (
44
p_namespaceName VARCHAR2,
55
p_bucketName VARCHAR2,
66
p_objectName VARCHAR2,
7+
p_featureType VARCHAR2,
78
p_label VARCHAR2
89
) RETURN CLOB IS
910
resp DBMS_CLOUD_TYPES.resp;
@@ -16,7 +17,7 @@ BEGIN
1617
body => UTL_RAW.cast_to_raw(
1718
JSON_OBJECT(
1819
'features' VALUE JSON_ARRAY(
19-
JSON_OBJECT('featureType' VALUE 'OBJECT_DETECTION')
20+
JSON_OBJECT('featureType' VALUE p_featureType)
2021
),
2122
'image' VALUE JSON_OBJECT(
2223
'source' VALUE 'OBJECT_STORAGE',
@@ -28,9 +29,8 @@ BEGIN
2829
)
2930
)
3031
);
31-
3232
json_response := DBMS_CLOUD.get_response_text(resp);
33-
dbms_output.put_line('json_response: ' || json_response);
33+
-- dbms_output.put_line('json_response: ' || json_response);
3434
INSERT INTO aivision_results VALUES (SYS_GUID(), SYSTIMESTAMP, p_label, json_response );
3535
RETURN json_response;
3636
EXCEPTION

sql/setup.sql

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,49 +34,21 @@ EXCEPTION
3434
END execute_dynamic_sql;
3535
/
3636

37-
38-
select * from aispeech_results_json
39-
40-
--CONTAINS operator
41-
select * from aispeech_results_json
42-
where contains ( jsondata, 'john' ) > 0
43-
44-
--Mixed Queries
45-
select * from aispeech_results_json
46-
where amount < 100
47-
and contains ( jsondata, 'smith' ) > 0
48-
49-
--An OR search
50-
select * from aispeech_results_json
51-
where contains ( jsondata, 'john OR johnny' ) > 0
52-
53-
--Wildcards (% matches any string of characters, and an underscore _ character matches any single character)
54-
select * from aispeech_results_json
55-
where contains ( jsondata, 'john%' ) > 0
56-
57-
--Phrase searches (an AND search similar to OR but implicit)
58-
select * from aispeech_results_json
59-
where contains ( jsondata, 'first order' ) > 0
60-
61-
--Fuzzy searches (find not only the original search word, but also all those similar to it)
62-
select * from aispeech_results_json
63-
where contains ( jsondata, 'fuzzy(popins)' ) > 0
64-
65-
--Near searches (words within specified distance of each other)
66-
select * from aispeech_results_json
67-
where contains ( jsondata, 'near((order, smith), 1)' ) > 0
37+
BEGIN
38+
ORDS.ENABLE_OBJECT(
39+
P_ENABLED => TRUE,
40+
P_SCHEMA => 'AIUSER',
41+
P_OBJECT => 'EXECUTE_DYNAMIC_SQL',
42+
P_OBJECT_TYPE => 'FUNCTION',
43+
P_OBJECT_ALIAS => 'EXECUTE_DYNAMIC_SQL',
44+
P_AUTO_REST_AUTH => FALSE
45+
);
46+
COMMIT;
47+
END;
6848

6949
--Easy Text Search over Multiple Tables and Views with DBMS_SEARCH in 23c
7050
--workshop: https://apexapps.oracle.com/pls/apex/r/dbpm/livelabs/view-workshop?wid=3721
7151

72-
--CREATE TABLE image_storage (
73-
-- image_id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
74-
-- image_name VARCHAR2(255),
75-
-- image_data BLOB,
76-
-- image_description VARCHAR2(1000),
77-
-- uploaded_on DATE DEFAULT SYSDATE
78-
--);
79-
8052
BEGIN
8153
dbms_cloud.create_credential (
8254
credential_name => 'OCI_KEY_CRED',
@@ -85,4 +57,7 @@ dbms_cloud.create_credential (
8557
private_key => '[yourprivatekey you can read this from file or put the contents of your pem without header, footer, and line wraps]'
8658
fingerprint => '[7f:yourfingerprint]'
8759
);
88-
END;
60+
END;
61+
62+
https://rddainsuh6u1okc-gd740878851.adb.us-ashburn-1.oraclecloudapps.com/ords/aiuser/call_analyze_image_api_objectstore
63+
https://rddainsuh6u1okc-gd740878851.adb.us-ashburn-1.oraclecloudapps.com/ords/aiuser/call_analyze_image_api_objectstore

src/main/java/oracleai/AIApplication.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ public class AIApplication {
1111
public static final String OBJECTSTORAGE_BUCKETNAME = System.getenv("OBJECTSTORAGE_BUCKETNAME");
1212
public static final String ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE = System.getenv("ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE");
1313
public static final String ORDS_ENDPOINT_ANALYZE_IMAGE_INLINE = System.getenv("ORDS_ENDPOINT_ANALYZE_IMAGE_INLINE");
14+
public static final String ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL = System.getenv("ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL");
1415
public static final String OCI_VISION_SERVICE_ENDPOINT = System.getenv("OCI_VISION_SERVICE_ENDPOINT");
1516

17+
static {
18+
System.out.println("AIApplication.static initializer COMPARTMENT_ID:" + COMPARTMENT_ID);
19+
System.out.println("AIApplication.static initializer OBJECTSTORAGE_NAMESPACE:" + OBJECTSTORAGE_NAMESPACE);
20+
System.out.println("AIApplication.static initializer OBJECTSTORAGE_BUCKETNAME:" + OBJECTSTORAGE_BUCKETNAME);
21+
System.out.println("AIApplication.static initializer ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE:" + ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE);
22+
System.out.println("AIApplication.static initializer ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL:" + ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL);
23+
System.out.println("AIApplication.static initializer OCI_VISION_SERVICE_ENDPOINT:" + OCI_VISION_SERVICE_ENDPOINT);
24+
}
1625
public static void main(String[] args) {
1726
SpringApplication.run(AIApplication.class, args);
1827
}

0 commit comments

Comments
 (0)