openai-java  by TheoKanning

Java SDK for OpenAI APIs (GPT-3, ChatGPT, GPT-4)

created 4 years ago
4,791 stars

Top 10.6% on sourcepulse

GitHubView on GitHub
Project Summary

This Java library provides a client for interacting with OpenAI's GPT APIs, including GPT-3, ChatGPT, and GPT-4. It offers data classes for API requests/responses, a Retrofit-based client, and a simplified service class for ease of use, targeting Java developers building applications that leverage OpenAI's language models.

How It Works

The project is structured into three Maven artifacts: api for POJOs, client for a Retrofit client, and service for a high-level abstraction. The service module simplifies interactions by providing an OpenAiService class that handles request building and API calls. It supports features like function calling via FunctionExecutor, allowing developers to define and integrate custom Java functions with OpenAI's models.

Quick Start & Requirements

  • Install: Use Gradle or Maven dependency management.
  • Prerequisites: Java, OpenAI API key.
  • Usage:
    • implementation 'com.theokanning.openai-gpt3-java:service:<version>'
    • OpenAiService service = new OpenAiService("your_token");
  • Examples: ./gradlew runExampleOne, ./gradlew runExampleTwo (functions), ./gradlew runExampleThree (functions with stream).

Highlighted Details

  • Supports Completions, Chat Completions, Edits, Embeddings, Audio, Files, Fine-tuning, Images, Moderations, and Assistants APIs.
  • Includes robust support for OpenAI's function calling feature.
  • Provides customization options for the Retrofit client, including logging and proxy support.
  • Offers streaming capabilities for responses.

Maintenance & Community

This project is no longer maintained and was archived on June 6th, 2024. The repository remains available for forking and modification.

Licensing & Compatibility

Published under the MIT License. This license permits commercial use and integration with closed-source projects.

Limitations & Caveats

The project is archived and will not receive further updates. OpenAI has deprecated engine-based APIs, and while the library includes instructions for upgrading, it may not fully align with future OpenAI API changes.

Health Check
Last commit

1 year ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
0
Star History
26 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.