Skip to content

Commit e7e2eab

Browse files
authored
Merge pull request #20 from paulparkinson/main
mods for GenAI endpoint and SDK/API change - does not include new jar
2 parents 47bcc9d + 180d7b9 commit e7e2eab

File tree

8 files changed

+57
-92
lines changed

8 files changed

+57
-92
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
[![License: UPL](https://img.shields.io/badge/license-UPL-green)](https://img.shields.io/badge/license-UPL-green) [![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=oracle-devrel_oracle-ai-for-sustainable-dev)](https://sonarcloud.io/dashboard?id=oracle-devrel_oracle-ai-for-sustainable-dev)
44

5-
## THIS IS A NEW, BLANK REPO THAT IS NOT READY FOR USE YET. PLEASE CHECK BACK SOON!
5+
## This is the source repos for the
6+
## "Develop with Oracle AI and Database Services: Gen, Vision, Speech, Language, and OML" workshop
67

78
## Introduction
8-
MISSING
9+
See workshop at https://apexapps.oracle.com/pls/apex/r/dbpm/livelabs/view-workshop?wid=3874
910

1011
## Getting Started
1112
MISSING
@@ -17,16 +18,16 @@ MISSING
1718
MISSING
1819

1920
## URLs
20-
* Nothing at this time
21+
https://apexapps.oracle.com/pls/apex/r/dbpm/livelabs/view-workshop?wid=3874
2122

2223
## Contributing
2324
This project is open source. Please submit your contributions by forking this repository and submitting a pull request! Oracle appreciates any contributions that are made by the open source community.
2425

2526
## License
26-
Copyright (c) 2022 Oracle and/or its affiliates.
27+
Copyright (c) 2024 Oracle and/or its affiliates.
2728

2829
Licensed under the Universal Permissive License (UPL), Version 1.0.
2930

3031
See [LICENSE](LICENSE) for more details.
3132

32-
ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.
33+
ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.

build.sh

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

33
#The following is temporary until release is available in maven and only required to be called once...
4-
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=lib/oci-java-sdk-generativeai-3.25.1-preview1-20230906.204234-1.jar
5-
mvn clean package
4+
#mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=lib/oci-java-sdk-generativeai-3.25.1-preview1-20230906.204234-1.jar
5+
6+
mvn clean package

env.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ COMPARTMENT_ID=ocid1.compartment.oc1..mycompartmentvalue
44
OBJECTSTORAGE_NAMESPACE=myobjectstorenamespacename
55
OBJECTSTORAGE_BUCKETNAME=myobjectstorebucketname
66
ORDS_ENDPOINT_URL=https://myordsendpointurl
7-
ORDS_ENDPOINT_URL=https://rddainsuh6u1okc-aidatabaseworkshop.adb.us-ashburn-1.oraclecloudapps.com/ords/aiuser/_sdw/
87
OCI_VISION_SERVICE_ENDPOINT=https://vision.aiservice.myregion.oci.oraclecloud.com
98
OCI_SPEECH_SERVICE_ENDPOINT=https://speech.aiservice.myregion.oci.oraclecloud.com
10-
OCI_GENAI_SERVICE_ENDPOINT=https://genai.aiservice.us-chicago-1.oci.oraclecloud.com
11-
OPENAI_KEY=mykeyfordalleifused
9+
OCI_GENAI_SERVICE_ENDPOINT=https://inference.generativeai.us-chicago-1.oci.oraclecloud.com
10+
OPENAI_KEY=mykeyfordalleifused
Binary file not shown.

pom.xml

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<oci.sdk.version>3.29.0</oci.sdk.version>
2323
<jib-maven-plugin.version>3.3.1</jib-maven-plugin.version>
2424
<liquibase.version>4.17.2</liquibase.version>
25-
<docker.registry>${env.DOCKER_REGISTRY}</docker.registry>
2625
</properties>
2726

2827
<dependencies>
@@ -50,30 +49,11 @@
5049
<artifactId>oci-java-sdk-common-httpclient-jersey</artifactId>
5150
<version>${oci.sdk.version}</version>
5251
</dependency>
53-
5452
<dependency>
5553
<groupId>com.oracle.oci.sdk</groupId>
56-
<artifactId>oci-java-sdk-generativeai</artifactId>
57-
<!-- <version>3.25.1-preview1-20230906.204234-1</version> -->
58-
<version>3.25.1-preview1-SNAPSHOT</version>
59-
<!-- <systemPath>${basedir}/../genai-sdk/oci-java-sdk-generativeai-3.25.1-preview1-20230906.204234-1.jar</systemPath> -->
60-
<!-- <scope>system</scope> -->
61-
</dependency>
62-
<!-- <dependency>-->
63-
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
64-
<!-- <artifactId>oci-java-sdk-artifacts</artifactId>-->
65-
<!-- <version>${oci.sdk.version}</version>-->
66-
<!-- </dependency>-->
67-
<!-- <dependency>-->
68-
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
69-
<!-- <artifactId>oci-java-sdk-vault</artifactId>-->
70-
<!-- <version>${oci.sdk.version}</version>-->
71-
<!-- </dependency>-->
72-
<!-- <dependency>-->
73-
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
74-
<!-- <artifactId>oci-java-sdk-secrets</artifactId>-->
75-
<!-- <version>${oci.sdk.version}</version>-->
76-
<!-- </dependency>-->
54+
<artifactId>oci-java-sdk-generativeaiinference</artifactId>
55+
<version>3.32.1</version>
56+
</dependency>
7757
<dependency>
7858
<groupId>com.oracle.oci.sdk</groupId>
7959
<artifactId>oci-java-sdk-aivision</artifactId>
@@ -105,31 +85,6 @@
10585
<artifactId>spring-boot-starter-web</artifactId>
10686
<version>${spring.boot.version}</version>
10787
</dependency>
108-
<!-- <dependency>-->
109-
<!-- <groupId>com.oracle.database.jdbc</groupId>-->
110-
<!-- <artifactId>ojdbc8</artifactId>-->
111-
<!-- <version>${oracle.jdbc.version}</version>-->
112-
<!-- </dependency>-->
113-
<!-- <dependency>-->
114-
<!-- <groupId>com.oracle.database.jdbc</groupId>-->
115-
<!-- <artifactId>ucp</artifactId>-->
116-
<!-- <version>${oracle.jdbc.version}</version>-->
117-
<!-- </dependency>-->
118-
<!-- <dependency>-->
119-
<!-- <groupId>com.oracle.database.security</groupId>-->
120-
<!-- <artifactId>oraclepki</artifactId>-->
121-
<!-- <version>${oracle.jdbc.version}</version>-->
122-
<!-- </dependency>-->
123-
<!-- <dependency>-->
124-
<!-- <groupId>com.oracle.database.security</groupId>-->
125-
<!-- <artifactId>osdt_core</artifactId>-->
126-
<!-- <version>${oracle.jdbc.version}</version>-->
127-
<!-- </dependency>-->
128-
<!-- <dependency>-->
129-
<!-- <groupId>com.oracle.database.security</groupId>-->
130-
<!-- <artifactId>osdt_cert</artifactId>-->
131-
<!-- <version>${oracle.jdbc.version}</version>-->
132-
<!-- </dependency>-->
13388
<dependency>
13489
<groupId>org.springframework.boot</groupId>
13590
<artifactId>spring-boot-starter-test</artifactId>

src/main/java/oracleai/ExplainAndAdviseOnHealthTestResults.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import oracleai.services.OracleGenAI;
77
import oracleai.services.OracleObjectStore;
88
import oracleai.services.OracleVisionAI;
9-
import org.slf4j.Logger;
10-
import org.slf4j.LoggerFactory;
119
import org.springframework.stereotype.Controller;
1210
import org.springframework.web.bind.annotation.*;
1311
import org.springframework.web.multipart.MultipartFile;
@@ -62,4 +60,4 @@ private static String concatenateText(OracleVisionAI.ImageData imageData) {
6260
}
6361
return sb.toString().trim();
6462
}
65-
}
63+
}
Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
11
package oracleai.services;
22

3+
import com.oracle.bmc.ClientConfiguration;
4+
import com.oracle.bmc.ConfigFileReader;
35
import com.oracle.bmc.Region;
46
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
5-
import com.oracle.bmc.generativeai.GenerativeAiClient;
6-
import com.oracle.bmc.generativeai.model.GenerateTextDetails;
7-
import com.oracle.bmc.generativeai.model.GenerateTextResult;
8-
import com.oracle.bmc.generativeai.model.OnDemandServingMode;
9-
import com.oracle.bmc.generativeai.requests.GenerateTextRequest;
10-
import com.oracle.bmc.generativeai.responses.GenerateTextResponse;
7+
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
8+
import com.oracle.bmc.retrier.RetryConfiguration;
9+
import com.oracle.bmc.ClientConfiguration;
10+
import com.oracle.bmc.ConfigFileReader;
11+
import com.oracle.bmc.Region;
12+
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
13+
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
14+
import com.oracle.bmc.generativeaiinference.GenerativeAiInferenceClient;
15+
import com.oracle.bmc.generativeaiinference.model.CohereLlmInferenceRequest;
16+
import com.oracle.bmc.generativeaiinference.model.GenerateTextDetails;
17+
import com.oracle.bmc.generativeaiinference.model.OnDemandServingMode;
18+
import com.oracle.bmc.generativeaiinference.requests.GenerateTextRequest;
19+
import com.oracle.bmc.generativeaiinference.responses.GenerateTextResponse;
20+
import com.oracle.bmc.generativeaiinference.responses.GenerateTextResponse;
21+
22+
1123
import oracleai.AIApplication;
1224

1325
import java.util.Arrays;
1426
import java.util.List;
1527

1628
public class OracleGenAI {
1729

18-
1930
public static String chat(String textcontent) throws Exception {
20-
AuthenticationDetailsProvider provider = AuthProvider.getAuthenticationDetailsProvider();
21-
//GenAI is only available in US_CHICAGO_1 for current beta, thus the override
22-
GenerativeAiClient generativeAiClient = GenerativeAiClient.builder().region(Region.US_CHICAGO_1).build(provider);
23-
List<String> prompts = Arrays.asList(textcontent);
31+
return new OracleGenAI().doChat(textcontent);
32+
}
33+
34+
public String doChat(String textcontent) throws Exception {
35+
final GenerativeAiInferenceClient generativeAiInferenceClient =
36+
new GenerativeAiInferenceClient(AuthProvider.getAuthenticationDetailsProvider());
37+
// generativeAiInferenceClient.setEndpoint(ENDPOINT);
38+
generativeAiInferenceClient.setRegion(Region.US_CHICAGO_1);
39+
CohereLlmInferenceRequest cohereLlmInferenceRequest =
40+
CohereLlmInferenceRequest.builder()
41+
.prompt(textcontent)
42+
.maxTokens(600)
43+
.temperature(0.75)
44+
.frequencyPenalty(1.0)
45+
.topP(0.7)
46+
.isStream(false) // SDK doesn't support streaming responses, feature is under development
47+
.isEcho(true)
48+
.build();
2449
GenerateTextDetails generateTextDetails = GenerateTextDetails.builder()
2550
.servingMode(OnDemandServingMode.builder().modelId("cohere.command").build()) // "cohere.command-light" is also available to use
2651
// .servingMode(DedicatedServingMode.builder().endpointId("custom-model-endpoint").build()) // for custom model from Dedicated AI Cluster
2752
.compartmentId(AIApplication.COMPARTMENT_ID)
28-
.prompts(prompts)
29-
.maxTokens(300)
30-
.temperature(0.75)
31-
.frequencyPenalty(1.0)
32-
.topP(0.7)
33-
.isStream(false)
34-
.isEcho(false)
53+
.inferenceRequest(cohereLlmInferenceRequest)
3554
.build();
3655
GenerateTextRequest generateTextRequest = GenerateTextRequest.builder()
3756
.generateTextDetails(generateTextDetails)
3857
.build();
39-
GenerateTextResponse generateTextResponse = generativeAiClient.generateText(generateTextRequest);
40-
GenerateTextResult result = generateTextResponse.getGenerateTextResult();
41-
if(result !=null && result.getGeneratedTexts().size() > 0 ) {
42-
String all_results ="";
43-
for (List<com.oracle.bmc.generativeai.model.GeneratedText> list : result.getGeneratedTexts()) {
44-
for (com.oracle.bmc.generativeai.model.GeneratedText text:list){
45-
all_results = all_results+text.getText();
46-
}
47-
}
48-
return all_results;
49-
}
50-
return "We could not find a result for your text. Try a different image.";
58+
GenerateTextResponse generateTextResponse = generativeAiInferenceClient.generateText(generateTextRequest);
59+
System.out.println(generateTextResponse.toString());
60+
return generateTextResponse.toString();
5161
}
5262

5363
}

src/main/resources/application.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ ORDS_ENDPOINT_URL="https://myordsendpointurl"
77
ORDS_ENDPOINT_URL="https://rddainsuh6u1okc-aidatabaseworkshop.adb.us-ashburn-1.oraclecloudapps.com/ords/aiuser/_sdw/"
88
OCI_VISION_SERVICE_ENDPOINT="https://vision.aiservice.myregion.oci.oraclecloud.com"
99
OCI_SPEECH_SERVICE_ENDPOINT="https://speech.aiservice.myregion.oci.oraclecloud.com"
10-
OCI_GENAI_SERVICE_ENDPOINT="https://genai.aiservice.us-chicago-1.oci.oraclecloud.com"
10+
OCI_GENAI_SERVICE_ENDPOINT="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com"
11+

0 commit comments

Comments
 (0)