Skip to content

Commit

Permalink
Add JsonProperty snake case names to each variable (TheoKanning#172)
Browse files Browse the repository at this point in the history
This is a better solution that asking everyone to use snake case in their converter
  • Loading branch information
TheoKanning authored Mar 8, 2023
1 parent 27c9089 commit ce39294
Show file tree
Hide file tree
Showing 39 changed files with 319 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: "Validate Gradle Wrapper"
on: [push, pull_request]
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
validation:
Expand Down
8 changes: 8 additions & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'

testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
testImplementation(platform('org.junit:junit-bom:5.8.2'))
testImplementation('org.junit.jupiter:junit-jupiter')
}

compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class OpenAiHttpException extends RuntimeException {

public OpenAiHttpException(OpenAiError error, Exception parent, int statusCode) {
super(error.error.message, parent);
// todo error.error looks dumb
this.statusCode = statusCode;
this.code = error.error.code;
this.param = error.error.param;
Expand Down
4 changes: 4 additions & 0 deletions api/src/main/java/com/theokanning/openai/Usage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
Expand All @@ -10,15 +11,18 @@ public class Usage {
/**
* The number of prompt tokens used.
*/
@JsonProperty("prompt_tokens")
long promptTokens;

/**
* The number of completion tokens used.
*/
@JsonProperty("completion_tokens")
long completionTokens;

/**
* The number of total tokens used
*/
@JsonProperty("total_tokens")
long totalTokens;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CompletionRequest {

/**
* The name of the model to use.
* Required if specifying a fine tuned model or if using the new v1/completions endpoint.
* Required if specifying a fine-tuned model or if using the new v1/completions endpoint.
*/
String model;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CompletionResult {
*/
String id;

/**
/**https://beta.openai.com/docs/api-reference/create-completion
* The type of object returned, should be "text_completion"
*/
String object;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.completion;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

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

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

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.theokanning.openai.completion.chat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
Expand All @@ -20,5 +21,6 @@ public class ChatCompletionChoice {
/**
* The reason why GPT-3 stopped generating, for example "length".
*/
@JsonProperty("finish_reason")
String finishReason;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.completion.chat;

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

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

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

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

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class EmbeddingRequest {
* To get embeddings for multiple inputs in a single request, pass an array of strings or array of token arrays.
* Each input must not exceed 2048 tokens in length.
* <p>
* Unless your are embedding code, we suggest replacing newlines (\n) in your input with a single space,
* Unless you are embedding code, we suggest replacing newlines (\n) in your input with a single space,
* as we have observed inferior results when newlines are present.
*/
@NonNull
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/com/theokanning/openai/file/File.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.file;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
Expand Down Expand Up @@ -28,6 +29,7 @@ public class File {
/**
* The creation time in epoch seconds.
*/
@JsonProperty("created_at")
Long createdAt;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.finetune;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
Expand All @@ -17,6 +18,7 @@ public class FineTuneEvent {
/**
* The creation time in epoch seconds.
*/
@JsonProperty("created_at")
Long createdAt;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public class FineTuneRequest {
* The ID of an uploaded file that contains training data.
*/
@NonNull
@JsonProperty("training_file")
String trainingFile;

/**
* The ID of an uploaded file that contains validation data.
*/
@JsonProperty("validation_file")
String validationFile;

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

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

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

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

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

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

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.finetune;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.theokanning.openai.file.File;
import lombok.Data;

Expand Down Expand Up @@ -30,6 +31,7 @@ public class FineTuneResult {
/**
* The creation time in epoch seconds.
*/
@JsonProperty("created_at")
Long createdAt;

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

/**
Expand All @@ -51,11 +54,13 @@ public class FineTuneResult {
/**
* The ID of the organization this model belongs to.
*/
@JsonProperty("organization_id")
String organizationId;

/**
* Result files for this fine-tune job.
*/
@JsonProperty("result_files")
List<File> resultFiles;

/**
Expand All @@ -66,15 +71,18 @@ public class FineTuneResult {
/**
* Training files for this fine-tune job.
*/
@JsonProperty("training_files")
List<File> trainingFiles;

/**
* The last update time in epoch seconds.
*/
@JsonProperty("updated_at")
Long updatedAt;

/**
* Validation files for this fine-tune job.
*/
@JsonProperty("validation_files")
List<File> validationFiles;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.finetune;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
Expand All @@ -13,20 +14,24 @@ public class HyperParameters {
/**
* The batch size to use for training.
*/
String batchSize;
@JsonProperty("batch_size")
Integer batchSize;

/**
* The learning rate multiplier to use for training.
*/
@JsonProperty("learning_rate_multiplier")
Double learningRateMultiplier;

/**
* The number of epochs to train the model for.
*/
@JsonProperty("n_epochs")
Integer nEpochs;

/**
* The weight to use for loss on the prompt tokens.
*/
@JsonProperty("prompt_loss_weight")
Double promptLossWeight;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.image;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

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

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.image;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

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

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theokanning.openai.image;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.List;
Expand All @@ -15,7 +16,7 @@ public class ImageResult {
/**
* The creation time in epoch seconds.
*/
Long createdAt;
Long created;

/**
* List of image results.
Expand Down
Loading

0 comments on commit ce39294

Please sign in to comment.