OJA is an open-source Java library designed to simplify the integration of OpenAI's API into Java environments. It allows developers to easily use OpenAI's AI models for tasks like chat completions, embeddings and moderation.
Since OJA is currently not available on Maven Central, you will need to specify a custom repository. Apart from that, OJA can be integrated into your software just like any other package using Gradle or Maven.
<repository>
<id>lookforfps</id>
<url>https://repo.lookforfps.dev/repository/maven-public</url>
</repository>
<dependency>
<groupId>me.lookforfps</groupId>
<artifactId>OJA</artifactId>
<version>version</version>
</dependency>
repositories {
maven {
url "https://repo.lookforfps.dev/repository/maven-public"
}
}
dependencies {
implementation("me.lookforfps:OJA:version")
}
Alternatively, you can download the project from the repository and build it yourself using Gradle.
First, we build a ChatCompletionService
according to our needs.
Next, we add a system message with some instructions and a user message to the context.
After that, we send the request to OpenAI.
ChatCompletionService service = ChatCompletionService.build("put$your#api%token§here", ChatCompletionModel.GPT_4_O_MINI.getIdentifier());
service.addMessage(new SystemMessage("You are an Assistant named Sarah."));
service.addMessage(new UserMessage("What is the biggest City in the world?"));
ChatCompletionResponse response = service.sendRequest();
System.out.println("Answer: "+response.getTextContent());
First, we build a EmbeddingService
according to our needs.
Then we send the request with the content we wish to convert into embeddings.
EmbeddingService service = EmbeddingService.build("put$your#api%token§here", EmbeddingModel.TEXT_EMBEDDING_3_LARGE.getIdentifier());
EmbeddingResponse response = service.sendRequest("something you want to convert");
System.out.println("Embedding: "+response.getFloatEmbedding());
First, we build a ModerationService
according to our needs.
Then we send the request with the content we want to moderate.
ModerationService service = ModerationService.build("put$your#api%token§here");
ModerationResponse response = service.sendRequest("content you want to check for moderation rules");
System.out.println("Flagged: "+response.getResult().getFlagged());
Due to the extensive range of core features that we will be offering, providing a detailed documentation within the repository's README alone is not possible. To ensure that each feature is completely and clearly explained, we have created a dedicated wiki page. This resource will provide detailed and structured explanations for all features, allowing for a more in-depth understanding and easier navigation.
OJA is licensed under the MIT License. For more information, see the LICENSE.md
file in the project repository.