Skip to content

Java client library for OpenAI API, generated using openai-generator with modifications to the official spec for error-free generation and functionality

Notifications You must be signed in to change notification settings

ainoya/openai-java-generated-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI API Java Client generated from OpenAPI specification with openapi-generator

Release

How to build

./generate-api-client.sh vXX.XX.XX

Overview

This repository contains a Java client library for the OpenAI API, generated using the OpenAPI Generator tool. The library is based on the official OpenAPI specification provided by OpenAI, which can be found at openai/openai-openapi.

Motivation

While attempting to generate the client library directly from the official OpenAPI spec file, several issues were encountered, primarily due to certain syntax elements like oneOf that led to generation errors. To overcome these challenges, modifications were made to the original spec file to ensure successful client generation and functional integrity of the resulting Java client.

Modifications and Testing

Several definitions in the spec file that caused errors during generation were identified and rectified. This included, but was not limited to, addressing issues with oneOf syntax. It is important to note that these modifications might have led to some original parameters becoming unavailable. For transparency and comparison, the original API spec has been saved as openapi.orig.yaml, and the modified file used for generation is openapi.yaml.

To view the specific changes made, you can use the command: diff -Nru openapi.yaml openapi.orig.yaml.

All automatically generated tests have been run and passed, ensuring the reliability of the modified spec.

Ongoing Verification

It is acknowledged that with a better understanding of the openapi-generator options, it might be possible to generate the client from the original spec without modifications. This aspect is currently under continuous review and exploration.

Usage and Contribution

We encourage users and developers to contribute to this repository, especially in improving the generation process and enhancing the library. Any updates or fixes that enable the use of the original spec file without modifications would be particularly valuable.

Disclaimer

This client library is an independent effort and is not officially affiliated with OpenAI. Users should exercise due diligence and refer to OpenAI's official documentation and API guidelines for accurate information.


openai-java-generated-client

OpenAI API

  • API version: 2.3.0

    • Build date: 2024-10-30T01:20:46.396706715Z[Etc/UTC]

The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.

For more information, please visit [https://help.openai.com/](https://help.openai.com/)

Automatically generated by the OpenAPI Generator

Requirements

Building the API client library requires:

  1. Java 1.8+ 2. Maven/Gradle

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
    <groupId>com.github.ainoya</groupId>
    <artifactId>openai-java-generated-client</artifactId>
    <version>0.0.30</version>
    <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

repositories {
mavenCentral()     // Needed if the 'openai-java-generated-client' jar has been published to maven central.
mavenLocal()       // Needed if the 'openai-java-generated-client' jar has been published to the local maven repo.
}

dependencies {
implementation "com.github.ainoya:openai-java-generated-client:0.0.30"
}

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/openai-java-generated-client-0.0.30.jar
  • target/lib/*.jar

Getting Started

Please follow the installation instruction and execute the following Java code:

    import com.github.ainoya.client.*;
    import com.github.ainoya.client.auth.*;
    import com.github.ainoya.client.model.*;
    import com.github.ainoya.openai.client.api.AssistantsApi;

    public class AssistantsApiExample {

    public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://api.openai.com/v1");
    
        // Configure HTTP bearer authorization: ApiKeyAuth
        HttpBearerAuth ApiKeyAuth = (HttpBearerAuth) defaultClient.getAuthentication("ApiKeyAuth");
        ApiKeyAuth.setBearerToken("BEARER TOKEN");

    AssistantsApi apiInstance = new AssistantsApi(defaultClient);
        String threadId = "threadId_example"; // String | The ID of the thread to which this run belongs.
        String runId = "runId_example"; // String | The ID of the run to cancel.
    try {
    RunObject result = apiInstance.cancelRun(threadId, runId);
        System.out.println(result);
    } catch (ApiException e) {
    System.err.println("Exception when calling AssistantsApi#cancelRun");
    System.err.println("Status code: " + e.getCode());
    System.err.println("Reason: " + e.getResponseBody());
    System.err.println("Response headers: " + e.getResponseHeaders());
    e.printStackTrace();
    }
    }
    }

Documentation for API Endpoints

All URIs are relative to https://api.openai.com/v1

Class Method HTTP request Description
AssistantsApi cancelRun POST /threads/{thread_id}/runs/{run_id}/cancel Cancels a run that is `in_progress`.
AssistantsApi createAssistant POST /assistants Create an assistant with a model and instructions.
AssistantsApi createMessage POST /threads/{thread_id}/messages Create a message.
AssistantsApi createRun POST /threads/{thread_id}/runs Create a run.
AssistantsApi createThread POST /threads Create a thread.
AssistantsApi createThreadAndRun POST /threads/runs Create a thread and run it in one request.
AssistantsApi deleteAssistant DELETE /assistants/{assistant_id} Delete an assistant.
AssistantsApi deleteMessage DELETE /threads/{thread_id}/messages/{message_id} Deletes a message.
AssistantsApi deleteThread DELETE /threads/{thread_id} Delete a thread.
AssistantsApi getAssistant GET /assistants/{assistant_id} Retrieves an assistant.
AssistantsApi getMessage GET /threads/{thread_id}/messages/{message_id} Retrieve a message.
AssistantsApi getRun GET /threads/{thread_id}/runs/{run_id} Retrieves a run.
AssistantsApi getRunStep GET /threads/{thread_id}/runs/{run_id}/steps/{step_id} Retrieves a run step.
AssistantsApi getThread GET /threads/{thread_id} Retrieves a thread.
AssistantsApi listAssistants GET /assistants Returns a list of assistants.
AssistantsApi listMessages GET /threads/{thread_id}/messages Returns a list of messages for a given thread.
AssistantsApi listRunSteps GET /threads/{thread_id}/runs/{run_id}/steps Returns a list of run steps belonging to a run.
AssistantsApi listRuns GET /threads/{thread_id}/runs Returns a list of runs belonging to a thread.
AssistantsApi modifyAssistant POST /assistants/{assistant_id} Modifies an assistant.
AssistantsApi modifyMessage POST /threads/{thread_id}/messages/{message_id} Modifies a message.
AssistantsApi modifyRun POST /threads/{thread_id}/runs/{run_id} Modifies a run.
AssistantsApi modifyThread POST /threads/{thread_id} Modifies a thread.
AssistantsApi submitToolOuputsToRun POST /threads/{thread_id}/runs/{run_id}/submit_tool_outputs When a run has the `status: &quot;requires_action&quot;` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.
AudioApi createSpeech POST /audio/speech Generates audio from the input text.
AudioApi createTranscription POST /audio/transcriptions Transcribes audio into the input language.
AudioApi createTranslation POST /audio/translations Translates audio into English.
AuditLogsApi listAuditLogs GET /organization/audit_logs List user actions and configuration changes within this organization.
BatchApi cancelBatch POST /batches/{batch_id}/cancel Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file.
BatchApi createBatch POST /batches Creates and executes a batch from an uploaded file of requests
BatchApi listBatches GET /batches List your organization's batches.
BatchApi retrieveBatch GET /batches/{batch_id} Retrieves a batch.
ChatApi createChatCompletion POST /chat/completions Creates a model response for the given chat conversation. Learn more in the text generation, vision, and audio guides.
CompletionsApi createCompletion POST /completions Creates a completion for the provided prompt and parameters.
EmbeddingsApi createEmbedding POST /embeddings Creates an embedding vector representing the input text.
FilesApi createFile POST /files Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. The Assistants API supports files up to 2 million tokens and of specific file types. See the Assistants Tools guide for details. The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for fine-tuning chat or completions models. The Batch API only supports `.jsonl` files up to 100 MB in size. The input also has a specific required format. Please contact us if you need to increase these storage limits.
FilesApi deleteFile DELETE /files/{file_id} Delete a file.
FilesApi downloadFile GET /files/{file_id}/content Returns the contents of the specified file.
FilesApi listFiles GET /files Returns a list of files that belong to the user's organization.
FilesApi retrieveFile GET /files/{file_id} Returns information about a specific file.
FineTuningApi cancelFineTuningJob POST /fine_tuning/jobs/{fine_tuning_job_id}/cancel Immediately cancel a fine-tune job.
FineTuningApi createFineTuningJob POST /fine_tuning/jobs Creates a fine-tuning job which begins the process of creating a new model from a given dataset. Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. Learn more about fine-tuning
FineTuningApi listFineTuningEvents GET /fine_tuning/jobs/{fine_tuning_job_id}/events Get status updates for a fine-tuning job.
FineTuningApi listFineTuningJobCheckpoints GET /fine_tuning/jobs/{fine_tuning_job_id}/checkpoints List checkpoints for a fine-tuning job.
FineTuningApi listPaginatedFineTuningJobs GET /fine_tuning/jobs List your organization's fine-tuning jobs
FineTuningApi retrieveFineTuningJob GET /fine_tuning/jobs/{fine_tuning_job_id} Get info about a fine-tuning job. Learn more about fine-tuning
ImagesApi createImage POST /images/generations Creates an image given a prompt.
ImagesApi createImageEdit POST /images/edits Creates an edited or extended image given an original image and a prompt.
ImagesApi createImageVariation POST /images/variations Creates a variation of a given image.
InvitesApi deleteInvite DELETE /organization/invites/{invite_id} Delete an invite. If the invite has already been accepted, it cannot be deleted.
InvitesApi inviteUser POST /organization/invites Create an invite for a user to the organization. The invite must be accepted by the user before they have access to the organization.
InvitesApi listInvites GET /organization/invites Returns a list of invites in the organization.
InvitesApi retrieveInvite GET /organization/invites/{invite_id} Retrieves an invite.
ModelsApi deleteModel DELETE /models/{model} Delete a fine-tuned model. You must have the Owner role in your organization to delete a model.
ModelsApi listModels GET /models Lists the currently available models, and provides basic information about each one such as the owner and availability.
ModelsApi retrieveModel GET /models/{model} Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
ModerationsApi createModeration POST /moderations Classifies if text and/or image inputs are potentially harmful. Learn more in the moderation guide.
ProjectsApi archiveProject POST /organization/projects/{project_id}/archive Archives a project in the organization. Archived projects cannot be used or updated.
ProjectsApi createProject POST /organization/projects Create a new project in the organization. Projects can be created and archived, but cannot be deleted.
ProjectsApi createProjectServiceAccount POST /organization/projects/{project_id}/service_accounts Creates a new service account in the project. This also returns an unredacted API key for the service account.
ProjectsApi createProjectUser POST /organization/projects/{project_id}/users Adds a user to the project. Users must already be members of the organization to be added to a project.
ProjectsApi deleteProjectApiKey DELETE /organization/projects/{project_id}/api_keys/{key_id} Deletes an API key from the project.
ProjectsApi deleteProjectServiceAccount DELETE /organization/projects/{project_id}/service_accounts/{service_account_id} Deletes a service account from the project.
ProjectsApi deleteProjectUser DELETE /organization/projects/{project_id}/users/{user_id} Deletes a user from the project.
ProjectsApi listProjectApiKeys GET /organization/projects/{project_id}/api_keys Returns a list of API keys in the project.
ProjectsApi listProjectServiceAccounts GET /organization/projects/{project_id}/service_accounts Returns a list of service accounts in the project.
ProjectsApi listProjectUsers GET /organization/projects/{project_id}/users Returns a list of users in the project.
ProjectsApi listProjects GET /organization/projects Returns a list of projects.
ProjectsApi modifyProject POST /organization/projects/{project_id} Modifies a project in the organization.
ProjectsApi modifyProjectUser POST /organization/projects/{project_id}/users/{user_id} Modifies a user's role in the project.
ProjectsApi retrieveProject GET /organization/projects/{project_id} Retrieves a project.
ProjectsApi retrieveProjectApiKey GET /organization/projects/{project_id}/api_keys/{key_id} Retrieves an API key in the project.
ProjectsApi retrieveProjectServiceAccount GET /organization/projects/{project_id}/service_accounts/{service_account_id} Retrieves a service account in the project.
ProjectsApi retrieveProjectUser GET /organization/projects/{project_id}/users/{user_id} Retrieves a user in the project.
UploadsApi addUploadPart POST /uploads/{upload_id}/parts Adds a Part to an Upload object. A Part represents a chunk of bytes from the file you are trying to upload. Each Part can be at most 64 MB, and you can add Parts until you hit the Upload maximum of 8 GB. It is possible to add multiple Parts in parallel. You can decide the intended order of the Parts when you complete the Upload.
UploadsApi cancelUpload POST /uploads/{upload_id}/cancel Cancels the Upload. No Parts may be added after an Upload is cancelled.
UploadsApi completeUpload POST /uploads/{upload_id}/complete Completes the Upload. Within the returned Upload object, there is a nested File object that is ready to use in the rest of the platform. You can specify the order of the Parts by passing in an ordered list of the Part IDs. The number of bytes uploaded upon completion must match the number of bytes initially specified when creating the Upload object. No Parts may be added after an Upload is completed.
UploadsApi createUpload POST /uploads Creates an intermediate Upload object that you can add Parts to. Currently, an Upload can accept at most 8 GB in total and expires after an hour after you create it. Once you complete the Upload, we will create a File object that contains all the parts you uploaded. This File is usable in the rest of our platform as a regular File object. For certain `purpose`s, the correct `mime_type` must be specified. Please refer to documentation for the supported MIME types for your use case: - Assistants For guidance on the proper filename extensions for each purpose, please follow the documentation on creating a File.
UsersApi deleteUser DELETE /organization/users/{user_id} Deletes a user from the organization.
UsersApi listUsers GET /organization/users Lists all of the users in the organization.
UsersApi modifyUser POST /organization/users/{user_id} Modifies a user's role in the organization.
UsersApi retrieveUser GET /organization/users/{user_id} Retrieves a user by their identifier.
VectorStoresApi cancelVectorStoreFileBatch POST /vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible.
VectorStoresApi createVectorStore POST /vector_stores Create a vector store.
VectorStoresApi createVectorStoreFile POST /vector_stores/{vector_store_id}/files Create a vector store file by attaching a File to a vector store.
VectorStoresApi createVectorStoreFileBatch POST /vector_stores/{vector_store_id}/file_batches Create a vector store file batch.
VectorStoresApi deleteVectorStore DELETE /vector_stores/{vector_store_id} Delete a vector store.
VectorStoresApi deleteVectorStoreFile DELETE /vector_stores/{vector_store_id}/files/{file_id} Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. To delete the file, use the delete file endpoint.
VectorStoresApi getVectorStore GET /vector_stores/{vector_store_id} Retrieves a vector store.
VectorStoresApi getVectorStoreFile GET /vector_stores/{vector_store_id}/files/{file_id} Retrieves a vector store file.
VectorStoresApi getVectorStoreFileBatch GET /vector_stores/{vector_store_id}/file_batches/{batch_id} Retrieves a vector store file batch.
VectorStoresApi listFilesInVectorStoreBatch GET /vector_stores/{vector_store_id}/file_batches/{batch_id}/files Returns a list of vector store files in a batch.
VectorStoresApi listVectorStoreFiles GET /vector_stores/{vector_store_id}/files Returns a list of vector store files.
VectorStoresApi listVectorStores GET /vector_stores Returns a list of vector stores.
VectorStoresApi modifyVectorStore POST /vector_stores/{vector_store_id} Modifies a vector store.

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API: ### ApiKeyAuth

    - **Type**: HTTP Bearer Token authentication

Recommendation

It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.

Author

About

Java client library for OpenAI API, generated using openai-generator with modifications to the official spec for error-free generation and functionality

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages