Skip to content

Commit bd148f5

Browse files
authored
Merge pull request #1565 from oracle-devrel/native-fixes
code and readme change
2 parents 52efb69 + 999578c commit bd148f5

File tree

2 files changed

+27
-14
lines changed
  • app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions

2 files changed

+27
-14
lines changed

app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ IAM user option will work on both cases above, as local and as OCI Function.
6464

6565
## Build and test
6666

67-
During following the steps of the <a href="../java-helloworld-with-local-dev-and-oci-functions">Hello function example </a> adjust the <a href="https://github.com/oracle-devrel/technology-engineering/blob/main/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java#L131">line 131</a> to match your <code>GenAI service model OCID</code>.
67+
Following the steps of the <a href="../java-helloworld-with-local-dev-and-oci-functions">Hello function example </a> adjust the <a href="https://github.com/oracle-devrel/technology-engineering/blob/main/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java#76">line 76</a> to match your <code>compartment OCID</code> and the <a href="https://github.com/oracle-devrel/technology-engineering/blob/main/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java#77">line 77</a> to match your <code>GenAI service model OCID</code>.
6868

6969
<p>
7070

@@ -75,13 +75,25 @@ Testing with curl (or copy-pasting the API Gateway deployment url to a browser):
7575
<pre>
7676
curl https://n3yu.....ghhi.apigateway.eu-frankfurt-1.oci.customer-oci.com/
7777

78-
What happened today 01/17/2025 100 years ago ?
79-
On January 17th, 1925, 100 years ago, the following events took place:
80-
- In the US, President Calvin Coolidge delivered his annual State of the Union address to Congress. He discussed the thriving state of the national economy, emphasizing the record-high production of American industries and the growth of the country's merchant marine fleet. Coolidge also urged Congress to pass legislation facilitating world trade and improving diplomatic relations.
81-
- The first Winter Sports Week was held in Chamonix, France. This event eventually evolved into the prestigious Chamonix International Festival of Sports and Cinema.
82-
- The play "The New York Idea" by Langdon Mitchell premiered at the Ambassador Theatre on Broadway. It ran for 144 performances and received critical acclaim.
83-
- The silent film "The Gold Rush" directed by Charlie Chaplin was released in the United States. It's a classic comedy that tells the story of a prospector during the Klondike Gold Rush. Chaplin's unique brand of physical comedy and the film's innovative effects delighted audiences.
84-
- In Germany, the Weimar Republic experienced a political scandal known as the "German-Russian Trade and Credit Agreement." The agreement, which granted Germany a loan of 300 million marks from Russia, was signed secretly, leading to accusations of mismanagement and lack of transparency in the government. This incident further destabilized the already fragile Weimar Republic.
78+
What happened at 1925-02-07 ?
79+
80+
On February 7, 1925, several significant events took place around the world:
81+
82+
- In the United States, the Grand Ole Opry, a famous country music stage and radio show, made its debut on WSM radio in Nashville, Tennessee. It was initially called the "WSM Barn Dance" and has since become one of the longest-running radio programs in history.
83+
84+
- The first issue of "The New Yorker" magazine was published in New York City. Founded by Harold Ross, the magazine quickly gained a reputation for its sophisticated and witty writing, featuring contributions from renowned writers and artists.
85+
86+
- In the field of aviation, the first non-stop flight from England to India was completed by Squadron Leader John Henry "Jack" Moore-Brabazon, 1st Baron Brabazon of Tara. He flew a modified Airco DH.9A biplane, covering a distance of approximately 4,130 miles (6,646 kilometers) in about 50 hours and 37 minutes.
87+
88+
- In sports, the 1925 Rose Bowl game was played in Pasadena, California. The game, which is an annual college football bowl game, saw the Dartmouth Indians defeat the California Golden Bears by a score of 14-0.
89+
90+
- In the world of literature, the novel "The Great Gatsby" by F. Scott Fitzgerald was published in the United States. The book, set in the 1920s, explores themes of social class, wealth, and the American Dream, and has since become a classic of American literature.
91+
92+
- In the realm of science, the American chemist Wallace Carothers filed a patent for the synthetic polymer nylon. Nylon, known for its strength and versatility, would go on to revolutionize the textile industry and find applications in various products.
93+
94+
- In Europe, the Locarno Treaties were signed in Switzerland. These treaties aimed to promote peace and security in Europe after World War I. They included mutual guarantees of borders and commitments to resolve disputes peacefully.
95+
96+
These are just a few notable events that occurred on February 7, 1925. The day witnessed advancements in entertainment, aviation, sports, literature, science, and international diplomacy.
8597
</pre>
8698

8799
# Native image using GraalVM

app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on
6363
import com.oracle.bmc.generativeaiinference.model.TextContent;
6464
import com.oracle.bmc.retrier.RetryConfiguration;
6565

66+
import java.time.LocalDate;
6667
import java.io.*;
6768
import java.util.*;
6869
import java.text.*;
@@ -72,9 +73,10 @@ public class HelloAIFunction {
7273
// FILL IN PROPER VALUES FOR OCI GENAI SERVICE
7374
private static final String ENDPOINT = "https://inference.generativeai.eu-frankfurt-1.oci.oraclecloud.com";
7475
private static final Region REGION = Region.EU_FRANKFURT_1;
76+
private static final String COMPARTMENT_ID = "ocid1.compartment.oc1..";
77+
private static final String GENAI_OCID = "ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaa....wtig4q";
7578

7679
// FILL IN PROPER VALUES FOR IAM USER WHEN NOT USING INSTANCE_PRINCIPAL IN OCI FUNCTION
77-
private static final String COMPARTMENT_ID = "ocid1.compartment.oc1..";
7880
private static final String TENANCY_ID = "ocid1.tenancy.oc1..";
7981
private static final String USER_ID = "ocid1.user.oc1..";
8082
private static final String FINGERPRINT = "ef:4d:..";
@@ -85,10 +87,9 @@ public String handleRequest(String input) {
8587
GenerativeAiInferenceClient generativeAiInferenceClient;
8688
String answer = "";
8789
try {
88-
Date date = new Date();
89-
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
90-
String currentDate = dateFormat. format(date);
91-
String questionToAI = (input == null || input.isEmpty()) ? "What happened today " + currentDate + " 100 years ago ?": input;
90+
91+
LocalDate date = LocalDate.now().minusYears(100);
92+
String questionToAI = (input == null || input.isEmpty()) ? "What happened at " + date + " ?": input;
9293

9394
if(System.getenv("AUTH_INSTANCE_PRINCIPAL") != null) {
9495
System.out.println("AUTH_INSTANCE_PRINCIPAL");
@@ -128,7 +129,7 @@ public String handleRequest(String input) {
128129
.build();
129130

130131
ChatDetails chatDetails = ChatDetails.builder()
131-
.servingMode(OnDemandServingMode.builder().modelId("ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaa....wtig4q").build()) // Replace this with the actual OCID of the GenAI service
132+
.servingMode(OnDemandServingMode.builder().modelId(GENAI_OCID).build())
132133
.compartmentId(COMPARTMENT_ID)
133134
.chatRequest(chatRequest)
134135
.build();

0 commit comments

Comments
 (0)