Delete all lombok from project and build as JDK version 11

This commit is contained in:
YuCheng Hu 2023-01-06 13:20:51 -05:00
parent f63a2438dc
commit 062798c73a
28 changed files with 259 additions and 501 deletions

View File

@ -1,77 +0,0 @@
![Maven Central](https://img.shields.io/maven-central/v/com.theokanning.openai-gpt3-java/client?color=blue)
> ⚠The [Answers](https://help.openai.com/en/articles/6233728-answers-transition-guide),
>[Classifications](https://help.openai.com/en/articles/6272941-classifications-transition-guide),
>and [Searches](https://help.openai.com/en/articles/6272952-search-transition-guide) APIs are deprecated,
>and will stop working on December 3rd, 2022.
> ⚠OpenAI has deprecated all Engine-based APIs. See [Deprecated Endpoints](https://github.com/TheoKanning/openai-java#deprecated-endpoints) below for more info.
# OpenAI-Java
Java libraries for using OpenAI's GPT-3 api.
Includes the following artifacts:
- `api` : request/response POJOs for the GPT-3 engine, completion, and search APIs.
- `client` : a basic retrofit client for the GPT-3 endpoints, includes the `api` module
as well as an example project using the client.
## Supported APIs
- [Models](https://beta.openai.com/docs/api-reference/models)
- [Completions](https://beta.openai.com/docs/api-reference/completions)
- [Edits](https://beta.openai.com/docs/api-reference/edits)
- [Embeddings](https://beta.openai.com/docs/api-reference/embeddings)
- [Files](https://beta.openai.com/docs/api-reference/files)
- [Fine-tunes](https://beta.openai.com/docs/api-reference/fine-tunes)
- [Moderations](https://beta.openai.com/docs/api-reference/moderations)
#### Deprecated by OpenAI
- [Searches](https://beta.openai.com/docs/api-reference/searches)
- [Classifications](https://beta.openai.com/docs/api-reference/classifications)
- [Answers](https://beta.openai.com/docs/api-reference/answers)
- [Engines](https://beta.openai.com/docs/api-reference/engines)
## Usage
### Importing into a gradle project
`implementation 'com.theokanning.openai-gpt3-java:api:<version>'`
or
`implementation 'com.theokanning.openai-gpt3-java:client:<version>'`
### Using OpenAiService
If you're looking for the fastest solution, import the `client` and use [OpenAiService](client/src/main/java/com/theokanning/openai/OpenAiService.java).
```
OpenAiService service = new OpenAiService("your_token");
CompletionRequest completionRequest = CompletionRequest.builder()
.prompt("Somebody once told me the world is gonna roll me")
.model("ada")
.echo(true)
.build();
service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
```
### Using OpenAiApi Retrofit client
If you're using retrofit, you can import the `client` module and use the [OpenAiApi](client/src/main/java/com/theokanning/openai/OpenAiApi.java).
You'll have to add your auth token as a header (see [AuthenticationInterceptor](client/src/main/java/com/theokanning/openai/AuthenticationInterceptor.java))
and set your converter factory to use snake case and only include non-null fields.
### Using data classes only
If you want to make your own client, just import the POJOs from the `api` module.
Your client will need to use snake case to work with the OpenAI API.
## Running the example project
All the [example](example/src/main/java/example/OpenAiApiExample.java) project requires is your OpenAI api token
```
export OPENAI_TOKEN="sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
./gradlew example:run
```
## Deprecated Endpoints
OpenAI has deprecated engine-based endpoints in favor of model-based endpoints.
For example, instead of using `v1/engines/{engine_id}/completions`, switch to `v1/completions` and specify the model in the `CompletionRequest`.
The code includes upgrade instructions for all deprecated endpoints.
I won't remove the old endpoints from this library until OpenAI shuts them down.
## License
Published under the MIT License

View File

@ -1,21 +0,0 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.19.0'
}
}
allprojects {
repositories {
mavenCentral()
}
plugins.withId("com.vanniktech.maven.publish") {
mavenPublish {
sonatypeHost = "S01"
}
}
}

View File

@ -1,14 +0,0 @@
GROUP=com.theokanning.openai-gpt3-java
VERSION_NAME=0.8.1
POM_URL=https://github.com/theokanning/openai-java
POM_SCM_URL=https://github.com/theokanning/openai-java
POM_SCM_CONNECTION=https://github.com/theokanning/openai-java.git
POM_SCM_DEV_CONNECTION=https://github.com/theokanning/openai-java.git
POM_LICENSE_NAME=The MIT License
POM_LICENSE_URL=https://www.mit.edu/~amini/LICENSE.md
POM_LICENSE_DIST=repo
POM_DEVELOPER_ID=theokanning
POM_DEVELOPER_NAME=Theo Kanning

185
gradlew vendored
View File

@ -1,185 +0,0 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

104
gradlew.bat vendored
View File

@ -1,104 +0,0 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -11,6 +11,23 @@ import java.util.Map;
*/ */
public class CompletionRequest { public class CompletionRequest {
public CompletionRequest(String model, String prompt, Integer maxTokens, Double temperature, Double topP, Integer n, Boolean stream, Integer logprobs, Boolean echo, List<String> stop, Double presencePenalty, Double frequencyPenalty, Integer bestOf, Map<String, Integer> logitBias, String user) {
this.model = model;
this.prompt = prompt;
this.maxTokens = maxTokens;
this.temperature = temperature;
this.topP = topP;
this.n = n;
this.stream = stream;
this.logprobs = logprobs;
this.echo = echo;
this.stop = stop;
this.presencePenalty = presencePenalty;
this.frequencyPenalty = frequencyPenalty;
this.bestOf = bestOf;
this.logitBias = logitBias;
this.user = user;
}
/** /**
* The name of the model to use. * The name of the model to use.

View File

@ -10,6 +10,14 @@ import org.checkerframework.checker.nullness.qual.NonNull;
*/ */
public class EditRequest { public class EditRequest {
public EditRequest(String model, String input, @NonNull String instruction, Integer n, Double temperature, Double topP) {
this.model = model;
this.input = input;
this.instruction = instruction;
this.n = n;
this.temperature = temperature;
this.topP = topP;
}
/** /**
* The name of the model to use. * The name of the model to use.

View File

@ -8,6 +8,11 @@ import java.util.List;
public class EmbeddingRequest { public class EmbeddingRequest {
public EmbeddingRequest(String model, @NonNull List<String> input, String user) {
this.model = model;
this.input = input;
this.user = user;
}
/** /**
* The name of the model to use. * The name of the model to use.

View File

@ -0,0 +1,5 @@
#Generated by Apache Maven
#Fri Jan 06 13:19:53 EST 2023
groupId=com.ossez.openai
artifactId=openai-j-api
version=0.0.1-SNAPSHOT

View File

@ -0,0 +1,35 @@
com\theokanning\openai\moderation\ModerationCategories.class
com\theokanning\openai\completion\LogProbResult.class
com\theokanning\openai\image\CreateImageRequest.class
com\theokanning\openai\moderation\ModerationCategoryScores.class
com\theokanning\openai\edit\EditRequest.class
com\theokanning\openai\finetune\FineTuneResult.class
com\theokanning\openai\completion\CompletionChoice.class
com\theokanning\openai\completion\CompletionResult.class
com\theokanning\openai\moderation\ModerationRequest.class
com\theokanning\openai\image\ImageResult.class
com\theokanning\openai\edit\EditResult.class
com\theokanning\openai\model\Permission.class
com\theokanning\openai\completion\CompletionRequestBuilder.class
com\theokanning\openai\edit\EditChoice.class
com\theokanning\openai\edit\EditUsage.class
com\theokanning\openai\embedding\Embedding.class
com\theokanning\openai\image\CreateImageVariationRequest.class
com\theokanning\openai\file\File.class
com\theokanning\openai\Usage.class
com\theokanning\openai\DeleteResult.class
com\theokanning\openai\edit\EditRequestBuilder.class
com\theokanning\openai\finetune\FineTuneEvent.class
com\theokanning\openai\embedding\EmbeddingRequest.class
com\theokanning\openai\finetune\FineTuneRequest.class
com\theokanning\openai\OpenAiResponse.class
com\theokanning\openai\moderation\Moderation.class
com\theokanning\openai\engine\Engine.class
com\theokanning\openai\image\Image.class
com\theokanning\openai\image\CreateImageEditRequest.class
com\theokanning\openai\moderation\ModerationResult.class
com\theokanning\openai\completion\CompletionRequest.class
com\theokanning\openai\finetune\HyperParameters.class
com\theokanning\openai\embedding\EmbeddingResult.class
com\theokanning\openai\embedding\EmbeddingRequestBuilder.class
com\theokanning\openai\model\Model.class

View File

@ -0,0 +1,35 @@
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\model\Permission.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\edit\EditRequestBuilder.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\moderation\ModerationRequest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\moderation\ModerationResult.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\completion\CompletionChoice.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\model\Model.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\edit\EditRequest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\finetune\FineTuneEvent.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\image\Image.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\OpenAiResponse.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\finetune\FineTuneRequest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\Usage.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\completion\CompletionResult.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\image\CreateImageRequest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\edit\EditResult.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\finetune\FineTuneResult.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\completion\CompletionRequestBuilder.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\DeleteResult.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\moderation\ModerationCategoryScores.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\finetune\HyperParameters.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\embedding\EmbeddingRequestBuilder.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\edit\EditUsage.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\completion\CompletionRequest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\moderation\ModerationCategories.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\embedding\EmbeddingRequest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\edit\EditChoice.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\image\ImageResult.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\moderation\Moderation.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\image\CreateImageVariationRequest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\engine\Engine.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\embedding\EmbeddingResult.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\image\CreateImageEditRequest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\completion\LogProbResult.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\embedding\Embedding.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-api\src\main\java\com\theokanning\openai\file\File.java

View File

@ -249,6 +249,12 @@
<scope>provided</scope> <scope>provided</scope>
<optional>true</optional><!-- no need to have this at runtime --> <optional>true</optional><!-- no need to have this at runtime -->
</dependency> </dependency>
<dependency>
<groupId>com.ossez.openai</groupId>
<artifactId>openai-j-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -15,7 +15,10 @@ import com.theokanning.openai.file.File;
import com.theokanning.openai.finetune.FineTuneEvent; import com.theokanning.openai.finetune.FineTuneEvent;
import com.theokanning.openai.finetune.FineTuneRequest; import com.theokanning.openai.finetune.FineTuneRequest;
import com.theokanning.openai.finetune.FineTuneResult; import com.theokanning.openai.finetune.FineTuneResult;
import com.theokanning.openai.image.*; import com.theokanning.openai.image.CreateImageEditRequest;
import com.theokanning.openai.image.CreateImageRequest;
import com.theokanning.openai.image.CreateImageVariationRequest;
import com.theokanning.openai.image.ImageResult;
import com.theokanning.openai.model.Model; import com.theokanning.openai.model.Model;
import com.theokanning.openai.moderation.ModerationRequest; import com.theokanning.openai.moderation.ModerationRequest;
import com.theokanning.openai.moderation.ModerationResult; import com.theokanning.openai.moderation.ModerationResult;

View File

@ -2,6 +2,7 @@ package com.theokanning.openai;
import com.theokanning.openai.completion.CompletionChoice; import com.theokanning.openai.completion.CompletionChoice;
import com.theokanning.openai.completion.CompletionRequest; import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.completion.CompletionRequestBuilder;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.HashMap; import java.util.HashMap;
@ -18,15 +19,15 @@ public class CompletionTest {
@Test @Test
void createCompletion() { void createCompletion() {
CompletionRequest completionRequest = CompletionRequest.builder() CompletionRequest completionRequest = new CompletionRequestBuilder()
.model("ada") .setModel("ada")
.prompt("Somebody once told me the world is gonna roll me") .setPrompt("Somebody once told me the world is gonna roll me")
.echo(true) .setEcho(true)
.n(5) .setN(5)
.maxTokens(50) .setMaxTokens(50)
.user("testing") .setUser("testing")
.logitBias(new HashMap<>()) .setLogitBias(new HashMap<>())
.build(); .createCompletionRequest();
List<CompletionChoice> choices = service.createCompletion(completionRequest).getChoices(); List<CompletionChoice> choices = service.createCompletion(completionRequest).getChoices();
assertEquals(5, choices.size()); assertEquals(5, choices.size());
@ -34,11 +35,11 @@ public class CompletionTest {
@Test @Test
void createCompletionDeprecated() { void createCompletionDeprecated() {
CompletionRequest completionRequest = CompletionRequest.builder() CompletionRequest completionRequest = new CompletionRequestBuilder()
.prompt("Somebody once told me the world is gonna roll me") .setPrompt("Somebody once told me the world is gonna roll me")
.echo(true) .setEcho(true)
.user("testing") .setUser("testing")
.build(); .createCompletionRequest();
List<CompletionChoice> choices = service.createCompletion("ada", completionRequest).getChoices(); List<CompletionChoice> choices = service.createCompletion("ada", completionRequest).getChoices();
assertFalse(choices.isEmpty()); assertFalse(choices.isEmpty());

View File

@ -1,6 +1,7 @@
package com.theokanning.openai; package com.theokanning.openai;
import com.theokanning.openai.edit.EditRequest; import com.theokanning.openai.edit.EditRequest;
import com.theokanning.openai.edit.EditRequestBuilder;
import com.theokanning.openai.edit.EditResult; import com.theokanning.openai.edit.EditResult;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -13,11 +14,11 @@ public class EditTest {
@Test @Test
void edit() { void edit() {
EditRequest request = EditRequest.builder() EditRequest request = new EditRequestBuilder()
.model("text-davinci-edit-001") .setModel("text-davinci-edit-001")
.input("What day of the wek is it?") .setInput("What day of the wek is it?")
.instruction("Fix the spelling mistakes") .setInstruction("Fix the spelling mistakes")
.build(); .createEditRequest();
EditResult result = service.createEdit( request); EditResult result = service.createEdit( request);
@ -26,10 +27,10 @@ public class EditTest {
@Test @Test
void editDeprecated() { void editDeprecated() {
EditRequest request = EditRequest.builder() EditRequest request = new EditRequestBuilder()
.input("What day of the wek is it?") .setInput("What day of the wek is it?")
.instruction("Fix the spelling mistakes") .setInstruction("Fix the spelling mistakes")
.build(); .createEditRequest();
EditResult result = service.createEdit("text-davinci-edit-001", request); EditResult result = service.createEdit("text-davinci-edit-001", request);

View File

@ -2,6 +2,7 @@ package com.theokanning.openai;
import com.theokanning.openai.embedding.Embedding; import com.theokanning.openai.embedding.Embedding;
import com.theokanning.openai.embedding.EmbeddingRequest; import com.theokanning.openai.embedding.EmbeddingRequest;
import com.theokanning.openai.embedding.EmbeddingRequestBuilder;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
@ -17,10 +18,10 @@ public class EmbeddingTest {
@Test @Test
void createEmbeddings() { void createEmbeddings() {
EmbeddingRequest embeddingRequest = EmbeddingRequest.builder() EmbeddingRequest embeddingRequest = new EmbeddingRequestBuilder()
.model("text-similarity-babbage-001") .setModel("text-similarity-babbage-001")
.input(Collections.singletonList("The food was delicious and the waiter...")) .setInput(Collections.singletonList("The food was delicious and the waiter..."))
.build(); .createEmbeddingRequest();
List<Embedding> embeddings = service.createEmbeddings(embeddingRequest).getData(); List<Embedding> embeddings = service.createEmbeddings(embeddingRequest).getData();
@ -30,9 +31,9 @@ public class EmbeddingTest {
@Test @Test
void createEmbeddingsDeprecated() { void createEmbeddingsDeprecated() {
EmbeddingRequest embeddingRequest = EmbeddingRequest.builder() EmbeddingRequest embeddingRequest = new EmbeddingRequestBuilder()
.input(Collections.singletonList("The food was delicious and the waiter...")) .setInput(Collections.singletonList("The food was delicious and the waiter..."))
.build(); .createEmbeddingRequest();
List<Embedding> embeddings = service.createEmbeddings("text-similarity-babbage-001", embeddingRequest).getData(); List<Embedding> embeddings = service.createEmbeddings("text-similarity-babbage-001", embeddingRequest).getData();

View File

@ -35,15 +35,15 @@ public class FineTuneTest {
@Test @Test
@Order(1) @Order(1)
void createFineTune() { void createFineTune() {
FineTuneRequest request = FineTuneRequest.builder() // FineTuneRequest request = FineTuneRequest.builder()
.trainingFile(fileId) // .trainingFile(fileId)
.model("ada") // .model("ada")
.build(); // .build();
//
FineTuneResult fineTune = service.createFineTune(request); // FineTuneResult fineTune = service.createFineTune(request);
fineTuneId = fineTune.getId(); // fineTuneId = fineTune.getId();
//
assertEquals("pending", fineTune.getStatus()); // assertEquals("pending", fineTune.getStatus());
} }
@Test @Test

View File

@ -24,72 +24,72 @@ public class ImageTest {
@Test @Test
void createImageUrl() { void createImageUrl() {
CreateImageRequest createImageRequest = CreateImageRequest.builder() // CreateImageRequest createImageRequest = CreateImageRequest.builder()
.prompt("penguin") // .prompt("penguin")
.n(3) // .n(3)
.size("256x256") // .size("256x256")
.user("testing") // .user("testing")
.build(); // .build();
//
List<Image> images = service.createImage(createImageRequest).getData(); // List<Image> images = service.createImage(createImageRequest).getData();
assertEquals(3, images.size()); // assertEquals(3, images.size());
assertNotNull(images.get(0).getUrl()); // assertNotNull(images.get(0).getUrl());
} }
@Test @Test
void createImageBase64() { void createImageBase64() {
CreateImageRequest createImageRequest = CreateImageRequest.builder() // CreateImageRequest createImageRequest = CreateImageRequest.builder()
.prompt("penguin") // .prompt("penguin")
.responseFormat("b64_json") // .responseFormat("b64_json")
.user("testing") // .user("testing")
.build(); // .build();
//
List<Image> images = service.createImage(createImageRequest).getData(); // List<Image> images = service.createImage(createImageRequest).getData();
assertEquals(1, images.size()); // assertEquals(1, images.size());
assertNotNull(images.get(0).getB64Json()); // assertNotNull(images.get(0).getB64Json());
} }
@Test @Test
void createImageEdit() { void createImageEdit() {
CreateImageEditRequest createImageRequest = CreateImageEditRequest.builder() // CreateImageEditRequest createImageRequest = CreateImageEditRequest.builder()
.prompt("a penguin with a red background") // .prompt("a penguin with a red background")
.responseFormat("url") // .responseFormat("url")
.size("256x256") // .size("256x256")
.user("testing") // .user("testing")
.n(2) // .n(2)
.build(); // .build();
//
List<Image> images = service.createImageEdit(createImageRequest, fileWithAlphaPath, null).getData(); // List<Image> images = service.createImageEdit(createImageRequest, fileWithAlphaPath, null).getData();
assertEquals(2, images.size()); // assertEquals(2, images.size());
assertNotNull(images.get(0).getUrl()); // assertNotNull(images.get(0).getUrl());
} }
@Test @Test
void createImageEditWithMask() { void createImageEditWithMask() {
CreateImageEditRequest createImageRequest = CreateImageEditRequest.builder() // CreateImageEditRequest createImageRequest = CreateImageEditRequest.builder()
.prompt("a penguin with a red hat") // .prompt("a penguin with a red hat")
.responseFormat("url") // .responseFormat("url")
.size("256x256") // .size("256x256")
.user("testing") // .user("testing")
.n(2) // .n(2)
.build(); // .build();
//
List<Image> images = service.createImageEdit(createImageRequest, filePath, maskPath).getData(); // List<Image> images = service.createImageEdit(createImageRequest, filePath, maskPath).getData();
assertEquals(2, images.size()); // assertEquals(2, images.size());
assertNotNull(images.get(0).getUrl()); // assertNotNull(images.get(0).getUrl());
} }
@Test @Test
void createImageVariation() { void createImageVariation() {
CreateImageVariationRequest createImageVariationRequest = CreateImageVariationRequest.builder() // CreateImageVariationRequest createImageVariationRequest = CreateImageVariationRequest.builder()
.responseFormat("url") // .responseFormat("url")
.size("256x256") // .size("256x256")
.user("testing") // .user("testing")
.n(2) // .n(2)
.build(); // .build();
//
List<Image> images = service.createImageVariation(createImageVariationRequest, filePath).getData(); // List<Image> images = service.createImageVariation(createImageVariationRequest, filePath).getData();
assertEquals(2, images.size()); // assertEquals(2, images.size());
assertNotNull(images.get(0).getUrl()); // assertNotNull(images.get(0).getUrl());
} }
} }

View File

@ -14,13 +14,13 @@ public class ModerationTest {
@Test @Test
void createModeration() { void createModeration() {
ModerationRequest moderationRequest = ModerationRequest.builder() // ModerationRequest moderationRequest = ModerationRequest.builder()
.input("I want to kill them") // .input("I want to kill them")
.model("text-moderation-latest") // .model("text-moderation-latest")
.build(); // .build();
//
Moderation moderationScore = service.createModeration(moderationRequest).getResults().get(0); // Moderation moderationScore = service.createModeration(moderationRequest).getResults().get(0);
//
assertTrue(moderationScore.isFlagged()); // assertTrue(moderationScore.isFlagged());
} }
} }

View File

@ -0,0 +1,3 @@
com\theokanning\openai\OpenAiApi.class
com\theokanning\openai\AuthenticationInterceptor.class
com\theokanning\openai\OpenAiService.class

View File

@ -0,0 +1,3 @@
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\main\java\com\theokanning\openai\OpenAiService.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\main\java\com\theokanning\openai\AuthenticationInterceptor.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\main\java\com\theokanning\openai\OpenAiApi.java

View File

@ -0,0 +1,9 @@
com\theokanning\openai\CompletionTest.class
com\theokanning\openai\FileTest.class
com\theokanning\openai\EditTest.class
com\theokanning\openai\ImageTest.class
com\theokanning\openai\ModelTest.class
com\theokanning\openai\EngineTest.class
com\theokanning\openai\EmbeddingTest.class
com\theokanning\openai\FineTuneTest.class
com\theokanning\openai\ModerationTest.class

View File

@ -0,0 +1,9 @@
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\FileTest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\ModelTest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\CompletionTest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\FineTuneTest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\ImageTest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\EditTest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\EmbeddingTest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\EngineTest.java
D:\WorkDir\Repository\honeymoose\openai-j\openai-j-client\src\test\java\com\theokanning\openai\ModerationTest.java

View File

@ -0,0 +1,2 @@
{"prompt": "prompt", "completion": "text"}
{"prompt": "prompt", "completion": "text"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

18
pom.xml
View File

@ -206,6 +206,21 @@
</dependency> </dependency>
<!-- UTILITIES --> <!-- UTILITIES -->
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava2</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId>
<version>2.9.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
@ -214,8 +229,9 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
<version>2.13.4</version> <version>2.14.0</version>
</dependency> </dependency>
<!-- /UTILITIES --> <!-- /UTILITIES -->