Skip to content

Commit 0d41437

Browse files
committed
init
1 parent 6384d1f commit 0d41437

18 files changed

+1939
-5
lines changed

.gitignore

Lines changed: 490 additions & 5 deletions
Large diffs are not rendered by default.

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM openjdk:11-jre-slim
2+
3+
ENTRYPOINT ["java", "-jar", "/usr/share/oracleai/oracleai.jar"]
4+
5+
ADD target/oracleai-0.0.1-SNAPSHOT.jar /usr/share/oracleai/oracleai.jar

README 2.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Oracle AI For Economic and Social Sustainable Development Livelabs Workshop
2+
3+
This a temporarily readme for the soon to be released workshop.
4+
5+
The original workshop/hackathon that this is built upon can be found here:
6+
https://paulparkinson.github.io/developer/openai-with-oracle/workshops/freetier/index.html
7+
8+
The forthcoming workshop also includes aspects from this blog along with a number of other use cases and tech aspects such as OML, etc.:
9+
https://blogs.oracle.com/developers/post/how-to-call-hugging-face-ai-from-within-an-oracle-database-using-javascript-store-and-access-results-using-sql-json-and-rest

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
mvn clean package

build_and_push.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
IMAGE_NAME=oracleai
4+
IMAGE_VERSION=0.1
5+
6+
if [ -z "$DOCKER_REGISTRY" ]; then
7+
echo "Error: DOCKER_REGISTRY env variable needs to be set!"
8+
exit 1
9+
fi
10+
11+
export IMAGE=${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_VERSION}
12+
export IMAGE_VERSION=$IMAGE_VERSION
13+
14+
mvn clean package
15+
16+
docker build -t=$IMAGE .
17+
18+
docker push "$IMAGE"
19+
if [ $? -eq 0 ]; then
20+
docker rmi "$IMAGE"
21+
fi
22+

build_and_run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
export OPENAI_KEY="sk-youropenaikeyhere-asdf"
4+
export OCICONFIG_FILE=~/.oci/config
5+
export OCICONFIG_PROFILE=DEFAULT
6+
mvn clean package ; java -jar target/oracleai-0.0.1-SNAPSHOT.jar

pom.xml

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.7.1</version>
9+
<relativePath/>
10+
</parent>
11+
<groupId>oracleai</groupId>
12+
<artifactId>oracleai</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>oracleai</name>
15+
<description>Oracle AI Demos</description>
16+
17+
<properties>
18+
<spring-cloud.version>2021.0.5</spring-cloud.version>
19+
<oracle.jdbc.version>21.7.0.0</oracle.jdbc.version>
20+
<spring.boot.version>2.7.6</spring.boot.version>
21+
<spring.vault.version>3.1.1</spring.vault.version>
22+
<oci.sdk.version>3.2.0</oci.sdk.version>
23+
24+
25+
<jib-maven-plugin.version>3.3.1</jib-maven-plugin.version>
26+
<liquibase.version>4.17.2</liquibase.version>
27+
<docker.registry>${env.DOCKER_REGISTRY}</docker.registry>
28+
</properties>
29+
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-web</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-mail</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.json</groupId>
45+
<artifactId>json</artifactId>
46+
<version>20230227</version>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>com.oracle.oci.sdk</groupId>
51+
<artifactId>oci-java-sdk-common</artifactId>
52+
<version>${oci.sdk.version}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.oracle.oci.sdk</groupId>
56+
<artifactId>oci-java-sdk-common-httpclient-jersey</artifactId>
57+
<version>${oci.sdk.version}</version>
58+
</dependency>
59+
<!-- <dependency>-->
60+
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
61+
<!-- <artifactId>oci-java-sdk-artifacts</artifactId>-->
62+
<!-- <version>${oci.sdk.version}</version>-->
63+
<!-- </dependency>-->
64+
<!-- <dependency>-->
65+
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
66+
<!-- <artifactId>oci-java-sdk-vault</artifactId>-->
67+
<!-- <version>${oci.sdk.version}</version>-->
68+
<!-- </dependency>-->
69+
<!-- <dependency>-->
70+
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
71+
<!-- <artifactId>oci-java-sdk-secrets</artifactId>-->
72+
<!-- <version>${oci.sdk.version}</version>-->
73+
<!-- </dependency>-->
74+
<dependency>
75+
<groupId>com.oracle.oci.sdk</groupId>
76+
<artifactId>oci-java-sdk-aivision</artifactId>
77+
<version>${oci.sdk.version}</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>com.oracle.oci.sdk</groupId>
81+
<artifactId>oci-java-sdk-aispeech</artifactId>
82+
<version>${oci.sdk.version}</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>com.oracle.oci.sdk</groupId>
86+
<artifactId>oci-java-sdk-ailanguage</artifactId>
87+
<version>${oci.sdk.version}</version>
88+
</dependency>
89+
<!-- <dependency>-->
90+
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
91+
<!-- <artifactId>oci-java-sdk-streaming</artifactId>-->
92+
<!-- <version>${oci.sdk.version}</version>-->
93+
<!-- </dependency>-->
94+
<!-- <dependency>-->
95+
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
96+
<!-- <artifactId>oci-java-sdk-objectstorage</artifactId>-->
97+
<!-- <version>${oci.sdk.version}</version>-->
98+
<!-- </dependency>-->
99+
100+
<dependency>
101+
<groupId>org.slf4j</groupId>
102+
<artifactId>slf4j-simple</artifactId>
103+
<version>2.0.6</version>
104+
</dependency>
105+
106+
<!-- <dependency>-->
107+
<!-- <groupId>org.apache.commons</groupId>-->
108+
<!-- <artifactId>commons-lang3</artifactId>-->
109+
<!-- <version>3.12.0</version>-->
110+
<!-- </dependency>-->
111+
<!-- <dependency>-->
112+
<!-- <groupId>com.google.code.google-collections</groupId>-->
113+
<!-- <artifactId>google-collect</artifactId>-->
114+
<!-- <version>snapshot-20080530</version>-->
115+
<!-- </dependency>-->
116+
<!-- <dependency>-->
117+
<!-- <groupId>commons-codec</groupId>-->
118+
<!-- <artifactId>commons-codec</artifactId>-->
119+
<!-- <version>1.15</version>-->
120+
<!-- </dependency>-->
121+
122+
123+
124+
<dependency>
125+
<groupId>org.springframework.boot</groupId>
126+
<artifactId>spring-boot-starter-web</artifactId>
127+
<version>${spring.boot.version}</version>
128+
</dependency>
129+
<dependency>
130+
<groupId>com.oracle.database.jdbc</groupId>
131+
<artifactId>ojdbc8</artifactId>
132+
<version>${oracle.jdbc.version}</version>
133+
</dependency>
134+
<dependency>
135+
<groupId>com.oracle.database.jdbc</groupId>
136+
<artifactId>ucp</artifactId>
137+
<version>${oracle.jdbc.version}</version>
138+
</dependency>
139+
<dependency>
140+
<groupId>com.oracle.database.security</groupId>
141+
<artifactId>oraclepki</artifactId>
142+
<version>${oracle.jdbc.version}</version>
143+
</dependency>
144+
<dependency>
145+
<groupId>com.oracle.database.security</groupId>
146+
<artifactId>osdt_core</artifactId>
147+
<version>${oracle.jdbc.version}</version>
148+
</dependency>
149+
<dependency>
150+
<groupId>com.oracle.database.security</groupId>
151+
<artifactId>osdt_cert</artifactId>
152+
<version>${oracle.jdbc.version}</version>
153+
</dependency>
154+
<dependency>
155+
<groupId>org.springframework.boot</groupId>
156+
<artifactId>spring-boot-starter-test</artifactId>
157+
<version>${spring.boot.version}</version>
158+
<scope>test</scope>
159+
</dependency>
160+
161+
162+
163+
<dependency>
164+
<groupId>javax.xml.bind</groupId>
165+
<artifactId>jaxb-api</artifactId>
166+
<version>2.4.0-b180830.0359</version>
167+
</dependency>
168+
<dependency>
169+
<groupId>com.fasterxml.jackson.core</groupId>
170+
<artifactId>jackson-databind</artifactId>
171+
</dependency>
172+
173+
174+
<dependency>
175+
<groupId>org.projectlombok</groupId>
176+
<artifactId>lombok</artifactId>
177+
</dependency>
178+
<!-- <dependency>-->
179+
<!-- <groupId>io.projectreactor</groupId>-->
180+
<!-- <artifactId>reactor-core</artifactId>-->
181+
<!-- <version>3.4.22</version>-->
182+
<!-- </dependency>-->
183+
184+
<dependency>
185+
<groupId>com.theokanning.openai-gpt3-java</groupId>
186+
<artifactId>service</artifactId>
187+
<version>0.12.0</version>
188+
</dependency>
189+
</dependencies>
190+
<dependencyManagement>
191+
<dependencies>
192+
<dependency>
193+
<groupId>org.springframework.cloud</groupId>
194+
<artifactId>spring-cloud-dependencies</artifactId>
195+
<version>${spring-cloud.version}</version>
196+
<type>pom</type>
197+
<scope>import</scope>
198+
</dependency>
199+
</dependencies>
200+
</dependencyManagement>
201+
<build>
202+
<plugins>
203+
<plugin>
204+
<groupId>org.springframework.boot</groupId>
205+
<artifactId>spring-boot-maven-plugin</artifactId>
206+
</plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>9</source><target>9</target></configuration></plugin>
207+
208+
<plugin>
209+
<groupId>org.springframework.boot</groupId>
210+
<artifactId>spring-boot-maven-plugin</artifactId>
211+
</plugin>
212+
<plugin>
213+
<groupId>org.apache.maven.plugins</groupId>
214+
<artifactId>maven-compiler-plugin</artifactId>
215+
<configuration><source>8</source><target>8</target></configuration>
216+
</plugin>
217+
218+
</plugins>
219+
</build>
220+
221+
</project>

sql/conversation.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
drop view if exists conversation_dv;
2+
drop table if exists interlocutor;
3+
drop table if exists conversation;
4+
5+
CREATE TABLE IF NOT EXISTS conversation
6+
(conversation_id INTEGER GENERATED BY DEFAULT ON NULL AS IDENTITY,
7+
name VARCHAR2(255) NOT NULL UNIQUE,
8+
CONSTRAINT conversation_pk PRIMARY KEY(conversation_id));
9+
10+
CREATE TABLE IF NOT EXISTS interlocutor
11+
(interlocutor_id INTEGER GENERATED BY DEFAULT ON NULL AS IDENTITY,
12+
name VARCHAR2(255) NOT NULL UNIQUE,
13+
dialogue VARCHAR2(255) ,
14+
conversation_id INTEGER,
15+
CONSTRAINT interlocutor_pk PRIMARY KEY(interlocutor_id),
16+
CONSTRAINT interlocutor_fk FOREIGN KEY(conversation_id) REFERENCES conversation(conversation_id));
17+
18+
CREATE OR REPLACE JSON RELATIONAL DUALITY VIEW conversation_dv AS
19+
SELECT JSON {'conversationId' IS t.conversation_id,
20+
'name' IS t.name,
21+
'interlocutor' IS
22+
[ SELECT JSON {'interlocutorId' IS d.interlocutor_id,
23+
'name' IS d.name,
24+
'dialogue' IS d.dialogue WITH NOCHECK}
25+
FROM interlocutor d WITH INSERT UPDATE
26+
WHERE d.conversation_id = t.conversation_id ]}
27+
FROM conversation t WITH INSERT UPDATE DELETE;

sql/create_aijs_user.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE USER aijs identified BY Welcome12345;
2+
grant CREATE session TO aijs;
3+
grant RESOURCE, db_developer_role TO aijs;
4+
grant unlimited tablespace TO aijs;
5+
6+
grant EXECUTE ON javascript TO aijs;
7+
grant EXECUTE dynamic mle TO aijs;
8+
9+
BEGIN
10+
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE
11+
(
12+
host => '192.168.205.1',
13+
lower_port => 80,
14+
upper_port => 8888,
15+
ace => xs$ace_type(privilege_list => xs$name_list('http'),
16+
principal_name => 'aijs',
17+
principal_type => xs_acl.ptype_db)
18+
);
19+
END;
20+
/
21+
22+
connect aijs/Welcome12345;
23+

sql/mlejs_openai_sproc.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE OR REPLACE PROCEDURE openai_call AS
2+
ctx DBMS_MLE.CONTEXT_HANDLE_T;
3+
SNIPPET CLOB;
4+
BEGIN
5+
ctx := DBMS_MLE.CREATE_CONTEXT();
6+
SNIPPET := q'~
7+
(async () => {
8+
await import('mle-js-fetch');
9+
const oracledb = require("mle-js-oracledb");
10+
const conn = oracledb.defaultConnection();
11+
for (var row of conn.execute("select conversation_id, name, dialogue from interlocutor where dialogue IS NOT NULL").rows) {
12+
const fetchUrl = "http://192.168.205.1:8080/databasejs/getreply?textcontent=" + row[2];
13+
const answer = await fetch(fetchUrl).then(response => response.json());
14+
const dialogue = JSON.stringify(answer, undefined, 4);
15+
conn.execute( "update conversation_dv set dialogue = :dialogue ", {dialogue: dialogue} );
16+
};
17+
})();
18+
~';
19+
DBMS_MLE.EVAL(ctx, 'JAVASCRIPT', SNIPPET, 'js_mode=module');
20+
DBMS_MLE.DROP_CONTEXT(ctx);
21+
EXCEPTION
22+
WHEN OTHERS THEN
23+
DBMS_OUTPUT.PUT_LINE(SQLERRM);
24+
END;
25+
/

0 commit comments

Comments
 (0)