Skip to content

Commit 3e149f5

Browse files
Merge pull request #192 from oracle-samples/169-springai-1.0
springai 1.0 update
2 parents 90cb55b + 11c9ad6 commit 3e149f5

File tree

12 files changed

+504
-234
lines changed

12 files changed

+504
-234
lines changed

.gitignore

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,3 @@ spring_ai/create_user.sql
6464
spring_ai/drop.sql
6565
src/client/spring_ai/target/classes/*
6666
api_server_key
67-
src/client/mcp/rag/optimizer_settings.json
68-
src/client/mcp/rag/pyproject.toml
69-
src/client/mcp/rag/main.py
70-
src/client/mcp/rag/.python-version
71-
src/client/mcp/rag/uv.lock
72-
src/client/mcp/rag/node_modules/
73-
src/client/mcp/rag/package-lock.json
74-
src/client/mcp/rag/package.json

src/client/spring_ai/LICENSE.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2024 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.

src/client/spring_ai/README.md

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Get Started with Java Development](https://docs.oracle.com/en/database/oracle/or
2020

2121
Download one of them through the `Download SpringAI` button. Unzip the content and set the executable permission on the `start.sh` with `chmod 755 ./start.sh`.
2222

23-
Edit `start.sh` to add only the DB_PASSWORD not exported, as in this example:
23+
Edit `start.sh` to change the DB_PASSWORD or any other referece/credential changed by the dev env, as in this example:
2424
```
2525
export SPRING_AI_OPENAI_API_KEY=$OPENAI_API_KEY
2626
export DB_DSN="jdbc:oracle:thin:@localhost:1521/FREEPDB1"
2727
export DB_USERNAME=<DB_USER_NAME>
28-
export DB_PASSWORD=""
28+
export DB_PASSWORD=<DB_PASSWORD>
2929
export DISTANCE_TYPE=COSINE
3030
export OPENAI_CHAT_MODEL=gpt-4o-mini
3131
export OPENAI_EMBEDDING_MODEL=text-embedding-3-small
@@ -52,15 +52,19 @@ Start with:
5252
./start.sh
5353
```
5454

55-
This project contains a web service that will accept HTTP GET requests at
55+
This project contains a web service that will accept HTTP requests at
5656

57-
* `http://localhost:9090/v1/chat/completions`: to use Vector Search via OpenAI REST API
58-
* `http://localhost:9090/v1/service/llm` : to chat straight with the LLM used
59-
* `http://localhost:9090/v1/service/search/`: to search for document similar to the message provided
60-
* `http://localhost:9090/v1/service/store-chunks/`: to embedd and store a list of text chunks in the vectorstore
57+
* `http://localhost:9090/v1/chat/completions`: to use RAG via OpenAI REST API [**POST**]
58+
* `http://localhost:9090/v1/models`: returns models behind the RAG via OpenAI REST API [**GET**]
59+
* `http://localhost:9090/v1/service/llm` : to chat straight with the LLM used [**GET**]
60+
* `http://localhost:9090/v1/service/search/`: to search for similar chunk documents to the message provided [**GET**]
61+
* `http://localhost:9090/v1/service/store-chunks/`: from a list of chunks provided, it generates vector embeddings and store them in the vector store. [**POST**]
6162

6263

63-
Vector Search call example with `openai` build profile with no-stream:
64+
65+
66+
### Completions
67+
RAG call example with `openai` build profile with no-stream:
6468

6569
```
6670
curl -N http://localhost:9090/v1/chat/completions \
@@ -119,23 +123,38 @@ curl -X POST http://localhost:9090/v1/service/store-chunks \
119123
-d '["First chunk of text.", "Second chunk.", "Another example."]'
120124
```
121125

122-
response:
126+
### Get model name
127+
Return the name of model used. It's useful to integrate ChatGUIs that require the model list before proceed.
128+
129+
```
130+
curl http://localhost:9090/v1/models
131+
```
132+
133+
## MCP RagTool
134+
The completion service is also available as an MCP server based on the SSE transport protocol.
135+
To test it:
123136

137+
* Start as usual the microservice:
138+
```shell
139+
./start.sh
124140
```
125-
[
126-
[
127-
-0.014500250108540058,
128-
-0.03604526072740555,
129-
0.035963304340839386,
130-
0.010181647725403309,
131-
-0.01610776223242283,
132-
-0.021091962233185768,
133-
0.03924199938774109,
134-
..
135-
]
136-
]
141+
142+
* Start the MCP inspector:
143+
```shell
144+
export DANGEROUSLY_OMIT_AUTH=true
145+
npx @modelcontextprotocol/inspector
137146
```
138147

148+
* With a web browser open: http://127.0.0.1:6274
149+
150+
* Configure:
151+
* Transport Type: SSE
152+
* URL: http://127.0.0.1:9090/sse
153+
* set Request Timeout to: 200000
154+
155+
* Test a call to `getRag` Tool.
156+
157+
139158
## Oracle Backend for Microservices and AI
140159
* Add in `application-obaas.yml` the **OPENAI_API_KEY**, if the deployement is based on the OpenAI LLM services:
141160
```
@@ -248,11 +267,6 @@ it should return:
248267
```
249268

250269

251-
252-
253-
254-
255-
256270
## Prerequisites
257271

258272
Before using the AI commands, make sure you have a developer token from OpenAI.
@@ -269,3 +283,7 @@ export SPRING_AI_OPENAI_API_KEY=<INSERT KEY HERE>
269283
Setting the API key is all you need to run the application.
270284
However, you can find more information on setting started in the [Spring AI reference documentation section on OpenAI Chat](https://docs.spring.io/spring-ai/reference/api/clients/openai-chat.html).
271285

286+
287+
288+
289+

src/client/spring_ai/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232

3333
<dependencies>
3434

35+
<dependency>
36+
<groupId>org.springframework.ai</groupId>
37+
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
38+
</dependency>
39+
3540
<dependency>
3641
<groupId>org.springframework.boot</groupId>
3742
<artifactId>spring-boot-starter-web</artifactId>
@@ -75,15 +80,15 @@
7580
<version>23.5.0.24.07</version>
7681
</dependency>
7782

78-
<dependency>
83+
<dependency>
7984
<groupId>org.springframework.boot</groupId>
8085
<artifactId>spring-boot-starter-jdbc</artifactId>
8186
</dependency>
8287
<dependency>
8388
<groupId>com.oracle.database.spring</groupId>
8489
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
8590
<version>23.4.0</version>
86-
</dependency>
91+
</dependency>
8792

8893
<!-- ORACLE DB END-->
8994

0 commit comments

Comments
 (0)