|
| 1 | +package org.devlive.sdk.openai.entity; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonFormat; |
| 4 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 5 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 6 | +import lombok.AllArgsConstructor; |
| 7 | +import lombok.Builder; |
| 8 | +import lombok.Data; |
| 9 | +import lombok.NoArgsConstructor; |
| 10 | +import lombok.ToString; |
| 11 | +import org.devlive.sdk.openai.exception.ParamException; |
| 12 | +import org.devlive.sdk.openai.model.CompletionModel; |
| 13 | + |
| 14 | +@Data |
| 15 | +@Builder |
| 16 | +@ToString |
| 17 | +@NoArgsConstructor |
| 18 | +@AllArgsConstructor |
| 19 | +@JsonIgnoreProperties(ignoreUnknown = true) |
| 20 | +public class FineTuningEntity |
| 21 | +{ |
| 22 | + /** |
| 23 | + * Identifier for the last job from the previous pagination request. |
| 24 | + * 上一个分页请求中最后一个作业的标识符。 |
| 25 | + */ |
| 26 | + @JsonProperty(value = "after") |
| 27 | + private String after; |
| 28 | + |
| 29 | + /** |
| 30 | + * Number of fine-tuning jobs to retrieve. Defaults to 20 |
| 31 | + * 要检索的微调作业数。默认值为 20 |
| 32 | + */ |
| 33 | + @JsonProperty(value = "limit") |
| 34 | + private Integer limit; |
| 35 | + |
| 36 | + /** |
| 37 | + * The name of the model to fine-tune. |
| 38 | + * 要微调的模型的名称。 |
| 39 | + */ |
| 40 | + @JsonProperty(value = "model") |
| 41 | + private String model; |
| 42 | + |
| 43 | + /** |
| 44 | + * The ID of an uploaded file that contains training data. |
| 45 | + * 包含训练数据的已上传文件的 ID。 |
| 46 | + */ |
| 47 | + @JsonProperty(value = "training_file") |
| 48 | + private String file; |
| 49 | + |
| 50 | + @JsonProperty(value = "object") |
| 51 | + private String object; |
| 52 | + |
| 53 | + @JsonProperty(value = "id") |
| 54 | + private String id; |
| 55 | + |
| 56 | + @JsonProperty(value = "created_at") |
| 57 | + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| 58 | + private String createTime; |
| 59 | + |
| 60 | + @JsonProperty(value = "finished_at") |
| 61 | + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| 62 | + private String finishTime; |
| 63 | + |
| 64 | + @JsonProperty(value = "level") |
| 65 | + private String level; |
| 66 | + |
| 67 | + @JsonProperty(value = "message") |
| 68 | + private String message; |
| 69 | + |
| 70 | + @JsonProperty(value = "data") |
| 71 | + private String data; |
| 72 | + |
| 73 | + @JsonProperty(value = "type") |
| 74 | + private String type; |
| 75 | + |
| 76 | + @JsonProperty(value = "fine_tuned_model") |
| 77 | + private String tunedModel; |
| 78 | + |
| 79 | + @JsonProperty(value = "organization_id") |
| 80 | + private String organizationId; |
| 81 | + |
| 82 | + @JsonProperty(value = "status") |
| 83 | + private String status; |
| 84 | + |
| 85 | + @JsonProperty(value = "validation_file") |
| 86 | + private String validationFile; |
| 87 | + |
| 88 | + @JsonProperty(value = "trained_tokens") |
| 89 | + private Long trainedTokens; |
| 90 | + |
| 91 | + private FineTuningEntity(FineTuningEntityBuilder builder) |
| 92 | + { |
| 93 | + if (builder.limit == null) { |
| 94 | + builder.limit(null); |
| 95 | + } |
| 96 | + this.limit = builder.limit; |
| 97 | + this.after = builder.after; |
| 98 | + |
| 99 | + if (builder.model == null) { |
| 100 | + builder.model(CompletionModel.GPT_35_TURBO); |
| 101 | + } |
| 102 | + this.model = builder.model; |
| 103 | + |
| 104 | + if (builder.file == null) { |
| 105 | + builder.file(null); |
| 106 | + } |
| 107 | + this.file = builder.file; |
| 108 | + } |
| 109 | + |
| 110 | + public static class FineTuningEntityBuilder |
| 111 | + { |
| 112 | + public FineTuningEntityBuilder limit(Integer limit) |
| 113 | + { |
| 114 | +// if (limit == null) { |
| 115 | +// limit = 20; |
| 116 | +// } |
| 117 | +// |
| 118 | +// if (limit < 1) { |
| 119 | +// throw new ParamException("Invalid limit must not be less than 1"); |
| 120 | +// } |
| 121 | + this.limit = limit; |
| 122 | + return this; |
| 123 | + } |
| 124 | + |
| 125 | + public FineTuningEntityBuilder after(String after) |
| 126 | + { |
| 127 | + this.after = after; |
| 128 | + return this; |
| 129 | + } |
| 130 | + |
| 131 | + public FineTuningEntityBuilder model(CompletionModel model) |
| 132 | + { |
| 133 | + if (model == null) { |
| 134 | + model = CompletionModel.GPT_35_TURBO; |
| 135 | + } |
| 136 | + |
| 137 | + switch (model) { |
| 138 | + case GPT_35_TURBO: |
| 139 | + case GPT_35_TURBO_0613: |
| 140 | + case BABBAGE_002: |
| 141 | + case DAVINCI_002: |
| 142 | + case GPT_4_0613: |
| 143 | + this.model = model.getName(); |
| 144 | + break; |
| 145 | + default: |
| 146 | + throw new ParamException(String.format("Not support completion model %s", model)); |
| 147 | + } |
| 148 | + return this; |
| 149 | + } |
| 150 | + |
| 151 | + public FineTuningEntityBuilder file(String file) |
| 152 | + { |
| 153 | + if (file == null) { |
| 154 | + throw new ParamException("Invalid file name must not be empty"); |
| 155 | + } |
| 156 | + this.file = file; |
| 157 | + return this; |
| 158 | + } |
| 159 | + |
| 160 | + public FineTuningEntity build() |
| 161 | + { |
| 162 | + return new FineTuningEntity(this); |
| 163 | + } |
| 164 | + } |
| 165 | +} |
0 commit comments