Skip to content

Commit

Permalink
Rename chatjpt to jvm-openai
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jan 12, 2024
1 parent 187958d commit f363416
Show file tree
Hide file tree
Showing 69 changed files with 135 additions and 134 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ChatJPT
# jvm-openai

[![build](https://github.com/StefanBratanov/chatjpt/actions/workflows/build.yml/badge.svg)](https://github.com/StefanBratanov/chatjpt/actions/workflows/build.yml)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.stefanbratanov/chatjpt)](https://central.sonatype.com/artifact/io.github.stefanbratanov/chatjpt)
[![javadoc](https://javadoc.io/badge2/io.github.stefanbratanov/chatjpt/javadoc.svg)](https://javadoc.io/doc/io.github.stefanbratanov/chatjpt)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=StefanBratanov_chatjpt&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=StefanBratanov_chatjpt)
[![build](https://github.com/StefanBratanov/jvm-openai/actions/workflows/build.yml/badge.svg)](https://github.com/StefanBratanov/jvm-openai/actions/workflows/build.yml)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.stefanbratanov/jvm-openai)](https://central.sonatype.com/artifact/io.github.stefanbratanov/jvm-openai)
[![javadoc](https://javadoc.io/badge2/io.github.stefanbratanov/jvm-openai/javadoc.svg)](https://javadoc.io/doc/io.github.stefanbratanov/jvm-openai)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=StefanBratanov_jvm-openai&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=StefanBratanov_jvm-openai)

A minimalistic unofficial Java client for the [OpenAI API](https://platform.openai.com/docs/api-reference)
A minimalistic unofficial JVM client for the [OpenAI API](https://platform.openai.com/docs/api-reference) written in Java

## Add dependency

Expand All @@ -14,34 +14,34 @@ Java 17+ is a prerequisite
#### Gradle

```groovy
implementation("io.github.stefanbratanov:chatjpt:${version}")
implementation("io.github.stefanbratanov:jvm-openai:${version}")
```

#### Maven

F
```xml

<dependency>
<groupId>io.github.stefanbratanov</groupId>
<artifactId>chatjpt</artifactId>
<artifactId>jvm-openai</artifactId>
<version>${version}</version>
</dependency>
```

## Minimal sample

```java
ChatJPT chatJPT = ChatJPT.newBuilder(System.getenv("OPENAI_API_KEY")).build();
OpenAI openAI = OpenAI.newBuilder(System.getenv("OPENAI_API_KEY")).build();

ChatClient chatClient = chatJPT.chatClient();
ChatClient chatClient = openAI.chatClient();
ChatRequest chatRequest = ChatRequest.newBuilder()
.model("gpt-3.5-turbo")
.message(ChatMessage.userMessage("Who won the world series in 2020?"))
.build();
ChatResponse response = chatClient.sendRequest(chatRequest);
// ChatResponse[id=chatcmpl-123, created=1703506594, model=gpt-3.5-turbo-0613, systemFingerprint=fp_44709d6fcb, choices=[Choice[index=0, message=Message[content=The Los Angeles Dodgers won the World Series in 2020., toolCalls=null, role=assistant], logProbs=null, finishReason=stop]], usage=Usage[promptTokens=17, completionTokens=13, totalTokens=30]]

ImagesClient imagesClient = chatJPT.imagesClient();
ImagesClient imagesClient = openAI.imagesClient();
CreateImageRequest createImageRequest = CreateImageRequest.newBuilder()
.model("dall-e-3")
.prompt("A cute baby sea otter")
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ publishing {
from components.java

pom {
name = "ChatJPT"
description = "A minimalistic Java client for the OpenAI API"
url = "https://github.com/StefanBratanov/chatjpt"
name = "jvm-openai"
description = "A minimalistic JVM client for the OpenAI API written in Java"
url = "https://github.com/StefanBratanov/jvm-openai"
licenses {
license {
name = "The Apache License, Version 2.0"
Expand All @@ -66,9 +66,9 @@ publishing {
}
}
scm {
connection = "scm:git:git://github.com/StefanBratanov/chatjpt.git"
developerConnection = "scm:git:ssh://github.com/StefanBratanov/chatjpt.git"
url = "https://github.com/StefanBratanov/chatjpt"
connection = "scm:git:git://github.com/StefanBratanov/jvm-openai.git"
developerConnection = "scm:git:ssh://github.com/StefanBratanov/jvm-openai.git"
url = "https://github.com/StefanBratanov/jvm-openai"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = "chatjpt"
rootProject.name = "jvm-openai"

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

/** A list of Files attached to an assistant. */
public record AssistantFile(String id, long createdAt, String assistantId) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.stefanbratanov.chatjpt.ChatMessage.UserMessage.UserMessageWithContentParts;
import io.github.stefanbratanov.chatjpt.ChatMessage.UserMessage.UserMessageWithContentParts.ContentPart;
import io.github.stefanbratanov.chatjpt.ChatMessage.UserMessage.UserMessageWithTextContent;
import io.github.stefanbratanov.jvm.openai.ChatMessage.UserMessage.UserMessageWithContentParts;
import io.github.stefanbratanov.jvm.openai.ChatMessage.UserMessage.UserMessageWithContentParts.ContentPart;
import io.github.stefanbratanov.jvm.openai.ChatMessage.UserMessage.UserMessageWithTextContent;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

class Constants {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.LinkedList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.nio.file.Path;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.LinkedList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

public record DeletionStatus(String id, boolean deleted) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.nio.file.Path;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

enum Endpoint {
CHAT("chat/completions"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

public record File(String id, int bytes, long createdAt, String filename, String purpose) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

public record FineTuningJobEvent(String id, long createdAt, String level, String message) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.net.URL;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

public record Model(String id, long created, String ownedBy) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.LinkedList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.LinkedList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
Expand All @@ -14,7 +14,7 @@
* based on the endpoints defined at <a href="https://platform.openai.com/docs/api-reference">API
* Reference - OpenAI API</a>
*/
public final class ChatJPT {
public final class OpenAI {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

Expand All @@ -38,8 +38,7 @@ public final class ChatJPT {
private final MessagesClient messagesClient;
private final RunsClient runsClient;

private ChatJPT(
URI baseUrl, String apiKey, Optional<String> organization, HttpClient httpClient) {
private OpenAI(URI baseUrl, String apiKey, Optional<String> organization, HttpClient httpClient) {
audioClient = new AudioClient(baseUrl, apiKey, organization, httpClient, OBJECT_MAPPER);
chatClient = new ChatClient(baseUrl, apiKey, organization, httpClient, OBJECT_MAPPER);
embeddingsClient =
Expand Down Expand Up @@ -201,11 +200,11 @@ public Builder httpClient(HttpClient httpClient) {
return this;
}

public ChatJPT build() {
public OpenAI build() {
if (!baseUrl.endsWith("/")) {
baseUrl += "/";
}
return new ChatJPT(
return new OpenAI(
URI.create(baseUrl),
apiKey,
organization,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.stefanbratanov.chatjpt;
package io.github.stefanbratanov.jvm.openai;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.http.HttpClient;
Expand Down
Loading

0 comments on commit f363416

Please sign in to comment.