Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce39294

Browse filesBrowse files
authored
Add JsonProperty snake case names to each variable (TheoKanning#172)
This is a better solution that asking everyone to use snake case in their converter
1 parent 27c9089 commit ce39294
Copy full SHA for ce39294
Expand file treeCollapse file tree

39 files changed

+319
-9
lines changed

‎.github/workflows/gradle-wrapper-validation.yml

Copy file name to clipboardExpand all lines: .github/workflows/gradle-wrapper-validation.yml
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: "Validate Gradle Wrapper"
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
37

48
jobs:
59
validation:

‎api/build.gradle

Copy file name to clipboardExpand all lines: api/build.gradle
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ dependencies {
55
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
66
compileOnly 'org.projectlombok:lombok:1.18.24'
77
annotationProcessor 'org.projectlombok:lombok:1.18.24'
8+
9+
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
10+
testImplementation(platform('org.junit:junit-bom:5.8.2'))
11+
testImplementation('org.junit.jupiter:junit-jupiter')
812
}
913

1014
compileJava {
1115
sourceCompatibility = '1.8'
1216
targetCompatibility = '1.8'
1317
}
18+
19+
test {
20+
useJUnitPlatform()
21+
}

‎api/src/main/java/com/theokanning/openai/OpenAiHttpException.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/OpenAiHttpException.java
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class OpenAiHttpException extends RuntimeException {
2323

2424
public OpenAiHttpException(OpenAiError error, Exception parent, int statusCode) {
2525
super(error.error.message, parent);
26-
// todo error.error looks dumb
2726
this.statusCode = statusCode;
2827
this.code = error.error.code;
2928
this.param = error.error.param;

‎api/src/main/java/com/theokanning/openai/Usage.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/Usage.java
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai;
22

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

56
/**
@@ -10,15 +11,18 @@ public class Usage {
1011
/**
1112
* The number of prompt tokens used.
1213
*/
14+
@JsonProperty("prompt_tokens")
1315
long promptTokens;
1416

1517
/**
1618
* The number of completion tokens used.
1719
*/
20+
@JsonProperty("completion_tokens")
1821
long completionTokens;
1922

2023
/**
2124
* The number of total tokens used
2225
*/
26+
@JsonProperty("total_tokens")
2327
long totalTokens;
2428
}

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

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/completion/CompletionRequest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class CompletionRequest {
2424

2525
/**
2626
* The name of the model to use.
27-
* Required if specifying a fine tuned model or if using the new v1/completions endpoint.
27+
* Required if specifying a fine-tuned model or if using the new v1/completions endpoint.
2828
*/
2929
String model;
3030

‎api/src/main/java/com/theokanning/openai/completion/CompletionResult.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/completion/CompletionResult.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CompletionResult {
1818
*/
1919
String id;
2020

21-
/**
21+
/**https://beta.openai.com/docs/api-reference/create-completion
2222
* The type of object returned, should be "text_completion"
2323
*/
2424
String object;

‎api/src/main/java/com/theokanning/openai/completion/LogProbResult.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/completion/LogProbResult.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.completion;
22

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

56
import java.util.List;
@@ -22,12 +23,14 @@ public class LogProbResult {
2223
/**
2324
* The log probability of each token in {@link tokens}
2425
*/
26+
@JsonProperty("token_logprobs")
2527
List<Double> tokenLogprobs;
2628

2729
/**
2830
* A map for each index in the completion result.
2931
* The map contains the top {@link CompletionRequest#logprobs} tokens and their probabilities
3032
*/
33+
@JsonProperty("top_logprobs")
3134
List<Map<String, Double>> topLogprobs;
3235

3336
/**

‎api/src/main/java/com/theokanning/openai/completion/chat/ChatCompletionChoice.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/completion/chat/ChatCompletionChoice.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.theokanning.openai.completion.chat;
2+
import com.fasterxml.jackson.annotation.JsonProperty;
23
import lombok.Data;
34

45
/**
@@ -20,5 +21,6 @@ public class ChatCompletionChoice {
2021
/**
2122
* The reason why GPT-3 stopped generating, for example "length".
2223
*/
24+
@JsonProperty("finish_reason")
2325
String finishReason;
2426
}

‎api/src/main/java/com/theokanning/openai/completion/chat/ChatCompletionRequest.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/completion/chat/ChatCompletionRequest.java
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.completion.chat;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
34
import lombok.AllArgsConstructor;
45
import lombok.Builder;
56
import lombok.Data;
@@ -38,6 +39,7 @@ public class ChatCompletionRequest {
3839
* with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.<br>
3940
* We generally recommend altering this or temperature but not both.
4041
*/
42+
@JsonProperty("top_p")
4143
Double topP;
4244

4345
/**
@@ -61,18 +63,21 @@ public class ChatCompletionRequest {
6163
* The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will
6264
* be (4096 - prompt tokens).
6365
*/
66+
@JsonProperty("max_tokens")
6467
Integer maxTokens;
6568

6669
/**
6770
* Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far,
6871
* increasing the model's likelihood to talk about new topics.
6972
*/
73+
@JsonProperty("presence_penalty")
7074
Double presencePenalty;
7175

7276
/**
7377
* Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far,
7478
* decreasing the model's likelihood to repeat the same line verbatim.
7579
*/
80+
@JsonProperty("frequency_penalty")
7681
Double frequencyPenalty;
7782

7883
/**
@@ -81,6 +86,7 @@ public class ChatCompletionRequest {
8186
* vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100
8287
* should result in a ban or exclusive selection of the relevant token.
8388
*/
89+
@JsonProperty("logit_bias")
8490
Map<String, Integer> logitBias;
8591

8692

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

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/embedding/EmbeddingRequest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class EmbeddingRequest {
2626
* To get embeddings for multiple inputs in a single request, pass an array of strings or array of token arrays.
2727
* Each input must not exceed 2048 tokens in length.
2828
* <p>
29-
* Unless your are embedding code, we suggest replacing newlines (\n) in your input with a single space,
29+
* Unless you are embedding code, we suggest replacing newlines (\n) in your input with a single space,
3030
* as we have observed inferior results when newlines are present.
3131
*/
3232
@NonNull

‎api/src/main/java/com/theokanning/openai/file/File.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/file/File.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.file;
22

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

56
/**
@@ -28,6 +29,7 @@ public class File {
2829
/**
2930
* The creation time in epoch seconds.
3031
*/
32+
@JsonProperty("created_at")
3133
Long createdAt;
3234

3335
/**

‎api/src/main/java/com/theokanning/openai/finetune/FineTuneEvent.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/finetune/FineTuneEvent.java
+2Lines changed: 2 additions & 0 deletions
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.Data;
45

56
/**
@@ -17,6 +18,7 @@ public class FineTuneEvent {
1718
/**
1819
* The creation time in epoch seconds.
1920
*/
21+
@JsonProperty("created_at")
2022
Long createdAt;
2123

2224
/**

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

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/finetune/FineTuneRequest.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ public class FineTuneRequest {
2121
* The ID of an uploaded file that contains training data.
2222
*/
2323
@NonNull
24+
@JsonProperty("training_file")
2425
String trainingFile;
2526

2627
/**
2728
* The ID of an uploaded file that contains validation data.
2829
*/
30+
@JsonProperty("validation_file")
2931
String validationFile;
3032

3133
/**
@@ -47,6 +49,7 @@ public class FineTuneRequest {
4749
* By default, the batch size will be dynamically configured to be ~0.2% of the number of examples in the training
4850
* set, capped at 256 - in general, we've found that larger batch sizes tend to work better for larger datasets.
4951
*/
52+
@JsonProperty("batch_size")
5053
Integer batchSize;
5154

5255
/**
@@ -57,6 +60,7 @@ public class FineTuneRequest {
5760
* (larger learning rates tend to perform better with larger batch sizes).
5861
* We recommend experimenting with values in the range 0.02 to 0.2 to see what produces the best results.
5962
*/
63+
@JsonProperty("learning_rate_multiplier")
6064
Double learningRateMultiplier;
6165

6266
/**
@@ -68,6 +72,7 @@ public class FineTuneRequest {
6872
* If prompts are extremely long (relative to completions), it may make sense to reduce this weight so as to
6973
* avoid over-prioritizing learning the prompt.
7074
*/
75+
@JsonProperty("prompt_loss_weight")
7176
Double promptLossWeight;
7277

7378
/**
@@ -78,6 +83,7 @@ public class FineTuneRequest {
7883
* Additionally, you must specify {@link FineTuneRequest#classificationNClasses} for multiclass
7984
* classification or {@link FineTuneRequest#classificationPositiveClass} for binary classification.
8085
*/
86+
@JsonProperty("compute_classification_metrics")
8187
Boolean computeClassificationMetrics;
8288

8389
/**
@@ -93,6 +99,7 @@ public class FineTuneRequest {
9399
*
94100
* This parameter is needed to generate precision, recall, and F1 metrics when doing binary classification.
95101
*/
102+
@JsonProperty("classification_positive_class")
96103
String classificationPositiveClass;
97104

98105
/**
@@ -103,6 +110,7 @@ public class FineTuneRequest {
103110
* A larger beta score puts more weight on recall and less on precision.
104111
* A smaller beta score puts more weight on precision and less on recall.
105112
*/
113+
@JsonProperty("classification_betas")
106114
List<Double> classificationBetas;
107115

108116
/**

‎api/src/main/java/com/theokanning/openai/finetune/FineTuneResult.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/finetune/FineTuneResult.java
+8Lines changed: 8 additions & 0 deletions
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 com.theokanning.openai.file.File;
45
import lombok.Data;
56

@@ -30,6 +31,7 @@ public class FineTuneResult {
3031
/**
3132
* The creation time in epoch seconds.
3233
*/
34+
@JsonProperty("created_at")
3335
Long createdAt;
3436

3537
/**
@@ -41,6 +43,7 @@ public class FineTuneResult {
4143
* The ID of the fine-tuned model, null if tuning job is not finished.
4244
* This is the id used to call the model.
4345
*/
46+
@JsonProperty("fine_tuned_model")
4447
String fineTunedModel;
4548

4649
/**
@@ -51,11 +54,13 @@ public class FineTuneResult {
5154
/**
5255
* The ID of the organization this model belongs to.
5356
*/
57+
@JsonProperty("organization_id")
5458
String organizationId;
5559

5660
/**
5761
* Result files for this fine-tune job.
5862
*/
63+
@JsonProperty("result_files")
5964
List<File> resultFiles;
6065

6166
/**
@@ -66,15 +71,18 @@ public class FineTuneResult {
6671
/**
6772
* Training files for this fine-tune job.
6873
*/
74+
@JsonProperty("training_files")
6975
List<File> trainingFiles;
7076

7177
/**
7278
* The last update time in epoch seconds.
7379
*/
80+
@JsonProperty("updated_at")
7481
Long updatedAt;
7582

7683
/**
7784
* Validation files for this fine-tune job.
7885
*/
86+
@JsonProperty("validation_files")
7987
List<File> validationFiles;
8088
}

‎api/src/main/java/com/theokanning/openai/finetune/HyperParameters.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/finetune/HyperParameters.java
+6-1Lines changed: 6 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.Data;
45

56
/**
@@ -13,20 +14,24 @@ public class HyperParameters {
1314
/**
1415
* The batch size to use for training.
1516
*/
16-
String batchSize;
17+
@JsonProperty("batch_size")
18+
Integer batchSize;
1719

1820
/**
1921
* The learning rate multiplier to use for training.
2022
*/
23+
@JsonProperty("learning_rate_multiplier")
2124
Double learningRateMultiplier;
2225

2326
/**
2427
* The number of epochs to train the model for.
2528
*/
29+
@JsonProperty("n_epochs")
2630
Integer nEpochs;
2731

2832
/**
2933
* The weight to use for loss on the prompt tokens.
3034
*/
35+
@JsonProperty("prompt_loss_weight")
3136
Double promptLossWeight;
3237
}

‎api/src/main/java/com/theokanning/openai/image/CreateImageEditRequest.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/image/CreateImageEditRequest.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.image;
22

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

56
/**
@@ -33,6 +34,7 @@ public class CreateImageEditRequest {
3334
/**
3435
* The format in which the generated images are returned. Must be one of url or b64_json. Defaults to url.
3536
*/
37+
@JsonProperty("response_format")
3638
String responseFormat;
3739

3840
/**

‎api/src/main/java/com/theokanning/openai/image/CreateImageVariationRequest.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/image/CreateImageVariationRequest.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.image;
22

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

56
/**
@@ -27,6 +28,7 @@ public class CreateImageVariationRequest {
2728
/**
2829
* The format in which the generated images are returned. Must be one of url or b64_json. Defaults to url.
2930
*/
31+
@JsonProperty("response_format")
3032
String responseFormat;
3133

3234
/**

‎api/src/main/java/com/theokanning/openai/image/ImageResult.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/image/ImageResult.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.theokanning.openai.image;
22

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

56
import java.util.List;
@@ -15,7 +16,7 @@ public class ImageResult {
1516
/**
1617
* The creation time in epoch seconds.
1718
*/
18-
Long createdAt;
19+
Long created;
1920

2021
/**
2122
* List of image results.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.