Skip to content

Commit 2624c8c

Browse files
committed
init
1 parent 9f85d1c commit 2624c8c

20 files changed

+571
-490
lines changed

build_and_run.sh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
#!/bin/bash
22

3-
## Add exports here... For example...
4-
#export COHERE_KEY="mykeyvalue"
5-
#export OPENAI_KEY="mykeyvalue"
6-
#export OCICONFIG_FILE=~/.oci/config
7-
#export OCICONFIG_PROFILE=DEFAULT
8-
#export COMPARTMENT_ID="ocid1.compartment.oc1..mycompartmentvalue"
9-
#export OBJECTSTORAGE_NAMESPACE="myobjectstorenamespacename"
10-
#export OBJECTSTORAGE_BUCKETNAME="myobjectstorebucketname"
11-
#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-
15-
## The following are only applicable when using Kubernetes...
16-
#export KUBECONFIG=~/.kube/config-healthai
17-
#export DOCKER_REGISTRY=us-ashburn-1.ocir.io/oradbclouducm/gd74087885
3+
source env.properties
184

195
#The following is temporary until release is available in maven and only required to be called once...
206
#mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=oci-java-sdk-generativeai-3.25.1-preview1-20230906.204234-1.jar

env.properties

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
export OPENAI_KEY="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"
4+
export COHERE_KEY="oJfPT7nhQDJNAecjDQ3L89UOJYPaIH9L9Ji1VRz7"
5+
export OCICONFIG_FILE=~/.oci/config
6+
export OCICONFIG_PROFILE=DEFAULT
7+
export COMPARTMENT_ID="ocid1.compartment.oc1..aaaaaaaafnah3ogykjsg34qruhixhb2drls6zhsejzm7mubi2i5qj66slcoq"
8+
export OBJECTSTORAGE_NAMESPACE="oradbclouducm"
9+
export OBJECTSTORAGE_BUCKETNAME="aitests"
10+
export ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE="https://rddainsuh6u1okc-gd740878851.adb.us-ashburn-1.oraclecloudapps.com/ords/aiuser/call_analyze_image_api/"
11+
export ORDS_ENDPOINT_ANALYZE_IMAGE_INLINE="https://rddainsuh6u1okc-gd740878851.adb.us-ashburn-1.oraclecloudapps.com/ords/aiuser/call_analyze_image_api/"
12+
export OCI_VISION_SERVICE_ENDPOINT="https://vision.aiservice.us-ashburn-1.oci.oraclecloud.com"
13+
14+
export KUBECONFIG=~/.kube/config-healthai
15+
export DOCKER_REGISTRY=us-ashburn-1.ocir.io/oradbclouducm/gd74087885
16+
17+
#export SPRING_DATASOURCE_USERNAME="admin"
18+
#export SPRING_DATASOURCE_URL="jdbc:oracle:thin:@xr_tp?TNS_ADMIN=/Users/pparkins/Downloads/xr/Wallet_xrdb"
19+
#export SPRING_DATASOURCE_PASSWORD=1XRWelcome123
20+
21+
export SPRING_DATASOURCE_USERNAME="TESTUSER1"
22+
export SPRING_DATASOURCE_URL="jdbc:oracle:thin:@indadw_high?TNS_ADMIN=/Users/pparkins/Downloads/Wallet_IndADW"
23+
export SPRING_DATASOURCE_PASSWORD="Welcome12345"
24+
25+
#export SPRING_DATASOURCE_PASSWORD="Livelabs@2023"
26+
27+
echo dbcloud tenancy dev env configured
28+
29+
## Add exports here... For example...
30+
#export COHERE_KEY="mykeyvalue"
31+
#export OPENAI_KEY="mykeyvalue"
32+
#export OCICONFIG_FILE=~/.oci/config
33+
#export OCICONFIG_PROFILE=DEFAULT
34+
#export COMPARTMENT_ID="ocid1.compartment.oc1..mycompartmentvalue"
35+
#export OBJECTSTORAGE_NAMESPACE="myobjectstorenamespacename"
36+
#export OBJECTSTORAGE_BUCKETNAME="myobjectstorebucketname"
37+
#export ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE="myordsendpoint"
38+
#export ORDS_ENDPOINT_ANALYZE_IMAGE_INLINE="myordsendpoint"
39+
#export OCI_VISION_SERVICE_ENDPOINT="https://vision.aiservice.us-ashburn-1.oci.oraclecloud.com"
40+
41+
## The following are only applicable when using Kubernetes...
42+
#export KUBECONFIG=~/.kube/config-mykubeconfig
43+
#export DOCKER_REGISTRY=us-ashburn-1.ocir.io/myocirnamespacename/myocirfolder

sql/create_aiuser.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--run as admin
2+
3+
CREATE USER aiuser identified BY [Yourpassword];
4+
grant CREATE session TO aiuser;
5+
grant RESOURCE, db_developer_role TO aiuser;
6+
grant unlimited tablespace TO aiuser;
7+
grant EXECUTE ON javascript TO aiuser;
8+
grant EXECUTE dynamic mle TO aiuser;
9+
grant execute on DBMS_CLOUD to aiuser;

sql/dbms_sendrequest_visionai_call.sql

Lines changed: 0 additions & 37 deletions
This file was deleted.

sql/dbms_sendrequest_visionai_call_inline_function.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
--This is a work in progress and only applicable to smaller image sizes
1+
--This is a work in progress and only applicable to smaller image sizes as-is
22
create or replace FUNCTION call_analyze_image_api_inline (
33
p_endpoint VARCHAR2,
44
p_compartment_ocid VARCHAR2,

sql/dbms_sendrequest_visionai_call_objectstore_function.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ create or replace FUNCTION call_analyze_image_api_objectstore (
33
p_compartment_ocid VARCHAR2,
44
p_namespaceName VARCHAR2,
55
p_bucketName VARCHAR2,
6-
p_objectName VARCHAR2
6+
p_objectName VARCHAR2,
7+
p_label VARCHAR2
78
) RETURN CLOB IS
89
resp DBMS_CLOUD_TYPES.resp;
910
json_response CLOB;
@@ -29,15 +30,15 @@ BEGIN
2930
);
3031

3132
json_response := DBMS_CLOUD.get_response_text(resp);
32-
dbms_output.put_line('json_response: ' || json_response);
33-
INSERT INTO metering VALUES (SYS_GUID(), SYSTIMESTAMP, 'test', json_response );
34-
33+
dbms_output.put_line('json_response: ' || json_response);
34+
INSERT INTO aivision_results VALUES (SYS_GUID(), SYSTIMESTAMP, p_label, json_response );
3535
RETURN json_response;
3636
EXCEPTION
3737
WHEN OTHERS THEN
3838
-- Handle exceptions if needed and return an error message or raise
3939
RAISE;
4040
END call_analyze_image_api_objectstore;
41+
/
4142

4243
BEGIN
4344
ORDS.ENABLE_OBJECT(

sql/setup.sql

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,69 @@
1-
CREATE USER aiuser identified BY [Yourpassword];
2-
grant CREATE session TO aiuser;
3-
grant RESOURCE, db_developer_role TO aiuser;
4-
grant unlimited tablespace TO aiuser;
5-
grant EXECUTE ON javascript TO aiuser;
6-
grant EXECUTE dynamic mle TO aiuser;
7-
grant execute on DBMS_CLOUD to aiuser;
8-
--switch to aiuser
9-
10-
--CREATE TABLE metering
11-
-- (id RAW (16) NOT NULL,
12-
-- date_loaded TIMESTAMP WITH TIME ZONE,
13-
-- label varchar2(20),
14-
-- jsondata CLOB
15-
-- CONSTRAINT ensure_metering_json CHECK (jsondata IS JSON));
16-
--
1+
--run as aiuser
2+
173
CREATE TABLE aivision_results
184
(id RAW (16) NOT NULL,
195
date_loaded TIMESTAMP WITH TIME ZONE,
206
label varchar2(20),
217
jsondata CLOB
228
CONSTRAINT ensure_aivision_results_json CHECK (jsondata IS JSON));
9+
create index aivisionresultsindex on aivision_results(jsondata) indextype is ctxsys.context;
10+
select index_name, index_type, status from user_indexes where index_name = 'AIVISIONAIRESULTSINDEX';
11+
select idx_name, idx_table, idx_text_name from ctx_user_indexes;
12+
select token_text from dr$aivisionresultsindex$i;
2313

24-
create index airesultsindex on aivision_results(jsondata) indextype is ctxsys.context;
2514

26-
select index_name, index_type, status from user_indexes where index_name = 'AIRESULTSINDEX';
15+
CREATE TABLE aispeech_results
16+
(id RAW (16) NOT NULL,
17+
date_loaded TIMESTAMP WITH TIME ZONE,
18+
label varchar2(20),
19+
jsondata CLOB
20+
CONSTRAINT aispeech_results_json CHECK (jsondata IS JSON));
21+
create index aispeechresultsindex on aispeech_results(jsondata) indextype is ctxsys.context;
22+
select index_name, index_type, status from user_indexes where index_name = 'AISPEECHRESULTSINDEX';
2723
select idx_name, idx_table, idx_text_name from ctx_user_indexes;
28-
select token_text from dr$airesultsindex$i;
24+
select token_text from dr$aispeechresultsindex$i;
25+
26+
CREATE OR REPLACE FUNCTION execute_dynamic_sql(p_sql IN VARCHAR2) RETURN VARCHAR2 IS
27+
v_result VARCHAR2(4000);
28+
BEGIN
29+
EXECUTE IMMEDIATE p_sql INTO v_result;
30+
RETURN v_result;
31+
EXCEPTION
32+
WHEN OTHERS THEN
33+
RETURN SQLERRM;
34+
END execute_dynamic_sql;
35+
/
36+
2937

30-
select * from user_data
38+
select * from aispeech_results_json
3139

3240
--CONTAINS operator
33-
select * from user_data
41+
select * from aispeech_results_json
3442
where contains ( jsondata, 'john' ) > 0
3543

3644
--Mixed Queries
37-
select * from user_data
45+
select * from aispeech_results_json
3846
where amount < 100
3947
and contains ( jsondata, 'smith' ) > 0
4048

4149
--An OR search
42-
select * from user_data
50+
select * from aispeech_results_json
4351
where contains ( jsondata, 'john OR johnny' ) > 0
4452

4553
--Wildcards (% matches any string of characters, and an underscore _ character matches any single character)
46-
select * from user_data
54+
select * from aispeech_results_json
4755
where contains ( jsondata, 'john%' ) > 0
4856

4957
--Phrase searches (an AND search similar to OR but implicit)
50-
select * from user_data
58+
select * from aispeech_results_json
5159
where contains ( jsondata, 'first order' ) > 0
5260

5361
--Fuzzy searches (find not only the original search word, but also all those similar to it)
54-
select * from user_data
62+
select * from aispeech_results_json
5563
where contains ( jsondata, 'fuzzy(popins)' ) > 0
5664

5765
--Near searches (words within specified distance of each other)
58-
select * from user_data
66+
select * from aispeech_results_json
5967
where contains ( jsondata, 'near((order, smith), 1)' ) > 0
6068

6169
--Easy Text Search over Multiple Tables and Views with DBMS_SEARCH in 23c

src/main/java/oracleai/AIApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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 OCI_VISION_SERVICE_ENDPOINT = System.getenv("OCI_VISION_SERVICE_ENDPOINT"); ;
14+
public static final String OCI_VISION_SERVICE_ENDPOINT = System.getenv("OCI_VISION_SERVICE_ENDPOINT");
1515

1616
public static void main(String[] args) {
1717
SpringApplication.run(AIApplication.class, args);

src/main/java/oracleai/ExplainAndAdviseOnHealthTestResults.java

Lines changed: 8 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
11
package oracleai;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
43
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
6-
import com.oracle.bmc.aivision.AIServiceVisionClient;
7-
import com.oracle.bmc.aivision.model.*;
8-
import com.oracle.bmc.aivision.requests.AnalyzeImageRequest;
9-
import com.oracle.bmc.aivision.responses.AnalyzeImageResponse;
10-
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
11-
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
12-
import com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider;
13-
import com.oracle.bmc.generativeai.GenerativeAiClient;
14-
import com.oracle.bmc.generativeai.model.GenerateTextDetails;
15-
import com.oracle.bmc.generativeai.model.GenerateTextResult;
16-
import com.oracle.bmc.generativeai.model.OnDemandServingMode;
17-
import com.oracle.bmc.generativeai.requests.GenerateTextRequest;
18-
import com.oracle.bmc.generativeai.responses.GenerateTextResponse;
19-
import lombok.Getter;
20-
import lombok.Setter;
4+
import oracleai.services.OracleGenAI;
5+
import oracleai.services.OracleVisionAI;
216
import org.slf4j.Logger;
227
import org.slf4j.LoggerFactory;
238
import org.springframework.stereotype.Controller;
249
import org.springframework.web.bind.annotation.*;
2510
import org.springframework.web.multipart.MultipartFile;
2611

27-
import java.util.ArrayList;
28-
import java.util.Arrays;
29-
import java.util.List;
30-
3112
import org.springframework.ui.Model;
3213

3314
@Controller
@@ -41,95 +22,31 @@ public class ExplainAndAdviseOnHealthTestResults {
4122
public String analyzedoc(@RequestParam("file") MultipartFile file, Model model)
4223
throws Exception {
4324
log.info("analyzing image file:" + file);
44-
String objectDetectionResults = processImage(file.getBytes(), true);
25+
String objectDetectionResults = OracleVisionAI.processImage(file.getBytes(), true);
4526
ObjectMapper mapper = new ObjectMapper();
46-
ImageData imageData = mapper.readValue(objectDetectionResults, ImageData.class);
27+
OracleVisionAI.ImageData imageData = mapper.readValue(objectDetectionResults, OracleVisionAI.ImageData.class);
4728
String concatenatedText = concatenateText(imageData);
4829
System.out.println(concatenatedText);
4930
log.info("fullText = " + concatenatedText);
50-
String explanationOfResults = OracleGenAI.chat("explain these test results in simple terms, in less than 100 words, " +
31+
String explanationOfResults =
32+
OracleGenAI.chat("explain these test results in simple terms, in less than 100 words, " +
5133
"and tell me what should I do to get better results: \"" + concatenatedText + "\"");
5234
System.out.println("ExplainAndAdviseOnHealthTestResults.analyzedoc explanationOfResults:" + explanationOfResults);
5335
model.addAttribute("results", explanationOfResults);
5436
return "resultspage";
5537
}
5638

57-
private static String concatenateText(ImageData imageData) {
39+
private static String concatenateText(OracleVisionAI.ImageData imageData) {
5840
if (imageData.getImageText() == null || imageData.getImageText().getWords() == null) return "";
5941
StringBuilder sb = new StringBuilder();
60-
for (Word word : imageData.getImageText().getWords()) {
42+
for (OracleVisionAI.Word word : imageData.getImageText().getWords()) {
6143
sb.append(word.getText()).append(" ");
6244
}
6345
return sb.toString().trim();
6446
}
6547

6648

67-
String processImage(byte[] bytes, boolean isConfigFileAuth) throws Exception {
68-
AIServiceVisionClient aiServiceVisionClient;
69-
AuthenticationDetailsProvider provider;
70-
if (isConfigFileAuth) {
71-
provider = new ConfigFileAuthenticationDetailsProvider(
72-
System.getenv("OCICONFIG_FILE"),System.getenv("OCICONFIG_PROFILE"));
73-
aiServiceVisionClient = AIServiceVisionClient.builder().build(provider);
74-
} else {
75-
aiServiceVisionClient = new AIServiceVisionClient(InstancePrincipalsAuthenticationDetailsProvider.builder().build());
76-
}
77-
List<ImageFeature> features = new ArrayList<>();
78-
ImageFeature faceDetectionFeature = FaceDetectionFeature.builder()
79-
.maxResults(10)
80-
.build();
81-
ImageFeature classifyFeature = ImageClassificationFeature.builder()
82-
.maxResults(10)
83-
.build();
84-
ImageFeature detectImageFeature = ImageObjectDetectionFeature.builder()
85-
.maxResults(10)
86-
.build();
87-
ImageFeature textDetectImageFeature = ImageTextDetectionFeature.builder().build();
88-
// features.add(faceDetectionFeature);
89-
// features.add(classifyFeature);
90-
// features.add(detectImageFeature);
91-
features.add(textDetectImageFeature);
92-
InlineImageDetails inlineImageDetails = InlineImageDetails.builder()
93-
.data(bytes)
94-
.build();
95-
AnalyzeImageDetails analyzeImageDetails = AnalyzeImageDetails.builder()
96-
.image(inlineImageDetails)
97-
.features(features)
98-
.build();
99-
AnalyzeImageRequest request = AnalyzeImageRequest.builder()
100-
.analyzeImageDetails(analyzeImageDetails)
101-
.build();
102-
AnalyzeImageResponse response = aiServiceVisionClient.analyzeImage(request);
103-
ObjectMapper mapper = new ObjectMapper();
104-
mapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
105-
106-
String json = mapper.writeValueAsString(response.getAnalyzeImageResult());
107-
// System.out.println("AnalyzeImage Result");
108-
// System.out.println(json);
109-
return json;
110-
}
111-
112-
113-
@JsonIgnoreProperties(ignoreUnknown = true)
114-
@Getter
115-
@Setter
116-
static public class ImageData {
117-
private ImageText imageText;
118-
}
11949

120-
@JsonIgnoreProperties(ignoreUnknown = true)
121-
@Getter
122-
@Setter
123-
static class ImageText {
124-
private List<Word> words;
125-
}
126-
127-
@JsonIgnoreProperties(ignoreUnknown = true)
128-
@Getter
129-
@Setter
130-
static class Word {
131-
private String text;
132-
}
13350
/**
13451
13552

0 commit comments

Comments
 (0)