|
7 | 7 | import cn.hutool.http.Header; |
8 | 8 | import com.plexpt.chatgpt.api.Api; |
9 | 9 | import com.plexpt.chatgpt.entity.BaseResponse; |
| 10 | +import com.plexpt.chatgpt.entity.DeleteResponse; |
| 11 | +import com.plexpt.chatgpt.entity.FileResponse; |
10 | 12 | import com.plexpt.chatgpt.entity.audio.AudioResponse; |
| 13 | +import com.plexpt.chatgpt.entity.audio.SpeechRequest; |
11 | 14 | import com.plexpt.chatgpt.entity.audio.Transcriptions; |
12 | 15 | import com.plexpt.chatgpt.entity.billing.CreditGrantsResponse; |
13 | 16 | import com.plexpt.chatgpt.entity.billing.SubscriptionData; |
|
32 | 35 | import retrofit2.converter.jackson.JacksonConverterFactory; |
33 | 36 |
|
34 | 37 | import java.io.File; |
| 38 | +import java.io.InputStream; |
35 | 39 | import java.math.BigDecimal; |
36 | 40 | import java.net.Proxy; |
37 | 41 | import java.util.*; |
@@ -195,8 +199,7 @@ public EmbeddingResult createEmbeddings(String input, String user) { |
195 | 199 |
|
196 | 200 |
|
197 | 201 | public ImagesRensponse imageGeneration(Generations generations) { |
198 | | - Single<ImagesRensponse> imagesRensponse = |
199 | | - this.apiClient.imageGenerations(generations); |
| 202 | + Single<ImagesRensponse> imagesRensponse = this.apiClient.imageGenerations(generations); |
200 | 203 | return imagesRensponse.blockingGet(); |
201 | 204 | } |
202 | 205 |
|
@@ -229,6 +232,13 @@ public AudioResponse audioTranscription(File audio, Transcriptions transcription |
229 | 232 | return audioResponse.blockingGet(); |
230 | 233 | } |
231 | 234 |
|
| 235 | + public InputStream audioSpeech(SpeechRequest speechRequest) { |
| 236 | + Single<ResponseBody> audioResponse = this.apiClient.audioSpeech(speechRequest); |
| 237 | + ResponseBody response = audioResponse.blockingGet(); |
| 238 | + InputStream stream = response.byteStream(); |
| 239 | + return stream; |
| 240 | + } |
| 241 | + |
232 | 242 | public AudioResponse audioTranslation(File audio, Transcriptions transcriptions) { |
233 | 243 | RequestBody a = RequestBody.create(MediaType.parse("multipart/form-data;charset=UTF-8"), audio); |
234 | 244 | MultipartBody.Part aPart = MultipartBody.Part.createFormData("image", audio.getName(), a); |
@@ -282,4 +292,70 @@ public CreditGrantsResponse creditGrants() { |
282 | 292 | Single<CreditGrantsResponse> creditGrants = this.apiClient.creditGrants(); |
283 | 293 | return creditGrants.blockingGet(); |
284 | 294 | } |
| 295 | + |
| 296 | + /** |
| 297 | + * 列出文件 |
| 298 | + * List files |
| 299 | + */ |
| 300 | + public BaseResponse<FileResponse> listFiles() { |
| 301 | + Single<BaseResponse<FileResponse>> files = this.apiClient.listFiles(); |
| 302 | + return files.blockingGet(); |
| 303 | + } |
| 304 | + |
| 305 | + /** |
| 306 | + * 上传文件 |
| 307 | + * Upload file |
| 308 | + * |
| 309 | + * @param purpose 文件用途 |
| 310 | + * The purpose of the file |
| 311 | + * @param file 文件部分 |
| 312 | + * The file part |
| 313 | + * @return 文件响应 |
| 314 | + * File response |
| 315 | + */ |
| 316 | + public FileResponse uploadFile(String purpose, MultipartBody.Part file) { |
| 317 | + RequestBody purposeBody = RequestBody.create(MultipartBody.FORM, purpose); |
| 318 | + Single<FileResponse> files = this.apiClient.uploadFile(purposeBody, file); |
| 319 | + return files.blockingGet(); |
| 320 | + } |
| 321 | + |
| 322 | + /** |
| 323 | + * 删除文件 |
| 324 | + * Delete file |
| 325 | + * |
| 326 | + * @param fileId 文件ID |
| 327 | + * The file ID |
| 328 | + * @return 删除响应 |
| 329 | + * Delete response |
| 330 | + */ |
| 331 | + public DeleteResponse deleteFile(String fileId) { |
| 332 | + return this.apiClient.deleteFile(fileId).blockingGet(); |
| 333 | + } |
| 334 | + |
| 335 | + /** |
| 336 | + * 检索文件 |
| 337 | + * Retrieve file |
| 338 | + * |
| 339 | + * @param fileId 文件ID |
| 340 | + * The file ID |
| 341 | + * @return 文件响应 |
| 342 | + * File response |
| 343 | + */ |
| 344 | + public FileResponse retrieveFile(String fileId) { |
| 345 | + return this.apiClient.retrieveFile(fileId).blockingGet(); |
| 346 | + } |
| 347 | + |
| 348 | + /** |
| 349 | + * 检索文件内容 |
| 350 | + * Retrieve file content |
| 351 | + * |
| 352 | + * @param fileId 文件ID |
| 353 | + * The file ID |
| 354 | + * @return 文件内容响应 |
| 355 | + * File content response |
| 356 | + */ |
| 357 | + public ResponseBody retrieveFileContent(String fileId) { |
| 358 | + return this.apiClient.retrieveFileContent(fileId).blockingGet(); |
| 359 | + } |
| 360 | + |
285 | 361 | } |
0 commit comments