๐ Introduction to Simple-OpenAI
Simple-OpenAI is a Java library that facilitates the interaction with the OpenAI API, designed for simplicity and ease of use. With the help of this library, Java developers can seamlessly integrate OpenAI's capabilities into their applications. Whether it's generating text, creating images, or working with speech, Simple-OpenAI provides a straightforward interface to OpenAI's diverse set of services.
๐ก Description
Simple-OpenAI serves as a Java HTTP client library, enabling developers to send and receive requests to/from the OpenAI API. Not officially affiliated with OpenAI, this library offers a uniform interface akin to Python or NodeJs libraries. It minimizes boilerplate code using CleverClient for HTTP communication, Jackson for JSON parsing, and Lombok among other support libraries.
โ Supported Services
This library stays current with OpenAI's evolving features and supports the following services:
- Audio: Speech synthesis, transcription, and translation.
- Chat Completion: Advanced text generation, streaming, and integration with vision or audio.
- Image: Generation, editing, and providing variations.
- Embedded Text: Vector representation of text.
- File Management: File uploads and processing.
- Fine Tuning: Model customization.
- Moderation: Text moderation services.
- Assistant: Conversational agents and interactions.
The library functions asynchronously, using CompletableFuture
for handling response objects.
โ Installation
Integrating Simple-OpenAI into your project is straightforward. For Maven projects, add the following dependency:
<dependency>
<groupId>io.github.sashirestela</groupId>
<artifactId>simple-openai</artifactId>
<version>[latest version]</version>
</dependency>
For Gradle users, include:
dependencies {
implementation 'io.github.sashirestela:simple-openai:[latest version]'
}
๐ Usage
Here's how to get started with Simple-OpenAI:
Creating a SimpleOpenAI Object
The initial step involves creating a SimpleOpenAI instance. You'll need to provide your OpenAI API Key, as shown below:
var openAI = SimpleOpenAI.builder()
.apiKey(System.getenv("OPENAI_API_KEY"))
.build();
Optionally, you can provide additional parameters like the organization ID or project ID for more targeted use cases. Custom configurations, such as using a personal HTTP client with specific settings, can also be applied.
Examples of Use
- Audio Example: Convert text to audio and handle binary data.
- Image Example: Generate images from text prompts.
- Chat Completion Example: Engage in text-based conversations or handle structured outputs using functions or vision.
Additional Functionality
Simple-OpenAI also supports other providers, such as Azure OpenAI and Anyscale, for extended service compatibility.
Conclusion
Simple-OpenAI opens up a pathway to integrate powerful AI functionalities into Java applications with minimal complexity. Whether itโs engaging users with conversational agents, generating creative content, or processing speech, this library brings OpenAI's robust AI toolset to Java developers in the simplest form possible.