Skip to content

Commit 2265236

Browse files
Grt1228guorutao
authored andcommitted
feature 1.1.3 assistant api开发ing
1 parent 50e748b commit 2265236

File tree

9 files changed

+589
-39
lines changed

9 files changed

+589
-39
lines changed

src/main/java/com/unfbx/chatgpt/OpenAiApi.java

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import com.unfbx.chatgpt.entity.models.ModelResponse;
3434
import com.unfbx.chatgpt.entity.moderations.Moderation;
3535
import com.unfbx.chatgpt.entity.moderations.ModerationResponse;
36+
import com.unfbx.chatgpt.entity.thread.ModifyThread;
37+
import com.unfbx.chatgpt.entity.thread.Thread;
38+
import com.unfbx.chatgpt.entity.thread.ThreadResponse;
3639
import com.unfbx.chatgpt.entity.whisper.WhisperResponse;
3740
import io.reactivex.Single;
3841
import okhttp3.MultipartBody;
@@ -450,7 +453,8 @@ Single<WhisperResponse> speechToTextTranslations(@Part MultipartBody.Part file,
450453
/**
451454
* 修改助手信息
452455
*
453-
* @param assistant 修改助手参数
456+
* @param assistantId 助手id
457+
* @param assistant 修改助手参数
454458
* @return 助手信息
455459
* @since 1.1.3
456460
*/
@@ -477,39 +481,105 @@ Single<WhisperResponse> speechToTextTranslations(@Part MultipartBody.Part file,
477481
* @param order 排序类型
478482
* @param before 分页参数,之前的id,默认值:null
479483
* @param after 分页参数,之后的id,默认值:null
480-
* @return AssistantListResponse #Assistant
484+
* @return AssistantListResponse #AssistantResponse
481485
* @since 1.1.3
482486
*/
483487
@GET("v1/assistants")
484488
@Headers("OpenAI-Beta: assistants=v1")
485-
Single<AssistantListResponse<Assistant>> assistants(@Query("limit") Integer limit, @Query("order") Integer order, @Query("before") String before, @Query("after") String after);
489+
Single<AssistantListResponse<AssistantResponse>> assistants(@Query("limit") Integer limit, @Query("order") String order, @Query("before") String before, @Query("after") String after);
486490

487491
/**
488492
* 创建助手文件
489493
*
490494
* @param assistantId 助手id
491-
* @param assistantFile 文件id
495+
* @param assistantFile 文件信息
492496
* @return 返回信息AssistantResponse
493497
*/
494498
@POST("v1/assistants/{assistant_id}/files")
495499
@Headers("OpenAI-Beta: assistants=v1")
496-
Single<AssistantResponse> assistantFile(@Path("assistant_id") String assistantId, @Body AssistantFile assistantFile);
497-
500+
Single<AssistantFileResponse> assistantFile(@Path("assistant_id") String assistantId, @Body AssistantFile assistantFile);
498501

502+
/**
503+
* 检索助手文件
504+
*
505+
* @param assistantId 助手id
506+
* @param fileId 文件id
507+
* @return 助手文件信息
508+
*/
499509
@GET("v1/assistants/{assistant_id}/files/{file_id}")
500510
@Headers("OpenAI-Beta: assistants=v1")
501-
Single<AssistantResponse> retrieveAssistantFile(@Path("assistant_id") String assistantId, @Path("file_id") String fileId);
502-
511+
Single<AssistantFileResponse> retrieveAssistantFile(@Path("assistant_id") String assistantId, @Path("file_id") String fileId);
503512

513+
/**
514+
* 删除助手文件
515+
*
516+
* @param assistantId 助手id
517+
* @param fileId 文件id
518+
* @return 删除状态
519+
*/
504520
@DELETE("v1/assistants/{assistant_id}/files/{file_id}")
505521
@Headers("OpenAI-Beta: assistants=v1")
506522
Single<DeleteResponse> deleteAssistantFile(@Path("assistant_id") String assistantId, @Path("file_id") String fileId);
507523

508-
524+
/**
525+
* 助手文件列表
526+
*
527+
* @param assistantId 助手id
528+
* @param limit 一页数据大小
529+
* @param order 排序类型
530+
* @param before 分页参数,之前的id,默认值:null
531+
* @param after 分页参数,之后的id,默认值:null
532+
* @return 助手文件列表
533+
*/
509534
@GET("v1/assistants/{assistant_id}/files")
510535
@Headers("OpenAI-Beta: assistants=v1")
511536
Single<AssistantListResponse<AssistantFileResponse>> assistantFiles(@Path("assistant_id") String assistantId,
512-
@Query("limit") Integer limit, @Query("order") Integer order, @Query("before") String before, @Query("after") String after);
537+
@Query("limit") Integer limit, @Query("order") String order, @Query("before") String before, @Query("after") String after);
538+
539+
540+
/**
541+
* 创建线程
542+
*
543+
* @param thread 创建线程参数
544+
* @return 线程信息
545+
* @since 1.1.3
546+
*/
547+
@POST("v1/threads")
548+
@Headers("OpenAI-Beta: assistants=v1")
549+
Single<ThreadResponse> thread(@Body Thread thread);
513550

514551

552+
/**
553+
* 获取线程详细信息
554+
*
555+
* @param threadId 线程id
556+
* @return 线程信息
557+
* @since 1.1.3
558+
*/
559+
@GET("v1/threads/{thread_id}")
560+
@Headers("OpenAI-Beta: assistants=v1")
561+
Single<ThreadResponse> retrieveThread(@Path("thread_id") String threadId);
562+
563+
/**
564+
* 修改线程信息
565+
*
566+
* @param threadId 线程id
567+
* @param thread 线程信息
568+
* @return 线程信息
569+
* @since 1.1.3
570+
*/
571+
@POST("v1/threads/{thread_id}")
572+
@Headers("OpenAI-Beta: assistants=v1")
573+
Single<ThreadResponse> modifyThread(@Path("thread_id") String threadId, @Body ModifyThread thread);
574+
575+
/**
576+
* 删除线程
577+
*
578+
* @param threadId 线程id
579+
* @return 删除状态
580+
* @since 1.1.3
581+
*/
582+
@DELETE("v1/threads/{thread_id}")
583+
@Headers("OpenAI-Beta: assistants=v1")
584+
Single<DeleteResponse> deleteThread(@Path("thread_id") String threadId);
515585
}

src/main/java/com/unfbx/chatgpt/OpenAiClient.java

Lines changed: 153 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import cn.hutool.json.JSONUtil;
77
import com.unfbx.chatgpt.constant.OpenAIConst;
88
import com.unfbx.chatgpt.entity.Tts.TextToSpeech;
9-
import com.unfbx.chatgpt.entity.assistant.Assistant;
10-
import com.unfbx.chatgpt.entity.assistant.AssistantResponse;
9+
import com.unfbx.chatgpt.entity.assistant.*;
1110
import com.unfbx.chatgpt.entity.billing.BillingUsage;
1211
import com.unfbx.chatgpt.entity.billing.CreditGrantsResponse;
1312
import com.unfbx.chatgpt.entity.billing.Subscription;
1413
import com.unfbx.chatgpt.entity.chat.*;
1514
import com.unfbx.chatgpt.entity.common.DeleteResponse;
1615
import com.unfbx.chatgpt.entity.common.OpenAiResponse;
16+
import com.unfbx.chatgpt.entity.common.PageRequest;
1717
import com.unfbx.chatgpt.entity.completions.Completion;
1818
import com.unfbx.chatgpt.entity.completions.CompletionResponse;
1919
import com.unfbx.chatgpt.entity.edits.Edit;
@@ -36,6 +36,9 @@
3636
import com.unfbx.chatgpt.entity.models.ModelResponse;
3737
import com.unfbx.chatgpt.entity.moderations.Moderation;
3838
import com.unfbx.chatgpt.entity.moderations.ModerationResponse;
39+
import com.unfbx.chatgpt.entity.thread.ModifyThread;
40+
import com.unfbx.chatgpt.entity.thread.Thread;
41+
import com.unfbx.chatgpt.entity.thread.ThreadResponse;
3942
import com.unfbx.chatgpt.entity.whisper.Transcriptions;
4043
import com.unfbx.chatgpt.entity.whisper.Translations;
4144
import com.unfbx.chatgpt.entity.whisper.WhisperResponse;
@@ -50,19 +53,15 @@
5053
import com.unfbx.chatgpt.plugin.PluginParam;
5154
import io.reactivex.Single;
5255
import lombok.Getter;
53-
import lombok.SneakyThrows;
5456
import lombok.extern.slf4j.Slf4j;
5557
import okhttp3.*;
5658
import org.jetbrains.annotations.NotNull;
5759
import retrofit2.Call;
5860
import retrofit2.Callback;
59-
import retrofit2.Response;
6061
import retrofit2.Retrofit;
6162
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
6263
import retrofit2.converter.jackson.JacksonConverterFactory;
6364

64-
import java.io.IOException;
65-
import java.io.InputStream;
6665
import java.time.LocalDate;
6766
import java.util.*;
6867
import java.util.concurrent.TimeUnit;
@@ -118,8 +117,8 @@ public class OpenAiClient {
118117
*
119118
* @return OpenAiClient.Builder
120119
*/
121-
public static OpenAiClient.Builder builder() {
122-
return new OpenAiClient.Builder();
120+
public static Builder builder() {
121+
return new Builder();
123122
}
124123

125124
/**
@@ -1013,11 +1012,153 @@ public void textToSpeech(TextToSpeech textToSpeech, Callback callback) {
10131012
* @return 返回助手信息
10141013
* @since 1.1.2
10151014
*/
1016-
public AssistantResponse assistants(Assistant assistant) {
1017-
Single<AssistantResponse> assistants = this.openAiApi.assistant(assistant);
1015+
public AssistantResponse assistant(Assistant assistant) {
1016+
Single<AssistantResponse> assistantResponse = this.openAiApi.assistant(assistant);
1017+
return assistantResponse.blockingGet();
1018+
}
1019+
1020+
/**
1021+
* 获取助手详细信息
1022+
*
1023+
* @param assistantId 助手id
1024+
* @return 助手信息
1025+
* @since 1.1.3
1026+
*/
1027+
public AssistantResponse retrieveAssistant(String assistantId) {
1028+
Single<AssistantResponse> assistant = this.openAiApi.retrieveAssistant(assistantId);
1029+
return assistant.blockingGet();
1030+
}
1031+
1032+
1033+
/**
1034+
* 修改助手信息
1035+
*
1036+
* @param assistantId 助手id
1037+
* @param assistant 修改助手参数
1038+
* @return 助手信息
1039+
* @since 1.1.3
1040+
*/
1041+
public AssistantResponse modifyAssistant(String assistantId, Assistant assistant) {
1042+
Single<AssistantResponse> assistantResponse = this.openAiApi.modifyAssistant(assistantId, assistant);
1043+
return assistantResponse.blockingGet();
1044+
}
1045+
1046+
/**
1047+
* 删除助手
1048+
*
1049+
* @param assistantId 助手id
1050+
* @return 删除状态
1051+
* @since 1.1.3
1052+
*/
1053+
public DeleteResponse deleteAssistant(String assistantId) {
1054+
Single<DeleteResponse> deleteAssistant = this.openAiApi.deleteAssistant(assistantId);
1055+
return deleteAssistant.blockingGet();
1056+
}
1057+
1058+
/**
1059+
* 助手列表
1060+
*
1061+
* @param pageRequest 分页信息
1062+
* @return AssistantListResponse #AssistantResponse
1063+
* @since 1.1.3
1064+
*/
1065+
public AssistantListResponse<AssistantResponse> assistants(PageRequest pageRequest) {
1066+
Single<AssistantListResponse<AssistantResponse>> assistants = this.openAiApi.assistants(pageRequest.getLimit(), pageRequest.getOrder(), pageRequest.getBefore(), pageRequest.getAfter());
10181067
return assistants.blockingGet();
10191068
}
10201069

1070+
/**
1071+
* 创建助手文件
1072+
*
1073+
* @param assistantId 助手id
1074+
* @param assistantId 文件信息
1075+
* @return 返回信息AssistantResponse
1076+
*/
1077+
public AssistantFileResponse assistantFile(String assistantId, AssistantFile assistantFile) {
1078+
Single<AssistantFileResponse> assistantFileResponse = this.openAiApi.assistantFile(assistantId, assistantFile);
1079+
return assistantFileResponse.blockingGet();
1080+
}
1081+
1082+
/**
1083+
* 检索助手文件
1084+
*
1085+
* @param assistantId 助手id
1086+
* @param fileId 文件信息
1087+
* @return 助手文件信息
1088+
*/
1089+
public AssistantFileResponse retrieveAssistantFile(String assistantId, String fileId) {
1090+
Single<AssistantFileResponse> assistantFileResponse = this.openAiApi.retrieveAssistantFile(assistantId, fileId);
1091+
return assistantFileResponse.blockingGet();
1092+
}
1093+
1094+
/**
1095+
* 删除助手文件
1096+
*
1097+
* @param assistantId 助手id
1098+
* @param fileId 文件信息
1099+
* @return 删除状态
1100+
*/
1101+
public DeleteResponse deleteAssistantFile(String assistantId, String fileId) {
1102+
Single<DeleteResponse> deleteResponse = this.openAiApi.deleteAssistantFile(assistantId, fileId);
1103+
return deleteResponse.blockingGet();
1104+
}
1105+
1106+
/**
1107+
* 助手文件列表
1108+
*
1109+
* @param assistantId 助手id
1110+
* @param pageRequest 分页信息
1111+
* @return 助手文件列表
1112+
*/
1113+
public AssistantListResponse<AssistantFileResponse> assistantFiles(String assistantId, PageRequest pageRequest) {
1114+
Single<AssistantListResponse<AssistantFileResponse>> deleteResponse = this.openAiApi.assistantFiles(assistantId, pageRequest.getLimit(), pageRequest.getOrder(), pageRequest.getBefore(), pageRequest.getAfter());
1115+
return deleteResponse.blockingGet();
1116+
}
1117+
1118+
/**
1119+
* 创建线程
1120+
*
1121+
* @param thread 创建线程参数
1122+
* @return 线程信息
1123+
* @since 1.1.3
1124+
*/
1125+
public ThreadResponse thread(Thread thread) {
1126+
return this.openAiApi.thread(thread).blockingGet();
1127+
}
1128+
1129+
/**
1130+
* 获取线程详细信息
1131+
*
1132+
* @param threadId 线程id
1133+
* @return 线程信息
1134+
* @since 1.1.3
1135+
*/
1136+
public ThreadResponse retrieveThread(String threadId) {
1137+
return this.openAiApi.retrieveThread(threadId).blockingGet();
1138+
}
1139+
1140+
/**
1141+
* 修改线程信息
1142+
*
1143+
* @param threadId 线程id
1144+
* @param thread 线程信息
1145+
* @return 线程信息
1146+
* @since 1.1.3
1147+
*/
1148+
public ThreadResponse modifyThread(String threadId, ModifyThread thread) {
1149+
return this.openAiApi.modifyThread(threadId, thread).blockingGet();
1150+
}
1151+
1152+
/**
1153+
* 删除线程
1154+
*
1155+
* @param threadId 线程id
1156+
* @return 删除状态
1157+
* @since 1.1.3
1158+
*/
1159+
public DeleteResponse deleteThread(String threadId) {
1160+
return this.openAiApi.deleteThread(threadId).blockingGet();
1161+
}
10211162

10221163

10231164
public static final class Builder {
@@ -1028,7 +1169,7 @@ public static final class Builder {
10281169
/**
10291170
* api请求地址,结尾处有斜杠
10301171
*
1031-
* @see com.unfbx.chatgpt.constant.OpenAIConst
1172+
* @see OpenAIConst
10321173
*/
10331174
private String apiHost;
10341175
/**
@@ -1052,7 +1193,7 @@ public Builder() {
10521193
/**
10531194
* @param val api请求地址,结尾处有斜杠
10541195
* @return Builder对象
1055-
* @see com.unfbx.chatgpt.constant.OpenAIConst
1196+
* @see OpenAIConst
10561197
*/
10571198
public Builder apiHost(String val) {
10581199
apiHost = val;

src/main/java/com/unfbx/chatgpt/entity/assistant/AssistantFile.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,4 @@ public class AssistantFile implements Serializable {
2222
*/
2323
@JsonProperty("file_id")
2424
private String fileId;
25-
/**
26-
* 助手id
27-
*/
28-
@JsonProperty("assistant_id")
29-
private String assistantId;
3025
}

0 commit comments

Comments
 (0)