6 Commits

Author SHA1 Message Date
Theo Kanning 48cd7272f7 Bump version to 0.8.1 (#43) 2022-12-04 13:41:14 -06:00
Theo Kanning 1600841a58 Update lombok to 1.18.24 (#42)
Not sure why I never had compiling issues and others did, but I see no reason not to update this.
2022-12-04 12:55:17 -06:00
Theo Kanning 8d7f240010 Add logit bias parameter to CompletionRequest (#41) 2022-12-04 12:49:26 -06:00
Theo Kanning c76923926e Remove deprecated endpoints from example project (#40)
The engine APIs are deprecated, and OpenAI will shut them down eventually
2022-12-04 12:44:30 -06:00
Robin Glauser 0caab13666 Updating example to not use new api (#33) 2022-12-04 12:39:31 -06:00
Theo Kanning 5e14d4f62b Add usage data to Completion and Embedding APIs (#39)
Also changed EditResult to use the new shared object
2022-12-04 12:37:28 -06:00
11 changed files with 61 additions and 15 deletions
+3 -2
View File
@@ -41,12 +41,13 @@ or
### 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)
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("ada", completionRequest).getChoices().forEach(System.out::println);
service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
```
### Using OpenAiApi Retrofit client
+2 -2
View File
@@ -3,8 +3,8 @@ apply plugin: "com.vanniktech.maven.publish"
dependencies {
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
}
compileJava {
@@ -0,0 +1,24 @@
package com.theokanning.openai;
import lombok.Data;
/**
* The OpenAI resources used by a request
*/
@Data
public class Usage {
/**
* The number of prompt tokens used.
*/
long promptTokens;
/**
* The number of completion tokens used.
*/
long completionTokens;
/**
* The number of total tokens used
*/
long totalTokens;
}
@@ -6,6 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
/**
* A request for OpenAi to generate a predicted completion for a prompt.
@@ -110,6 +111,15 @@ public class CompletionRequest {
*/
Integer bestOf;
/**
* Modify the likelihood of specified tokens appearing in the completion.
*
* Maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100.
*
* https://beta.openai.com/docs/api-reference/completions/create#completions/create-logit_bias
*/
Map<String, Integer> logitBias;
/**
* A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse.
*/
@@ -1,5 +1,6 @@
package com.theokanning.openai.completion;
import com.theokanning.openai.Usage;
import lombok.Data;
import java.util.List;
@@ -35,4 +36,9 @@ public class CompletionResult {
* A list of generated completions.
*/
List<CompletionChoice> choices;
/**
* The API usage for this request
*/
Usage usage;
}
@@ -1,5 +1,6 @@
package com.theokanning.openai.edit;
import com.theokanning.openai.Usage;
import lombok.Data;
import java.util.List;
@@ -30,5 +31,5 @@ public class EditResult {
/**
* The API usage for this request
*/
public EditUsage usage;
public Usage usage;
}
@@ -5,9 +5,12 @@ import lombok.Data;
/**
* An object containing the API usage for an edit request
*
* Deprecated, use {@link com.theokanning.openai.Usage} instead
*
* https://beta.openai.com/docs/api-reference/edits/create
*/
@Data
@Deprecated
public class EditUsage {
/**
@@ -1,5 +1,6 @@
package com.theokanning.openai.embedding;
import com.theokanning.openai.Usage;
import lombok.Data;
import java.util.List;
@@ -26,4 +27,9 @@ public class EmbeddingResult {
* A list of the calculated embeddings
*/
List<Embedding> data;
/**
* The API usage for this request
*/
Usage usage;
}
@@ -4,6 +4,7 @@ import com.theokanning.openai.completion.CompletionChoice;
import com.theokanning.openai.completion.CompletionRequest;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -21,6 +22,7 @@ public class CompletionTest {
.prompt("Somebody once told me the world is gonna roll me")
.echo(true)
.user("testing")
.logitBias(new HashMap<>())
.build();
List<CompletionChoice> choices = service.createCompletion(completionRequest).getChoices();
@@ -2,26 +2,19 @@ package example;
import com.theokanning.openai.OpenAiService;
import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.engine.Engine;
class OpenAiApiExample {
public static void main(String... args) {
String token = System.getenv("OPENAI_TOKEN");
OpenAiService service = new OpenAiService(token);
System.out.println("\nGetting available engines...");
service.getEngines().forEach(System.out::println);
System.out.println("\nGetting ada engine...");
Engine ada = service.getEngine("ada");
System.out.println(ada);
System.out.println("\nCreating completion...");
CompletionRequest completionRequest = CompletionRequest.builder()
.model("ada")
.prompt("Somebody once told me the world is gonna roll me")
.echo(true)
.user("testing")
.build();
service.createCompletion("ada", completionRequest).getChoices().forEach(System.out::println);
service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
GROUP=com.theokanning.openai-gpt3-java
VERSION_NAME=0.8.0
VERSION_NAME=0.8.1
POM_URL=https://github.com/theokanning/openai-java
POM_SCM_URL=https://github.com/theokanning/openai-java