Skip to content

Commit

Permalink
Refactor showcase app code
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaprasadreddy committed Jul 23, 2024
1 parent 5d5832c commit 0c6a4f8
Show file tree
Hide file tree
Showing 34 changed files with 33 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
<modules>
<module>spring-ai-ollama</module>
<module>spring-ai-openai</module>
<module>spring-ai-showcase</module>
<module>spring-ai-openai-showcase</module>
</modules>
</project>
File renamed without changes.
5 changes: 5 additions & 0 deletions spring-ai-openai-showcase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Spring AI Showcase with OpenAI

```shell
export OPENAI_API_KEY=<INSERT KEY HERE>
```
File renamed without changes.
40 changes: 11 additions & 29 deletions spring-ai-showcase/pom.xml → spring-ai-openai-showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,42 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sivalabs</groupId>
<artifactId>spring-ai-showcase</artifactId>
<artifactId>spring-ai-openai-showcase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-ai-showcase</name>
<name>spring-ai-openai-showcase</name>
<properties>
<java.version>21</java.version>
<spring-ai.version>1.0.0-SNAPSHOT</spring-ai.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-chroma-store-spring-boot-starter</artifactId>
Expand All @@ -72,7 +66,6 @@
<artifactId>commons-compress</artifactId>
<version>1.26.2</version>
</dependency>

<dependency>
<groupId>io.github.wimdeblauwe</groupId>
<artifactId>htmx-spring-boot-thymeleaf</artifactId>
Expand All @@ -86,7 +79,6 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
Expand All @@ -97,7 +89,6 @@
<artifactId>htmx.org</artifactId>
<version>2.0.1</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down Expand Up @@ -125,6 +116,7 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -150,16 +142,6 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<!--<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>ollama</artifactId>
<scope>test</scope>
</dependency>-->
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VectorStoreConfig {
"https://www.sivalabs.in/mastering-spring-boot-in-5-stages/",
"https://www.sivalabs.in/spring-boot-jooq-tutorial-getting-started/"
);

@Bean
ApplicationRunner intVectorStore(VectorStore vectorStore) {
return args -> {
Expand All @@ -38,7 +38,7 @@ ApplicationRunner intVectorStore(VectorStore vectorStore) {
throw new RuntimeException(e);
}
});

};
}

Expand All @@ -48,8 +48,19 @@ private static void load(VectorStore vectorStore, String url) throws MalformedUR
List<Document> documents = new ArrayList<>(htmlReader.get());

logger.info("Creating and storing Embeddings from Documents");
//TODO; Need to tune the splitter
var textSplitter = new TokenTextSplitter();

int defaultChunkSize = 2000; //default 800
int minChunkSizeChars = 350;
int minChunkLengthToEmbed = 5;
int maxNumChunks = 10000;
boolean keepSeparator = true;
var textSplitter = new TokenTextSplitter(
defaultChunkSize,
minChunkSizeChars,
minChunkLengthToEmbed,
maxNumChunks,
keepSeparator
);
vectorStore.add(textSplitter.split(documents));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>RAG from Web URLs</h2>
<div class="alert alert-dark" role="alert">
<h3>Try asking the following questions</h3>
<ul>
<li>What are Spring Boot Best Practices? </li>
<li>Give me some resources to master Spring Boot? </li>
</ul>
</div>

Expand Down
5 changes: 0 additions & 5 deletions spring-ai-showcase/README.md

This file was deleted.

This file was deleted.

0 comments on commit 0c6a4f8

Please sign in to comment.