Skip to content

Commit

Permalink
Improve text classification, update Gradle, configure GraalVM
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasVitale committed Jun 13, 2024
1 parent 3034c1a commit 374c042
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .sdkmanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# See https://sdkman.io/usage#config
# A summary is to add the following to ~/.sdkman/etc/config
# sdkman_auto_env=true
java=21.0.2-tem
java=22-oracle
10 changes: 5 additions & 5 deletions 00-use-cases/text-classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ Each endpoint is backed by a progressively better prompt to increase the quality
Class Names:

```shell
http --raw "NBA announced a new application to enhance the experience of watching basketball on Apple Vision Pro." :8080/classify/class-names
http --raw "Basketball fans can now watch the game on the brand-new NBA app for Apple Vision Pro." :8080/classify/class-names
```

Class Descriptions:

```shell
http --raw "NBA announced a new application to enhance the experience of watching basketball on Apple Vision Pro." :8080/classify/class-descriptions
http --raw "Basketball fans can now watch the game on the brand-new NBA app for Apple Vision Pro." :8080/classify/class-descriptions
```

Few Shots Prompt:

```shell
http --raw "NBA announced a new application to enhance the experience of watching basketball on Apple Vision Pro." :8080/classify/few-shots-prompt
http --raw "Basketball fans can now watch the game on the brand-new NBA app for Apple Vision Pro." :8080/classify/few-shots-prompt
```

Few Shots History:

```shell
http --raw "NBA announced a new application to enhance the experience of watching basketball on Apple Vision Pro." :8080/classify/few-shots-history
http --raw "Basketball fans can now watch the game on the brand-new NBA app for Apple Vision Pro." :8080/classify/few-shots-history
```

Structured Output:

```shell
http --raw "NBA announced a new application to enhance the experience of watching basketball on Apple Vision Pro." :8080/classify/structured-output
http --raw "Basketball fans can now watch the game on the brand-new NBA app for Apple Vision Pro." :8080/classify/structured-output
```
2 changes: 1 addition & 1 deletion 00-use-cases/text-classification/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(22)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ String classifyClassNames(@RequestBody String text) {
}

@PostMapping("/classify/class-descriptions")
String classifyClassDescriptions(@RequestBody String input) {
return textClassifier.classifyClassDescriptions(input);
String classifyClassDescriptions(@RequestBody String text) {
return textClassifier.classifyClassDescriptions(text);
}

@PostMapping("/classify/few-shots-prompt")
String classifyFewShotsPrompt(@RequestBody String input) {
return textClassifier.classifyFewShotsPrompt(input);
String classifyFewShotsPrompt(@RequestBody String text) {
return textClassifier.classifyFewShotsPrompt(text);
}

@PostMapping("/classify/few-shots-history")
String classifyFewShotsHistory(@RequestBody String input) {
return textClassifier.classifyFewShotsHistory(input);
String classifyFewShotsHistory(@RequestBody String text) {
return textClassifier.classifyFewShotsHistory(text);
}

@PostMapping("/classify/structured-output")
ClassificationType classifyStructured(@RequestBody String input) {
return textClassifier.classifyStructured(input);
ClassificationType classifyStructured(@RequestBody String text) {
return textClassifier.classifyStructured(text);
}

@PostMapping("/classify")
ClassificationType classify(@RequestBody String text) {
return textClassifier.classifyStructured(text);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ String classifyClassDescriptions(String text) {
BUSINESS: Financial markets, economic trends, company acquisitions.
SPORT: Sport events, teams, players, tournaments, and statistics.
TECHNOLOGY: Technological advancements, innovations, software product launches.
TECHNOLOGY: Technological advancements, innovations, launches of new apps.
OTHER: Anything that doesn't fit into the other categories.
""")
.user(text)
Expand All @@ -64,7 +64,7 @@ String classifyFewShotsPrompt(String text) {
Text: The semifinals of the UEFA Euro 2024 will be played on Saturday.
Class: SPORT
Text: Apple announced the new version of their operating system.
Text: Football fan? You can now watch the UEFA Euro games on the brand-new app for Apple Vision Pro.
Class: TECHNOLOGY
Text: The Ravenclaw Quidditch team won the tournament!
Expand Down Expand Up @@ -101,7 +101,7 @@ private List<Message> getPromptWithFewShotsHistory(String text) {
new AssistantMessage("BUSINESS"),
new UserMessage("The semifinals of the UEFA Euro 2024 will be played on Saturday."),
new AssistantMessage("SPORT"),
new UserMessage("Apple announced the new version of their operating system."),
new UserMessage("Football fan? You can now watch the UEFA Euro games on the brand-new app for Apple Vision Pro."),
new AssistantMessage("TECHNOLOGY"),
new UserMessage("The Ravenclaw Quidditch team won the tournament!"),
new AssistantMessage("OTHER"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ spring:
chat:
options:
model: mistral
threads:
virtual:
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ void classifyTechnologyNews() {
assertThat(classificationType).isEqualTo(ClassificationType.TECHNOLOGY);
}

@Test
void classifyOtherNews() {
var classificationType = textClassifier.classifyStructured(
"They're taking the hobbits to Isengard! To Isengard! To Isengard!");
assertThat(classificationType).isEqualTo(ClassificationType.OTHER);
}

}
2 changes: 2 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ repositories {
ext {
set("springBootVersion", '3.3.0')
set("dependencyManagementVersion", '1.1.5')
set("graalvmVersion", '0.10.2')
}

dependencies {
implementation "io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}"
implementation "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
implementation "org.graalvm.buildtools:native-gradle-plugin:${graalvmVersion}"
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
springAiVersion=1.0.0-M1
springAiVersion=1.0.0-SNAPSHOT
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down

0 comments on commit 374c042

Please sign in to comment.