Skip to content

Commit 0036317

Browse files
authored
Merge pull request #45 from paulparkinson/main
update oci gen ai chat and digital double app
2 parents 304e423 + bdd2a29 commit 0036317

File tree

75 files changed

+2409
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2409
-239
lines changed

Dockerfile

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

java-ai/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM openjdk:17-alpine
2+
#docker.io/library/openjdk:17-oracle
3+
4+
ADD target/oracleai-0.0.1-SNAPSHOT.jar /usr/share/oracleai/oracleai-0.0.1-SNAPSHOT.jar
5+
ENTRYPOINT ["java", "-jar", "/usr/share/oracleai/oracleai-0.0.1-SNAPSHOT.jar"]
File renamed without changes.

java-ai/build0.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
IMAGE_NAME=podsofkon
6+
#IMAGE_VERSION=latest
7+
IMAGE_VERSION=sustainableaijava
8+
#DOCKER_REGISTRY=us-ashburn-1.ocir.io/oradbclouducm/gd74087885
9+
DOCKER_REGISTRY=us-ashburn-1.ocir.io/oradbclouducm/podsofkon
10+
11+
export IMAGE=${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_VERSION}
12+
export IMAGE_VERSION=$IMAGE_VERSION
13+
14+
mvn clean package
15+
16+
#docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE .
17+
podman build -t=$IMAGE .
18+
#docker buildx build --platform=linux/amd64 -t=$IMAGE .
19+
20+
#docker push --platform linux/amd64 "$IMAGE"
21+
podman push "$IMAGE"
File renamed without changes.
File renamed without changes.
File renamed without changes.

java-ai/k8s/createSecretFromWallet.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
#simply copy this file to and run it from your wallet dir...
3+
if kubectl apply -f - ; then
4+
echo "secret applied for wallet."
5+
else
6+
echo "Error: Failure to create ragdb-wallet-secret."
7+
fi <<!
8+
apiVersion: v1
9+
data:
10+
README: $(base64 -w0 README)
11+
cwallet.sso: $(base64 -w0 cwallet.sso)
12+
ewallet.p12: $(base64 -w0 ewallet.p12)
13+
keystore.jks: $(base64 -w0 keystore.jks)
14+
ojdbc.properties: $(base64 -w0 ojdbc.properties)
15+
sqlnet.ora: $(base64 -w0 sqlnet.ora)
16+
tnsnames.ora: $(base64 -w0 tnsnames.ora)
17+
truststore.jks: $(base64 -w0 truststore.jks)
18+
kind: Secret
19+
metadata:
20+
name: ragdb-wallet-secret
21+
!
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# Simply copy this file to and run it from your wallet dir...
3+
if kubectl apply -f - ; then
4+
echo "secret applied for wallet in the msdataworkshop namespace."
5+
else
6+
echo "Error: Failure to create ragdb-wallet-secret."
7+
fi <<!
8+
apiVersion: v1
9+
data:
10+
README: $(base64 -i ./README)
11+
cwallet.sso: $(base64 -i ./cwallet.sso)
12+
ewallet.p12: $(base64 -i ./ewallet.p12)
13+
keystore.jks: $(base64 -i ./keystore.jks)
14+
ojdbc.properties: $(base64 -i ./ojdbc.properties)
15+
sqlnet.ora: $(base64 -i ./sqlnet.ora)
16+
tnsnames.ora: $(base64 -i ./tnsnames.ora)
17+
truststore.jks: $(base64 -i ./truststore.jks)
18+
kind: Secret
19+
metadata:
20+
name: ragdb-wallet-secret
21+
namespace: msdataworkshop
22+
!

java-ai/k8s/createTLSSecret.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
kubectl create secret tls ssl-certificate-secret --key $MY_STATE/tls/tls.key --cert $MY_STATE/tls/tls.crt -n

java-ai/k8s/java-ai-deployment.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: oraclejavaai
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: oraclejavaai
10+
template:
11+
metadata:
12+
creationTimestamp: null
13+
labels:
14+
app: oraclejavaai
15+
spec:
16+
volumes:
17+
- name: creds
18+
secret:
19+
secretName: ragdb-wallet-secret
20+
defaultMode: 420
21+
containers:
22+
- name: oraclejavaai
23+
image: us-ashburn-1.ocir.io/oradbclouducm/podsofkon/podsofkon:sustainableai
24+
# image: us-ashburn-1.ocir.io/oradbclouducm/oraclejavaai/oraclejavaai:0.2
25+
# image: us-ashburn-1.ocir.io/oradbclouducm/gd74087885/xr-admin:0.1
26+
ports:
27+
- name: http
28+
containerPort: 8080
29+
protocol: TCP
30+
env:
31+
- name: LOG_LEVEL
32+
value: DEBUG
33+
- name: server_port
34+
value: '8080'
35+
- name: spring.datasource.username
36+
value: admin
37+
- name: spring.datasource.url
38+
value: jdbc:oracle:thin:@ragdb_tp?TNS_ADMIN=/oraclejavaai/creds
39+
- name: spring.datasource.password
40+
value: Welcome123456
41+
resources: {}
42+
volumeMounts:
43+
- name: creds
44+
mountPath: /oraclejavaai/creds
45+
imagePullPolicy: Always
46+
restartPolicy: Always
47+
imagePullSecrets:
48+
- name: regcred
49+
schedulerName: default-scheduler

java-ai/k8s/java-ai-services.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: oraclejavaai
5+
spec:
6+
ports:
7+
- protocol: TCP
8+
port: 80
9+
targetPort: 8080
10+
# nodePort: 32462
11+
selector:
12+
app: oraclejavaai
13+
type: LoadBalancer

pom.xml renamed to java-ai/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<description>Oracle AI Demos</description>
1616

1717
<properties>
18-
<oci.sdk.version>3.44.2</oci.sdk.version>
18+
<oci.sdk.version>3.52.1</oci.sdk.version>
1919
</properties>
2020

2121
<dependencies>
@@ -32,10 +32,15 @@
3232
<artifactId>json</artifactId>
3333
<version>20231013</version>
3434
</dependency>
35+
<dependency>
36+
<groupId>commons-io</groupId>
37+
<artifactId>commons-io</artifactId>
38+
<version>2.8.0</version>
39+
</dependency>
3540
<dependency>
3641
<groupId>com.oracle.cloud.spring</groupId>
3742
<artifactId>spring-cloud-oci-starter</artifactId>
38-
<version>1.0.0</version>
43+
<version>1.3.0</version>
3944
</dependency>
4045
<dependency>
4146
<groupId>com.oracle.oci.sdk</groupId>

run.sh renamed to java-ai/run.sh

File renamed without changes.
File renamed without changes.
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package oracleai;
22

3+
import com.oracle.bmc.retrier.RetryConfiguration;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56

7+
68
@SpringBootApplication
79
public class AIApplication {
810

911
public static final String COMPARTMENT_ID = System.getenv("COMPARTMENT_ID");
1012
public static final String OBJECTSTORAGE_NAMESPACE = System.getenv("OBJECTSTORAGE_NAMESPACE");
1113
public static final String OBJECTSTORAGE_BUCKETNAME = System.getenv("OBJECTSTORAGE_BUCKETNAME");
1214
public static final String ORDS_ENDPOINT_URL = System.getenv("ORDS_ENDPOINT_URL");
15+
public static final String ORDS_OMLOPSENDPOINT_URL= System.getenv("ORDS_ENDPOINT_URL") + "/omlopsuser/";
1316
public static final String OCI_VISION_SERVICE_ENDPOINT = System.getenv("OCI_VISION_SERVICE_ENDPOINT");
14-
public static final String OCI_SPEECH_SERVICE_ENDPOINT = System.getenv("OCI_SPEECH_SERVICE_ENDPOINT");
15-
public static final String OCI_GENAI_SERVICE_ENDPOINT = System.getenv("OCI_GENAI_SERVICE_ENDPOINT");
17+
public static final String OCICONFIG_FILE = System.getenv("OCICONFIG_FILE");
18+
public static final String OCICONFIG_PROFILE = System.getenv("OCICONFIG_PROFILE");
19+
public static final String DIGITAL_DOUBLES_IMAGES_ENDPOINT = System.getenv("DIGITAL_DOUBLES_IMAGES_ENDPOINT");
20+
public static final String THREEDEY = "msy_mykey";
1621

1722
static {
1823
System.out.println("AIApplication.static initializer COMPARTMENT_ID:" + COMPARTMENT_ID);
@@ -21,8 +26,12 @@ public class AIApplication {
2126
System.out.println("AIApplication.static initializer ORDS_ENDPOINT_URL:" + ORDS_ENDPOINT_URL);
2227
System.out.println("AIApplication.static initializer OCI_VISION_SERVICE_ENDPOINT:" + OCI_VISION_SERVICE_ENDPOINT);
2328
}
29+
2430
public static void main(String[] args) {
25-
SpringApplication.run(AIApplication.class, args);
26-
}
31+
// RetryConfiguration retryConfiguration = RetryConfiguration.builder()
32+
// .terminationStrategy(RetryUtils.createExponentialBackoffStrategy(500, 5)) // Configure limits
33+
// .build();
34+
SpringApplication.run(AIApplication.class, args);
35+
}
2736

2837
}

src/main/java/oracleai/ExplainAndAdviseOnHealthTestResults.java renamed to java-ai/src/main/java/oracleai/ExplainAndAdviseOnHealthTestResults.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.oracle.bmc.aivision.model.ImageTextDetectionFeature;
5+
import com.oracle.bmc.generativeaiinference.model.OnDemandServingMode;
56
import oracleai.services.ORDSCalls;
67
import oracleai.services.OracleGenAI;
78
import oracleai.services.OracleObjectStore;
@@ -43,8 +44,13 @@ public String analyzedoc(@RequestParam("file") MultipartFile multipartFile,
4344
}
4445
System.out.println(concatenatedText);
4546
System.out.println("analyzedoc fullText = " + concatenatedText);
47+
OnDemandServingMode chatServingMode = OnDemandServingMode.builder()
48+
.modelId("cohere.command-r-16k")
49+
.build();
4650
String explanationOfResults =
47-
OracleGenAI.chat("explain these test results in simple terms, in less than 100 words, " +
51+
OracleGenAI.builder().compartment(AIApplication.COMPARTMENT_ID)
52+
.servingMode(chatServingMode)
53+
.build().chat("explain these test results in simple terms, in less than 100 words, " +
4854
"and tell me what should I do to get better results: \"" + concatenatedText + "\"");
4955
System.out.println("ExplainAndAdviseOnHealthTestResults.analyzedoc explanationOfResults:" + explanationOfResults);
5056
model.addAttribute("results", "SUMMARY WITH ADVICE: " + explanationOfResults +

src/main/java/oracleai/UploadDownloadImage.java renamed to java-ai/src/main/java/oracleai/UploadDownloadImage.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package oracleai;
22

3-
3+
import oracleai.digitaldouble.ImageStore;
44
import oracleai.services.ORDSCalls;
55
import org.springframework.stereotype.Controller;
66
import org.springframework.ui.Model;
7-
import org.springframework.web.bind.annotation.GetMapping;
8-
import org.springframework.web.bind.annotation.PostMapping;
9-
import org.springframework.web.bind.annotation.RequestMapping;
10-
import org.springframework.web.bind.annotation.RequestParam;
7+
import org.springframework.web.bind.annotation.*;
118
import org.springframework.web.multipart.MultipartFile;
129

10+
1311
@Controller
1412
@RequestMapping("/transferimage")
1513
public class UploadDownloadImage {
@@ -23,8 +21,6 @@ public String uploadImage(@RequestParam("image") MultipartFile image, Model mode
2321
return "images";
2422
}
2523

26-
27-
2824
@GetMapping("/downloadimages")
2925
public String getImageStoreData(Model model) {
3026
ImageStore[] imageStores = ORDSCalls.getImageStoreData();

src/main/java/oracleai/WriteAStoryAboutAPictureAndGiveItsSentiments.java renamed to java-ai/src/main/java/oracleai/WriteAStoryAboutAPictureAndGiveItsSentiments.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public String tellastory(@RequestParam("file") MultipartFile multipartFile, @Req
4040
"OBJECT_DETECTION",
4141
"TellAStory");
4242
}
43-
String generatedstory = OracleGenAI.chat("using strong negative and positive sentiments, " +
43+
String generatedstory = OracleGenAI.builder().build().chat("using strong negative and positive sentiments, " +
4444
"write a story that is " + genopts + " and includes " + fullText );
4545
model.addAttribute("results", "STORY: " + generatedstory +
4646
" --->SENTIMENT ANALYSIS: " + OracleLanguageAI.sentimentAnalysis(generatedstory) );
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package oracleai.common;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.ControllerAdvice;
6+
import org.springframework.web.bind.annotation.ExceptionHandler;
7+
import org.springframework.web.multipart.MaxUploadSizeExceededException;
8+
9+
@ControllerAdvice
10+
public class FileUploadExceptionAdvice {
11+
12+
@ExceptionHandler(MaxUploadSizeExceededException.class)
13+
public ResponseEntity<String> handleMaxSizeException(MaxUploadSizeExceededException exc) {
14+
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body("File too large!");
15+
}
16+
}

0 commit comments

Comments
 (0)