openai4j  by Lambdua

Java client library for OpenAI API

created 1 year ago
403 stars

Top 73.0% on sourcepulse

GitHubView on GitHub
Project Summary

This Java library, openai4j, provides a comprehensive client for interacting with the OpenAI API, targeting Java developers who need to integrate advanced AI capabilities into their applications. It offers full support for all OpenAI models and features, including chat, vision, audio, and the latest Assistants API, simplifying complex API interactions with an easy-to-use interface.

How It Works

Built upon Retrofit, openai4j facilitates seamless API communication. It supports both synchronous and asynchronous calls, allowing developers to choose the interaction pattern that best suits their application's needs. The library emphasizes flexibility, enabling customization of the OpenAiService with custom HTTP clients, interceptors, and base URLs, including support for environment variable configuration of API keys and base URLs.

Quick Start & Requirements

  • Install:
    • Gradle: implementation 'io.github.lambdua:service:0.22.92'
    • Maven:
      <dependency>
          <groupId>io.github.lambdua</groupId>
          <artifactId>service</artifactId>
          <version>0.22.92</version>
      </dependency>
      
  • Prerequisites: Java, OpenAI API Key (recommended via OPENAI_API_KEY environment variable).
  • Documentation: Examples are available in the example package.

Highlighted Details

  • Full support for OpenAI API models: Completions, Chat, Edits, Embeddings, Audio, Files, Assistants-v2, Images, Moderations, Batch, and Fine-tuning.
  • Supports OpenAI's Assistants API, including streaming responses and tool usage.
  • Enables function calling and tool integration for advanced AI workflows.
  • Provides flexible configuration options for OpenAiService, including custom timeouts and HTTP clients.

Maintenance & Community

The project is a fork of TheoKanning/openai-java and aims to incorporate the latest API features. Contributions are welcomed via GitHub Issues and Pull Requests.

Licensing & Compatibility

Released under the MIT License, permitting commercial use and integration with closed-source applications.

Limitations & Caveats

The library is marked as unofficial. While it aims for comprehensive coverage, users should verify compatibility with the latest OpenAI API specifications.

Health Check
Last commit

1 month ago

Responsiveness

1 day

Pull Requests (30d)
1
Issues (30d)
1
Star History
15 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.