Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit 553e22f

Browse files
authored
Add Model support and new v1 endpoints (#27)
The old endpoints are marked as deprecated Also marked response fields as public for easier access
1 parent 252db27 commit 553e22f

File tree

18 files changed

+265
-37
lines changed

18 files changed

+265
-37
lines changed

api/src/main/java/com/theokanning/openai/completion/CompletionRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
public class CompletionRequest {
2121

2222
/**
23-
* The name of the model to use, only used if specifying a fine tuned model.
23+
* The name of the model to use.
24+
* Required if specifying a fine tuned model or if using the new v1/completions endpoint.
2425
*/
2526
String model;
2627

api/src/main/java/com/theokanning/openai/edit/EditRequest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
@Data
1515
public class EditRequest {
1616

17+
/**
18+
* The name of the model to use.
19+
* Required if using the new v1/edits endpoint.
20+
*/
21+
String model;
22+
1723
/**
1824
* The input text to use as a starting point for the edit.
1925
*/
@@ -32,14 +38,17 @@ public class EditRequest {
3238
Integer n;
3339

3440
/**
35-
* What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer.
41+
* What sampling temperature to use. Higher values means the model will take more risks.
42+
* Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer.
3643
*
3744
* We generally recommend altering this or {@link EditRequest#topP} but not both.
3845
*/
3946
Double temperature;
4047

4148
/**
42-
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
49+
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of
50+
* the tokens with top_p probability mass.So 0.1 means only the tokens comprising the top 10% probability mass are
51+
* considered.
4352
*
4453
* We generally recommend altering this or {@link EditRequest#temperature} but not both.
4554
*/

api/src/main/java/com/theokanning/openai/edit/EditResult.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ public class EditResult {
1515
/**
1616
* The type of object returned, should be "edit"
1717
*/
18-
String object;
18+
public String object;
1919

2020
/**
2121
* The creation time in epoch milliseconds.
2222
*/
23-
long created;
23+
public long created;
2424

2525
/**
2626
* A list of generated edits.
2727
*/
28-
List<EditChoice> choices;
28+
public List<EditChoice> choices;
2929

3030
/**
3131
* The API usage for this request
3232
*/
33-
EditUsage usage;
33+
public EditUsage usage;
3434
}

api/src/main/java/com/theokanning/openai/embedding/EmbeddingRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/**
88
* Creates an embedding vector representing the input text.
99
*
10-
* Documentation taken from
1110
* https://beta.openai.com/docs/api-reference/embeddings/create
1211
*/
1312
@Builder
@@ -16,6 +15,12 @@
1615
@Data
1716
public class EmbeddingRequest {
1817

18+
/**
19+
* The name of the model to use.
20+
* Required if using the new v1/embeddings endpoint.
21+
*/
22+
String model;
23+
1924
/**
2025
* Input text to get embeddings for, encoded as a string or array of tokens.
2126
* To get embeddings for multiple inputs in a single request, pass an array of strings or array of token arrays.

api/src/main/java/com/theokanning/openai/engine/Engine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* https://beta.openai.com/docs/api-reference/retrieve-engine
99
*/
10+
@Deprecated
1011
@Data
1112
public class Engine {
1213
/**

api/src/main/java/com/theokanning/openai/finetune/FineTuneRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.finetune;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
34
import lombok.*;
45

56
import java.util.List;
@@ -83,7 +84,8 @@ public class FineTuneRequest {
8384
*
8485
* This parameter is required for multiclass classification.
8586
*/
86-
Integer classificationNClasses; // todo verify snake case
87+
@JsonProperty("classification_n_classes")
88+
Integer classificationNClasses;
8789

8890
/**
8991
* The positive class in binary classification.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.theokanning.openai.model;
2+
3+
import lombok.Data;
4+
5+
import java.util.List;
6+
7+
/**
8+
* GPT-3 model details
9+
*
10+
* https://beta.openai.com/docs/api-reference/models
11+
*/
12+
@Data
13+
public class Model {
14+
/**
15+
* An identifier for this model, used to specify the model when making completions, etc
16+
*/
17+
public String id;
18+
19+
/**
20+
* The type of object returned, should be "model"
21+
*/
22+
public String object;
23+
24+
/**
25+
* The owner of the GPT-3 model, typically "openai"
26+
*/
27+
public String ownedBy;
28+
29+
/**
30+
* List of permissions for this model
31+
*/
32+
public List<Permission> permission;
33+
34+
/**
35+
* The root model that this and its parent (if applicable) are based on
36+
*/
37+
public String root;
38+
39+
/**
40+
* The parent model that this is based on
41+
*/
42+
public String parent;
43+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.theokanning.openai.model;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* GPT-3 model permissions
7+
* I couldn't find documentation for the specific permissions, and I've elected to leave them undocumented rather than
8+
* write something incorrect.
9+
*
10+
* https://beta.openai.com/docs/api-reference/models
11+
*/
12+
@Data
13+
public class Permission {
14+
/**
15+
* An identifier for this model permission
16+
*/
17+
public String id;
18+
19+
/**
20+
* The type of object returned, should be "model_permission"
21+
*/
22+
public String object;
23+
24+
/**
25+
* The creation time in epoch seconds.
26+
*/
27+
public long created;
28+
29+
public boolean allowCreateEngine;
30+
31+
public boolean allowSampling;
32+
33+
public boolean allowLogProbs;
34+
35+
public boolean allowSearchIndices;
36+
37+
public boolean allowView;
38+
39+
public boolean allowFineTuning;
40+
41+
public String organization;
42+
43+
public String group;
44+
45+
public boolean isBlocking;
46+
47+
}

api/src/main/java/com/theokanning/openai/moderation/Moderation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ public class Moderation {
1212
/**
1313
* Set to true if the model classifies the content as violating OpenAI's content policy, false otherwise
1414
*/
15-
boolean flagged;
15+
public boolean flagged;
1616

1717
/**
1818
* Object containing per-category binary content policy violation flags.
1919
* For each category, the value is true if the model flags the corresponding category as violated, false otherwise.
2020
*/
21-
ModerationCategories categories;
21+
public ModerationCategories categories;
2222

2323
/**
2424
* Object containing per-category raw scores output by the model, denoting the model's confidence that the
2525
* input violates the OpenAI's policy for the category.
2626
* The value is between 0 and 1, where higher values denote higher confidence.
2727
* The scores should not be interpreted as probabilities.
2828
*/
29-
ModerationCategoryScores categoryScores;
29+
public ModerationCategoryScores categoryScores;
3030
}

api/src/main/java/com/theokanning/openai/moderation/ModerationCategories.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
@Data
1515
public class ModerationCategories {
1616

17-
boolean hate;
17+
public boolean hate;
1818

1919
@JsonProperty("hate/threatening")
20-
boolean hateThreatening;
20+
public boolean hateThreatening;
2121

2222
@JsonProperty("self-harm")
23-
boolean selfHarm;
23+
public boolean selfHarm;
2424

25-
boolean sexual;
25+
public boolean sexual;
2626

2727
@JsonProperty("sexual/minors")
28-
boolean sexualMinors;
28+
public boolean sexualMinors;
2929

30-
boolean violence;
30+
public boolean violence;
3131

3232
@JsonProperty("violence/graphic")
33-
boolean violenceGraphic;
33+
public boolean violenceGraphic;
3434
}

0 commit comments

Comments
 (0)