Skip to content

Commit 7f8161c

Browse files
Feature fine tune (#39)
2 parents 93cbd9b + 9e40768 commit 7f8161c

File tree

13 files changed

+409
-13
lines changed

13 files changed

+409
-13
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish via Maven Central for SNAPSHOT version
2+
3+
on:
4+
push
5+
6+
jobs:
7+
publish-maven-central:
8+
runs-on: ubuntu-latest
9+
if: github.event.pull_request.merged == true
10+
steps:
11+
- name: Check out Git repository
12+
uses: actions/checkout@v4
13+
14+
- name: Install Java and Maven
15+
uses: actions/setup-java@v3
16+
with:
17+
java-version: '11'
18+
distribution: 'temurin'
19+
20+
- name: Publish to the Maven Central Repository
21+
uses: samuelmeuli/action-maven-publish@v1
22+
with:
23+
maven_profiles: 'deploy'
24+
maven_goals_phases: 'clean deploy'
25+
maven_args: '-DskipTests'
26+
gpg_private_key: ${{ secrets.GPG_SECRET }}
27+
gpg_passphrase: ${{ secrets.GPG_PASSWORD }}
28+
nexus_username: ${{ secrets.OSSRH_USERNAME }}
29+
nexus_password: ${{ secrets.OSSRH_TOKEN }}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
name: Publish jar via Maven Central
1+
name: Publish via Maven Central
22

33
on:
44
release:
55
types: [ published ]
66

77
jobs:
8-
release:
8+
publish-maven-central:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Check out Git repository
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v4
1313

1414
- name: Install Java and Maven
15-
uses: actions/setup-java@v1
15+
uses: actions/setup-java@v3
1616
with:
17-
java-version: 8
17+
java-version: '11'
18+
distribution: 'temurin'
1819

19-
- name: Release Maven package
20+
- name: Publish to the Maven Central Repository
2021
uses: samuelmeuli/action-maven-publish@v1
2122
with:
23+
maven_profiles: 'deploy'
24+
maven_goals_phases: 'clean deploy'
25+
maven_args: '-DskipTests'
2226
gpg_private_key: ${{ secrets.GPG_SECRET }}
2327
gpg_passphrase: ${{ secrets.GPG_PASSWORD }}
24-
nexus_username: ${{ secrets.OSSRH_USER }}
25-
nexus_password: ${{ secrets.OSSRH_PASSWORD }}
28+
nexus_username: ${{ secrets.OSSRH_USERNAME }}
29+
nexus_password: ${{ secrets.OSSRH_TOKEN }}

docs/mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
site_name: OpenAi Java Sdk
1+
site_name: Open AI Models Java Sdk
22
site_url: https://openai-java-sdk.devlive.org
33
site_author: qinamoQ
44
site_description: >-
5-
Provides Java developers with a convenient, easy-to-use SDK to interact with OpenAI's apis.
5+
Provides an easy-to-use SDK for Java developers to interact with the APIs of open AI models.
66
77
repo_name: devlive-community/openai-java-sdk
88
repo_url: https://github.com/devlive-community/openai-java-sdk

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.devlive.sdk</groupId>
77
<artifactId>openai-java-sdk</artifactId>
8-
<version>1.9.0</version>
8+
<version>2023.12.1-SNAPSHOT</version>
99

1010
<name>openai-java-sdk</name>
1111
<description>

src/main/java/org/devlive/sdk/openai/DefaultApi.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.devlive.sdk.openai.entity.EditEntity;
99
import org.devlive.sdk.openai.entity.EmbeddingEntity;
1010
import org.devlive.sdk.openai.entity.FileEntity;
11+
import org.devlive.sdk.openai.entity.FineTuningEntity;
1112
import org.devlive.sdk.openai.entity.ImageEntity;
1213
import org.devlive.sdk.openai.entity.ModelEntity;
1314
import org.devlive.sdk.openai.entity.ModerationEntity;
@@ -18,6 +19,7 @@
1819
import org.devlive.sdk.openai.response.EditResponse;
1920
import org.devlive.sdk.openai.response.EmbeddingResponse;
2021
import org.devlive.sdk.openai.response.FileResponse;
22+
import org.devlive.sdk.openai.response.FineTuningResponse;
2123
import org.devlive.sdk.openai.response.ImageResponse;
2224
import org.devlive.sdk.openai.response.ModelResponse;
2325
import org.devlive.sdk.openai.response.ModerationResponse;
@@ -194,4 +196,40 @@ Single<FileEntity> fetchUploadFile(@Url String url,
194196
*/
195197
@GET
196198
Single<Object> fetchRetrieveFileContent(@Url String url);
199+
200+
/**
201+
* List your organization's fine-tuning jobs
202+
* 列出组织的微调作业
203+
*/
204+
@GET
205+
Single<FineTuningResponse> fetchFineTuningJobs(@Url String url);
206+
207+
/**
208+
* Creates a job that fine-tunes a specified model from a given dataset.
209+
* 创建一个作业,用于微调给定数据集中的指定模型。
210+
*/
211+
@POST
212+
Single<FineTuningResponse> fetchCreateFineTuningJob(@Url String url,
213+
@Body FineTuningEntity configure);
214+
215+
/**
216+
* Get status updates for a fine-tuning job.
217+
* 获取微调作业的状态更新。
218+
*/
219+
@GET
220+
Single<FineTuningResponse> fetchFineTuningJobEvents(@Url String url);
221+
222+
/**
223+
* Get info about a fine-tuning job.
224+
* 获取有关微调作业的信息。
225+
*/
226+
@GET
227+
Single<FineTuningEntity> fetchFineTuningJobContent(@Url String url);
228+
229+
/**
230+
* Immediately cancel a fine-tune job.
231+
* 立即取消微调作业。
232+
*/
233+
@POST
234+
Single<FineTuningEntity> fetchCancelFineTuningJob(@Url String url);
197235
}

src/main/java/org/devlive/sdk/openai/DefaultClient.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.devlive.sdk.openai.entity.EditEntity;
1717
import org.devlive.sdk.openai.entity.EmbeddingEntity;
1818
import org.devlive.sdk.openai.entity.FileEntity;
19+
import org.devlive.sdk.openai.entity.FineTuningEntity;
1920
import org.devlive.sdk.openai.entity.ImageEntity;
2021
import org.devlive.sdk.openai.entity.ModelEntity;
2122
import org.devlive.sdk.openai.entity.ModerationEntity;
@@ -31,6 +32,7 @@
3132
import org.devlive.sdk.openai.response.EditResponse;
3233
import org.devlive.sdk.openai.response.EmbeddingResponse;
3334
import org.devlive.sdk.openai.response.FileResponse;
35+
import org.devlive.sdk.openai.response.FineTuningResponse;
3436
import org.devlive.sdk.openai.response.ImageResponse;
3537
import org.devlive.sdk.openai.response.ModelResponse;
3638
import org.devlive.sdk.openai.response.ModerationResponse;
@@ -212,6 +214,39 @@ public Object retrieveFileContent(String id)
212214
.blockingGet();
213215
}
214216

217+
public FineTuningResponse fineTuningJobs()
218+
{
219+
return this.api.fetchFineTuningJobs(ProviderUtils.getUrl(provider, UrlModel.FETCH_FINE_TUNING_JOBS))
220+
.blockingGet();
221+
}
222+
223+
public FineTuningResponse createFineTuningJob(FineTuningEntity configure)
224+
{
225+
return this.api.fetchCreateFineTuningJob(ProviderUtils.getUrl(provider, UrlModel.FETCH_FINE_TUNING_JOBS), configure)
226+
.blockingGet();
227+
}
228+
229+
public FineTuningResponse fineTuningJobEvents(String jobId)
230+
{
231+
String url = String.format(ProviderUtils.getUrl(provider, UrlModel.FETCH_FINE_TUNING_JOBS_EVENTS), jobId);
232+
return this.api.fetchFineTuningJobEvents(url)
233+
.blockingGet();
234+
}
235+
236+
public FineTuningEntity retrieveFineTuningJob(String jobId)
237+
{
238+
String url = String.format(ProviderUtils.getUrl(provider, UrlModel.FETCH_FINE_TUNING_JOBS_CONTENT), jobId);
239+
return this.api.fetchFineTuningJobContent(url)
240+
.blockingGet();
241+
}
242+
243+
public FineTuningEntity cancelFineTuningJob(String jobId)
244+
{
245+
String url = String.format(ProviderUtils.getUrl(provider, UrlModel.FETCH_FINE_TUNING_JOBS_CANCEL), jobId);
246+
return this.api.fetchCancelFineTuningJob(url)
247+
.blockingGet();
248+
}
249+
215250
private ObjectMapper createObjectMapper()
216251
{
217252
ObjectMapper objectMapper = new ObjectMapper();
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
}

src/main/java/org/devlive/sdk/openai/model/CompletionModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum CompletionModel
1616
"Capable of straightforward tasks, very fast, and lower cost.",
1717
null,
1818
2049),
19+
BABBAGE_002("babbage-002", null, null, 2049),
1920
BABBAGE_CODE_SEARCH_CODE("babbage-code-search-code", null, null, 4096),
2021
BABBAGE_CODE_SEARCH_TEXT("babbage-code-search-text", null, null, 4096),
2122
BABBAGE_SEARCH_DOCUMENT("babbage-search-document", null, null, 4096),
@@ -38,6 +39,7 @@ public enum CompletionModel
3839
"Most capable GPT-3 model. Can do any task the other models can do, often with higher quality.",
3940
null,
4041
2049),
42+
DAVINCI_002("davinci-002", null, null, 2049),
4143
DAVINCI_INSTRUCT_BETA("davinci-instruct-beta", null, null, 4096),
4244
DAVINCI_SEARCH_DOCUMENT("davinci-search-document", null, null, 4096),
4345
DAVINCI_SEARCH_QUERY("davinci-search-query", null, null, 4096),

src/main/java/org/devlive/sdk/openai/model/UrlModel.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ public enum UrlModel
1515
FETCH_AUDIO_TRANSCRIPTIONS,
1616
FETCH_MODERATIONS,
1717
FETCH_EDITS,
18-
FETCH_FILES
18+
FETCH_FILES,
19+
FETCH_FINE_TUNING_JOBS,
20+
FETCH_FINE_TUNING_JOBS_EVENTS,
21+
FETCH_FINE_TUNING_JOBS_CONTENT,
22+
FETCH_FINE_TUNING_JOBS_CANCEL,
1923
}

0 commit comments

Comments
 (0)