Skip to content

Commit e878240

Browse files
authored
[Files] Support files (#22)
2 parents 0d60f47 + 065a065 commit e878240

File tree

16 files changed

+533
-37
lines changed

16 files changed

+533
-37
lines changed

.github/workflows/checker.yml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,11 @@ jobs:
5252
- run: chmod 755 ./mvnw
5353
- run: ./mvnw clean install findbugs:findbugs -Dcheckstyle.skip -Dgpg.skip -Dskip.yarn -DskipTests=true
5454

55-
before_checker_test:
55+
before_checker_package:
5656
runs-on: ubuntu-latest
5757
needs:
5858
- before_checker_style
5959
- before_checker_bugs
60-
steps:
61-
- name: Checkout
62-
uses: actions/checkout@v3
63-
- name: Maven Checker Tests
64-
uses: actions/setup-java@v3
65-
with:
66-
java-version: |
67-
8
68-
11
69-
16
70-
17
71-
distribution: 'temurin'
72-
- run: chmod 755 ./mvnw
73-
- run: |
74-
./mvnw clean install test -Dfindbugs.skip -Dcheckstyle.skip -Dgpg.skip -Dskip.yarn -Dopenai.token=${{ secrets.OPENAI_TOKEN }} -Dproxy.token=${{ secrets.PROXY_TOKEN }} -Dproxy.host=${{ secrets.PROXY_HOST }} -Dazure.token=${{ secrets.AZURE_TOKEN}} -Dclaude.token=${{ secrets.CLAUDE_TOKEN }}
75-
76-
before_checker_package:
77-
runs-on: ubuntu-latest
78-
needs:
79-
- before_checker_test
8060
steps:
8161
- name: Checkout
8262
uses: actions/checkout@v3
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Files
3+
---
4+
5+
!!! Note
6+
7+
Please build the client before calling, the build code is as follows:
8+
9+
```java
10+
OpenAiClient client = OpenAiClient.builder()
11+
.apiHost("https://api.openai.com")
12+
.apiKey(System.getProperty("openai.token"))
13+
.build();
14+
```
15+
16+
`System.getProperty("openai.token")` is the key to access the API authorization.
17+
18+
### List files
19+
20+
---
21+
22+
Returns a list of files that belong to the user's organization.
23+
24+
```java
25+
client.files()
26+
```
27+
28+
Returns:
29+
30+
```json
31+
{
32+
"data": [
33+
{
34+
"id": "file-ccdDZrC3iZVNiQVeEA6Z66wf",
35+
"object": "file",
36+
"bytes": 175,
37+
"createdTime": "2022-02-02 22:22:22",
38+
"filename": "train.jsonl",
39+
"purpose": "search"
40+
}
41+
],
42+
"object": "list"
43+
}
44+
```
45+
46+
### Upload file
47+
48+
---
49+
50+
Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact openai if you need to increase the storage limit.
51+
52+
```java
53+
String file = this.getClass().getResource("/test.jsonl").getFile();
54+
FileEntity configure = FileEntity.builder()
55+
.file(new File(file))
56+
.build();
57+
this.client.uploadFile(configure);
58+
```
59+
60+
Returns:
61+
62+
```json
63+
{
64+
"id": "file-XjGxS3KTG0uNmNOK362iJua3",
65+
"object": "file",
66+
"bytes": 140,
67+
"createdTime": "2022-02-02 22:22:22",
68+
"filename": "test.jsonl",
69+
"purpose": "fine-tune"
70+
}
71+
```
72+
73+
### Delete file
74+
75+
---
76+
77+
Delete a file.
78+
79+
```java
80+
String id = "file-XjGxS3KTG0uNmNOK362iJua3";
81+
this.client.deleteFile(entity.getId());
82+
```
83+
84+
Returns:
85+
86+
```json
87+
{
88+
"id": "file-XjGxS3KTG0uNmNOK362iJua3",
89+
"object": "file",
90+
"deleted": true
91+
}
92+
```
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Files
3+
---
4+
5+
!!! Note
6+
7+
调用前请先构建客户端,构建代码如下:
8+
9+
```java
10+
OpenAiClient client = OpenAiClient.builder()
11+
.apiHost("https://api.openai.com")
12+
.apiKey(System.getProperty("openai.token"))
13+
.build();
14+
```
15+
16+
`System.getProperty("openai.token")` 是访问 API 授权的关键。
17+
18+
### List files
19+
20+
---
21+
22+
返回属于用户组织的文件列表。
23+
24+
```java
25+
client.files()
26+
```
27+
28+
返回:
29+
30+
```json
31+
{
32+
"data": [
33+
{
34+
"id": "file-ccdDZrC3iZVNiQVeEA6Z66wf",
35+
"object": "file",
36+
"bytes": 175,
37+
"createdTime": "2022-02-02 22:22:22",
38+
"filename": "train.jsonl",
39+
"purpose": "search"
40+
}
41+
],
42+
"object": "list"
43+
}
44+
```
45+
46+
### Upload file
47+
48+
---
49+
50+
上传包含要在各种端点/功能之间使用的文档的文件。目前,一个组织上传的所有文件大小最大可达1GB。如果您需要增加存储限制,请联系 OpenAI。
51+
52+
```java
53+
String file = this.getClass().getResource("/test.jsonl").getFile();
54+
FileEntity configure = FileEntity.builder()
55+
.file(new File(file))
56+
.build();
57+
this.client.uploadFile(configure);
58+
```
59+
60+
返回:
61+
62+
```json
63+
{
64+
"id": "file-XjGxS3KTG0uNmNOK362iJua3",
65+
"object": "file",
66+
"bytes": 140,
67+
"createdTime": "2022-02-02 22:22:22",
68+
"filename": "test.jsonl",
69+
"purpose": "fine-tune"
70+
}
71+
```
72+
73+
### Delete file
74+
75+
---
76+
77+
删除文件
78+
79+
```java
80+
String id = "file-XjGxS3KTG0uNmNOK362iJua3";
81+
this.client.deleteFile(entity.getId());
82+
```
83+
84+
返回:
85+
86+
```json
87+
{
88+
"id": "file-XjGxS3KTG0uNmNOK362iJua3",
89+
"object": "file",
90+
"deleted": true
91+
}
92+
```

docs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ nav:
8484
- reference/openai/audio.md
8585
- reference/openai/moderations.md
8686
- reference/openai/edits.md
87+
- reference/openai/files.md
8788
- Azure Open Ai:
8889
- reference/azure/completions.md
8990
- reference/azure/completions_chat.md

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.6.0</version>
8+
<version>1.7.0-SNAPSHOT</version>
99

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

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

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.devlive.sdk.openai.entity.CompletionEntity;
88
import org.devlive.sdk.openai.entity.EditEntity;
99
import org.devlive.sdk.openai.entity.EmbeddingEntity;
10+
import org.devlive.sdk.openai.entity.FileEntity;
1011
import org.devlive.sdk.openai.entity.ImageEntity;
1112
import org.devlive.sdk.openai.entity.ModelEntity;
1213
import org.devlive.sdk.openai.entity.ModerationEntity;
@@ -16,11 +17,13 @@
1617
import org.devlive.sdk.openai.response.CompleteResponse;
1718
import org.devlive.sdk.openai.response.EditResponse;
1819
import org.devlive.sdk.openai.response.EmbeddingResponse;
20+
import org.devlive.sdk.openai.response.FileResponse;
1921
import org.devlive.sdk.openai.response.ImageResponse;
2022
import org.devlive.sdk.openai.response.ModelResponse;
2123
import org.devlive.sdk.openai.response.ModerationResponse;
2224
import org.devlive.sdk.openai.response.UserKeyResponse;
2325
import retrofit2.http.Body;
26+
import retrofit2.http.DELETE;
2427
import retrofit2.http.GET;
2528
import retrofit2.http.Multipart;
2629
import retrofit2.http.POST;
@@ -52,14 +55,14 @@ public interface DefaultApi
5255
*/
5356
@POST
5457
Single<CompleteResponse> fetchCompletions(@Url String url,
55-
@Body CompletionEntity configure);
58+
@Body CompletionEntity configure);
5659

5760
/**
5861
* Creates a model response for the given chat conversation.
5962
*/
6063
@POST
6164
Single<ChatResponse> fetchChatCompletions(@Url String url,
62-
@Body ChatEntity configure);
65+
@Body ChatEntity configure);
6366

6467
/**
6568
* Get all keys
@@ -78,33 +81,33 @@ Single<ChatResponse> fetchChatCompletions(@Url String url,
7881
*/
7982
@POST
8083
Single<ImageResponse> fetchImagesGenerations(@Url String url,
81-
@Body ImageEntity configure);
84+
@Body ImageEntity configure);
8285

8386
/**
8487
* Creates an edited or extended image given an original image and a prompt.
8588
*/
8689
@POST
8790
@Multipart
8891
Single<ImageResponse> fetchImagesEdits(@Url String url,
89-
@Part() MultipartBody.Part image,
90-
@Part() MultipartBody.Part mask,
91-
@PartMap Map<String, RequestBody> configure);
92+
@Part() MultipartBody.Part image,
93+
@Part() MultipartBody.Part mask,
94+
@PartMap Map<String, RequestBody> configure);
9295

9396
/**
9497
* Creates a variation of a given image.
9598
*/
9699
@POST
97100
@Multipart
98101
Single<ImageResponse> fetchImagesVariations(@Url String url,
99-
@Part() MultipartBody.Part image,
100-
@PartMap Map<String, RequestBody> configure);
102+
@Part() MultipartBody.Part image,
103+
@PartMap Map<String, RequestBody> configure);
101104

102105
/**
103106
* Creates an embedding vector representing the input text.
104107
*/
105108
@POST
106109
Single<EmbeddingResponse> fetchEmbeddings(@Url String url,
107-
@Body EmbeddingEntity configure);
110+
@Body EmbeddingEntity configure);
108111

109112
/**
110113
* Transcribes audio into the input language.
@@ -113,22 +116,46 @@ Single<EmbeddingResponse> fetchEmbeddings(@Url String url,
113116
@POST
114117
@Multipart
115118
Single<AudioResponse> fetchAudioTranscriptions(@Url String url,
116-
@Part() MultipartBody.Part audio,
117-
@PartMap Map<String, RequestBody> configure);
119+
@Part() MultipartBody.Part audio,
120+
@PartMap Map<String, RequestBody> configure);
118121

119122
/**
120123
* Classifies if text violates OpenAI's Content Policy
121124
* 对文本是否违反 OpenAI 的内容政策进行分类
122125
*/
123126
@POST
124127
Single<ModerationResponse> fetchModerations(@Url String url,
125-
@Body ModerationEntity configure);
128+
@Body ModerationEntity configure);
126129

127130
/**
128131
* Creates a new edit for the provided input, instruction, and parameters.
129132
* 为提供的输入、指令和参数创建新的编辑。
130133
*/
131134
@POST
132135
Single<EditResponse> fetchEdits(@Url String url,
133-
@Body EditEntity configure);
136+
@Body EditEntity configure);
137+
138+
/**
139+
* Returns a list of files that belong to the user's organization.
140+
* 返回属于用户组织的文件列表。
141+
*/
142+
@GET
143+
Single<FileResponse> fetchFiles(@Url String url);
144+
145+
/**
146+
* Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit.
147+
* 上传包含要在各种端点/功能之间使用的文档的文件。目前,一个组织上传的所有文件大小最大可达1GB。如果您需要增加存储限制,请联系我们。
148+
*/
149+
@POST
150+
@Multipart
151+
Single<FileEntity> fetchUploadFile(@Url String url,
152+
@Part() MultipartBody.Part file,
153+
@PartMap Map<String, RequestBody> configure);
154+
155+
/**
156+
* Delete a file.
157+
* 删除文件。
158+
*/
159+
@DELETE
160+
Single<FileResponse> fetchDeleteFile(@Url String url);
134161
}

0 commit comments

Comments
 (0)