Skip to content

Commit

Permalink
Merge pull request #45 from paulparkinson/main
Browse files Browse the repository at this point in the history
update oci gen ai chat and digital double app
  • Loading branch information
jasperan authored Nov 2, 2024
2 parents 304e423 + bdd2a29 commit 0036317
Show file tree
Hide file tree
Showing 75 changed files with 2,409 additions and 239 deletions.
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

5 changes: 5 additions & 0 deletions java-ai/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-alpine
#docker.io/library/openjdk:17-oracle

ADD target/oracleai-0.0.1-SNAPSHOT.jar /usr/share/oracleai/oracleai-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/usr/share/oracleai/oracleai-0.0.1-SNAPSHOT.jar"]
File renamed without changes.
21 changes: 21 additions & 0 deletions java-ai/build0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

IMAGE_NAME=podsofkon
#IMAGE_VERSION=latest
IMAGE_VERSION=sustainableaijava
#DOCKER_REGISTRY=us-ashburn-1.ocir.io/oradbclouducm/gd74087885
DOCKER_REGISTRY=us-ashburn-1.ocir.io/oradbclouducm/podsofkon

export IMAGE=${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_VERSION}
export IMAGE_VERSION=$IMAGE_VERSION

mvn clean package

#docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE .
podman build -t=$IMAGE .
#docker buildx build --platform=linux/amd64 -t=$IMAGE .

#docker push --platform linux/amd64 "$IMAGE"
podman push "$IMAGE"
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions java-ai/k8s/createSecretFromWallet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
#simply copy this file to and run it from your wallet dir...
if kubectl apply -f - ; then
echo "secret applied for wallet."
else
echo "Error: Failure to create ragdb-wallet-secret."
fi <<!
apiVersion: v1
data:
README: $(base64 -w0 README)
cwallet.sso: $(base64 -w0 cwallet.sso)
ewallet.p12: $(base64 -w0 ewallet.p12)
keystore.jks: $(base64 -w0 keystore.jks)
ojdbc.properties: $(base64 -w0 ojdbc.properties)
sqlnet.ora: $(base64 -w0 sqlnet.ora)
tnsnames.ora: $(base64 -w0 tnsnames.ora)
truststore.jks: $(base64 -w0 truststore.jks)
kind: Secret
metadata:
name: ragdb-wallet-secret
!

22 changes: 22 additions & 0 deletions java-ai/k8s/createSecretFromWalletMac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# Simply copy this file to and run it from your wallet dir...
if kubectl apply -f - ; then
echo "secret applied for wallet in the msdataworkshop namespace."
else
echo "Error: Failure to create ragdb-wallet-secret."
fi <<!
apiVersion: v1
data:
README: $(base64 -i ./README)
cwallet.sso: $(base64 -i ./cwallet.sso)
ewallet.p12: $(base64 -i ./ewallet.p12)
keystore.jks: $(base64 -i ./keystore.jks)
ojdbc.properties: $(base64 -i ./ojdbc.properties)
sqlnet.ora: $(base64 -i ./sqlnet.ora)
tnsnames.ora: $(base64 -i ./tnsnames.ora)
truststore.jks: $(base64 -i ./truststore.jks)
kind: Secret
metadata:
name: ragdb-wallet-secret
namespace: msdataworkshop
!
3 changes: 3 additions & 0 deletions java-ai/k8s/createTLSSecret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

kubectl create secret tls ssl-certificate-secret --key $MY_STATE/tls/tls.key --cert $MY_STATE/tls/tls.crt -n
49 changes: 49 additions & 0 deletions java-ai/k8s/java-ai-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: oraclejavaai
spec:
replicas: 1
selector:
matchLabels:
app: oraclejavaai
template:
metadata:
creationTimestamp: null
labels:
app: oraclejavaai
spec:
volumes:
- name: creds
secret:
secretName: ragdb-wallet-secret
defaultMode: 420
containers:
- name: oraclejavaai
image: us-ashburn-1.ocir.io/oradbclouducm/podsofkon/podsofkon:sustainableai
# image: us-ashburn-1.ocir.io/oradbclouducm/oraclejavaai/oraclejavaai:0.2
# image: us-ashburn-1.ocir.io/oradbclouducm/gd74087885/xr-admin:0.1
ports:
- name: http
containerPort: 8080
protocol: TCP
env:
- name: LOG_LEVEL
value: DEBUG
- name: server_port
value: '8080'
- name: spring.datasource.username
value: admin
- name: spring.datasource.url
value: jdbc:oracle:thin:@ragdb_tp?TNS_ADMIN=/oraclejavaai/creds
- name: spring.datasource.password
value: Welcome123456
resources: {}
volumeMounts:
- name: creds
mountPath: /oraclejavaai/creds
imagePullPolicy: Always
restartPolicy: Always
imagePullSecrets:
- name: regcred
schedulerName: default-scheduler
13 changes: 13 additions & 0 deletions java-ai/k8s/java-ai-services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: oraclejavaai
spec:
ports:
- protocol: TCP
port: 80
targetPort: 8080
# nodePort: 32462
selector:
app: oraclejavaai
type: LoadBalancer
9 changes: 7 additions & 2 deletions pom.xml → java-ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>Oracle AI Demos</description>

<properties>
<oci.sdk.version>3.44.2</oci.sdk.version>
<oci.sdk.version>3.52.1</oci.sdk.version>
</properties>

<dependencies>
Expand All @@ -32,10 +32,15 @@
<artifactId>json</artifactId>
<version>20231013</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.oracle.cloud.spring</groupId>
<artifactId>spring-cloud-oci-starter</artifactId>
<version>1.0.0</version>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package oracleai;

import com.oracle.bmc.retrier.RetryConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class AIApplication {

public static final String COMPARTMENT_ID = System.getenv("COMPARTMENT_ID");
public static final String OBJECTSTORAGE_NAMESPACE = System.getenv("OBJECTSTORAGE_NAMESPACE");
public static final String OBJECTSTORAGE_BUCKETNAME = System.getenv("OBJECTSTORAGE_BUCKETNAME");
public static final String ORDS_ENDPOINT_URL = System.getenv("ORDS_ENDPOINT_URL");
public static final String ORDS_OMLOPSENDPOINT_URL= System.getenv("ORDS_ENDPOINT_URL") + "/omlopsuser/";
public static final String OCI_VISION_SERVICE_ENDPOINT = System.getenv("OCI_VISION_SERVICE_ENDPOINT");
public static final String OCI_SPEECH_SERVICE_ENDPOINT = System.getenv("OCI_SPEECH_SERVICE_ENDPOINT");
public static final String OCI_GENAI_SERVICE_ENDPOINT = System.getenv("OCI_GENAI_SERVICE_ENDPOINT");
public static final String OCICONFIG_FILE = System.getenv("OCICONFIG_FILE");
public static final String OCICONFIG_PROFILE = System.getenv("OCICONFIG_PROFILE");
public static final String DIGITAL_DOUBLES_IMAGES_ENDPOINT = System.getenv("DIGITAL_DOUBLES_IMAGES_ENDPOINT");
public static final String THREEDEY = "msy_mykey";

static {
System.out.println("AIApplication.static initializer COMPARTMENT_ID:" + COMPARTMENT_ID);
Expand All @@ -21,8 +26,12 @@ public class AIApplication {
System.out.println("AIApplication.static initializer ORDS_ENDPOINT_URL:" + ORDS_ENDPOINT_URL);
System.out.println("AIApplication.static initializer OCI_VISION_SERVICE_ENDPOINT:" + OCI_VISION_SERVICE_ENDPOINT);
}

public static void main(String[] args) {
SpringApplication.run(AIApplication.class, args);
}
// RetryConfiguration retryConfiguration = RetryConfiguration.builder()
// .terminationStrategy(RetryUtils.createExponentialBackoffStrategy(500, 5)) // Configure limits
// .build();
SpringApplication.run(AIApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.oracle.bmc.aivision.model.ImageTextDetectionFeature;
import com.oracle.bmc.generativeaiinference.model.OnDemandServingMode;
import oracleai.services.ORDSCalls;
import oracleai.services.OracleGenAI;
import oracleai.services.OracleObjectStore;
Expand Down Expand Up @@ -43,8 +44,13 @@ public String analyzedoc(@RequestParam("file") MultipartFile multipartFile,
}
System.out.println(concatenatedText);
System.out.println("analyzedoc fullText = " + concatenatedText);
OnDemandServingMode chatServingMode = OnDemandServingMode.builder()
.modelId("cohere.command-r-16k")
.build();
String explanationOfResults =
OracleGenAI.chat("explain these test results in simple terms, in less than 100 words, " +
OracleGenAI.builder().compartment(AIApplication.COMPARTMENT_ID)
.servingMode(chatServingMode)
.build().chat("explain these test results in simple terms, in less than 100 words, " +
"and tell me what should I do to get better results: \"" + concatenatedText + "\"");
System.out.println("ExplainAndAdviseOnHealthTestResults.analyzedoc explanationOfResults:" + explanationOfResults);
model.addAttribute("results", "SUMMARY WITH ADVICE: " + explanationOfResults +
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package oracleai;


import oracleai.digitaldouble.ImageStore;
import oracleai.services.ORDSCalls;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@Controller
@RequestMapping("/transferimage")
public class UploadDownloadImage {
Expand All @@ -23,8 +21,6 @@ public String uploadImage(@RequestParam("image") MultipartFile image, Model mode
return "images";
}



@GetMapping("/downloadimages")
public String getImageStoreData(Model model) {
ImageStore[] imageStores = ORDSCalls.getImageStoreData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String tellastory(@RequestParam("file") MultipartFile multipartFile, @Req
"OBJECT_DETECTION",
"TellAStory");
}
String generatedstory = OracleGenAI.chat("using strong negative and positive sentiments, " +
String generatedstory = OracleGenAI.builder().build().chat("using strong negative and positive sentiments, " +
"write a story that is " + genopts + " and includes " + fullText );
model.addAttribute("results", "STORY: " + generatedstory +
" --->SENTIMENT ANALYSIS: " + OracleLanguageAI.sentimentAnalysis(generatedstory) );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package oracleai.common;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

@ControllerAdvice
public class FileUploadExceptionAdvice {

@ExceptionHandler(MaxUploadSizeExceededException.class)
public ResponseEntity<String> handleMaxSizeException(MaxUploadSizeExceededException exc) {
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body("File too large!");
}
}
Loading

0 comments on commit 0036317

Please sign in to comment.