-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c092adf
commit 3034c1a
Showing
16 changed files
with
270 additions
and
215 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
...ses/classification/src/main/java/com/thomasvitale/ai/spring/ClassificationController.java
This file was deleted.
Oops, something went wrong.
106 changes: 0 additions & 106 deletions
106
...-cases/classification/src/main/java/com/thomasvitale/ai/spring/ClassificationService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Text Classification | ||
|
||
Text classification with LLMs via Ollama. | ||
|
||
## Running the application | ||
|
||
The application relies on Ollama for providing LLMs. You can either run Ollama locally on your laptop, or rely on the Testcontainers support in Spring Boot to spin up an Ollama service automatically. | ||
|
||
### Ollama as a native application | ||
|
||
First, make sure you have [Ollama](https://ollama.ai) installed on your laptop. | ||
Then, use Ollama to pull the _mistral_ large language model. | ||
|
||
```shell | ||
ollama pull mistral | ||
``` | ||
|
||
Finally, run the Spring Boot application. | ||
|
||
```shell | ||
./gradlew bootRun | ||
``` | ||
|
||
### Ollama as a dev service with Testcontainers | ||
|
||
The application relies on the native Testcontainers support in Spring Boot to spin up an Ollama service with a _mistral_ model at startup time. | ||
|
||
```shell | ||
./gradlew bootTestRun | ||
``` | ||
|
||
## Calling the application | ||
|
||
You can now call the application that will use Ollama and _mistral_ to classify your text. | ||
This example uses [httpie](https://httpie.io) to send HTTP requests. | ||
|
||
Each endpoint is backed by a progressively better prompt to increase the quality of the text classification task by the LLM. | ||
|
||
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 | ||
``` | ||
|
||
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 | ||
``` | ||
|
||
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 | ||
``` | ||
|
||
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 | ||
``` | ||
|
||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ext-classification/src/main/java/com/thomasvitale/ai/spring/ClassificationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.thomasvitale.ai.spring; | ||
|
||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
class ClassificationController { | ||
|
||
private final TextClassifier textClassifier; | ||
|
||
ClassificationController(TextClassifier textClassifier) { | ||
this.textClassifier = textClassifier; | ||
} | ||
|
||
@PostMapping("/classify/class-names") | ||
String classifyClassNames(@RequestBody String text) { | ||
return textClassifier.classifyClassNames(text); | ||
} | ||
|
||
@PostMapping("/classify/class-descriptions") | ||
String classifyClassDescriptions(@RequestBody String input) { | ||
return textClassifier.classifyClassDescriptions(input); | ||
} | ||
|
||
@PostMapping("/classify/few-shots-prompt") | ||
String classifyFewShotsPrompt(@RequestBody String input) { | ||
return textClassifier.classifyFewShotsPrompt(input); | ||
} | ||
|
||
@PostMapping("/classify/few-shots-history") | ||
String classifyFewShotsHistory(@RequestBody String input) { | ||
return textClassifier.classifyFewShotsHistory(input); | ||
} | ||
|
||
@PostMapping("/classify/structured-output") | ||
ClassificationType classifyStructured(@RequestBody String input) { | ||
return textClassifier.classifyStructured(input); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...svitale/ai/spring/ClassificationType.java → ...svitale/ai/spring/ClassificationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.thomasvitale.ai.spring; | ||
|
||
public enum ClassificationType { | ||
BOOK, MUSIC, UNKNOWN; | ||
BUSINESS, SPORT, TECHNOLOGY, OTHER; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.