Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,3 @@ spring_ai/create_user.sql
spring_ai/drop.sql
src/client/spring_ai/target/classes/*
api_server_key
src/client/mcp/rag/optimizer_settings.json
src/client/mcp/rag/pyproject.toml
src/client/mcp/rag/main.py
src/client/mcp/rag/.python-version
src/client/mcp/rag/uv.lock
src/client/mcp/rag/node_modules/
src/client/mcp/rag/package-lock.json
src/client/mcp/rag/package.json
35 changes: 35 additions & 0 deletions src/client/spring_ai/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Copyright (c) 2024 Oracle and/or its affiliates.

The Universal Permissive License (UPL), Version 1.0

Subject to the condition set forth below, permission is hereby granted to any
person obtaining a copy of this software, associated documentation and/or data
(collectively the "Software"), free of charge and under any and all copyright
rights in the Software, and any and all patent rights owned or freely
licensable by each licensor hereunder covering either (i) the unmodified
Software as contributed to or provided by such licensor, or (ii) the Larger
Works (as defined below), to deal in both

(a) the Software, and
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
one is included with the Software (each a "Larger Work" to which the Software
is contributed by such licensors),

without restriction, including without limitation the rights to copy, create
derivative works of, display, perform, and distribute the Software and make,
use, sell, offer for sale, import, export, have made, and have sold the
Software and the Larger Work(s), and to sublicense the foregoing rights on
either these or other terms.

This license is subject to the following condition:
The above copyright notice and either this complete permission notice or at
a minimum a reference to the UPL must be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 44 additions & 26 deletions src/client/spring_ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Get Started with Java Development](https://docs.oracle.com/en/database/oracle/or

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`.

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

This project contains a web service that will accept HTTP GET requests at
This project contains a web service that will accept HTTP requests at

* `http://localhost:9090/v1/chat/completions`: to use Vector Search via OpenAI REST API
* `http://localhost:9090/v1/service/llm` : to chat straight with the LLM used
* `http://localhost:9090/v1/service/search/`: to search for document similar to the message provided
* `http://localhost:9090/v1/service/store-chunks/`: to embedd and store a list of text chunks in the vectorstore
* `http://localhost:9090/v1/chat/completions`: to use RAG via OpenAI REST API [**POST**]
* `http://localhost:9090/v1/models`: returns models behind the RAG via OpenAI REST API [**GET**]
* `http://localhost:9090/v1/service/llm` : to chat straight with the LLM used [**GET**]
* `http://localhost:9090/v1/service/search/`: to search for similar chunk documents to the message provided [**GET**]
* `http://localhost:9090/v1/service/store-chunks/`: to embedd and store a list of text chunks in the vectorstore [**POST**]


Vector Search call example with `openai` build profile with no-stream:


### Completions
RAG call example with `openai` build profile with no-stream:

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

response:
### Get model name
Return the name of model used. It's useful to integrate ChatGUIs that require the model list before proceed.

```
curl http://localhost:9090/v1/models
```

## MCP RagTool
The completion service is also available as an MCP server based on the SSE transport protocol.
To test it:

* Start as usual the microservice:
```shell
./start.sh
```
[
[
-0.014500250108540058,
-0.03604526072740555,
0.035963304340839386,
0.010181647725403309,
-0.01610776223242283,
-0.021091962233185768,
0.03924199938774109,
..
]
]

* Start the MCP inspector:
```shell
export DANGEROUSLY_OMIT_AUTH=true
npx @modelcontextprotocol/inspector
```

* With a web browser open: http://127.0.0.1:6274

* Configure:
* Transport Type: SSE
* URL: http://127.0.0.1:9090/sse
* set Request Timeout to: 200000

* Test a call to `getRag` Tool.


## Oracle Backend for Microservices and AI
* Add in `application-obaas.yml` the **OPENAI_API_KEY**, if the deployement is based on the OpenAI LLM services:
```
Expand Down Expand Up @@ -248,11 +267,6 @@ it should return:
```







## Prerequisites

Before using the AI commands, make sure you have a developer token from OpenAI.
Expand All @@ -269,3 +283,7 @@ export SPRING_AI_OPENAI_API_KEY=<INSERT KEY HERE>
Setting the API key is all you need to run the application.
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).





9 changes: 7 additions & 2 deletions src/client/spring_ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@

<dependencies>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -75,15 +80,15 @@
<version>23.5.0.24.07</version>
</dependency>

<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
<version>23.4.0</version>
</dependency>
</dependency>

<!-- ORACLE DB END-->

Expand Down
Loading