|
7 | 7 | import com.unfbx.chatgpt.constant.OpenAIConst; |
8 | 8 | import com.unfbx.chatgpt.entity.Tts.TextToSpeech; |
9 | 9 | import com.unfbx.chatgpt.entity.assistant.*; |
| 10 | +import com.unfbx.chatgpt.entity.assistant.message.MessageFileResponse; |
| 11 | +import com.unfbx.chatgpt.entity.assistant.message.MessageResponse; |
| 12 | +import com.unfbx.chatgpt.entity.assistant.message.ModifyMessage; |
| 13 | +import com.unfbx.chatgpt.entity.assistant.run.*; |
| 14 | +import com.unfbx.chatgpt.entity.assistant.thread.ThreadMessage; |
10 | 15 | import com.unfbx.chatgpt.entity.billing.BillingUsage; |
11 | 16 | import com.unfbx.chatgpt.entity.billing.CreditGrantsResponse; |
12 | 17 | import com.unfbx.chatgpt.entity.billing.Subscription; |
|
32 | 37 | import com.unfbx.chatgpt.entity.fineTune.job.FineTuneJobListResponse; |
33 | 38 | import com.unfbx.chatgpt.entity.fineTune.job.FineTuneJobResponse; |
34 | 39 | import com.unfbx.chatgpt.entity.images.*; |
| 40 | +import com.unfbx.chatgpt.entity.images.Image; |
35 | 41 | import com.unfbx.chatgpt.entity.models.Model; |
36 | 42 | import com.unfbx.chatgpt.entity.models.ModelResponse; |
37 | 43 | import com.unfbx.chatgpt.entity.moderations.Moderation; |
|
61 | 67 | import retrofit2.Retrofit; |
62 | 68 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; |
63 | 69 | import retrofit2.converter.jackson.JacksonConverterFactory; |
| 70 | +import retrofit2.http.*; |
| 71 | +import retrofit2.http.Headers; |
64 | 72 |
|
65 | 73 | import java.time.LocalDate; |
66 | 74 | import java.util.*; |
@@ -112,6 +120,12 @@ public class OpenAiClient { |
112 | 120 | @Getter |
113 | 121 | private OpenAiAuthInterceptor authInterceptor; |
114 | 122 |
|
| 123 | + /** |
| 124 | + * 默认的分页参数 |
| 125 | + */ |
| 126 | + @Getter |
| 127 | + private PageRequest pageRequest = PageRequest.builder().build(); |
| 128 | + |
115 | 129 | /** |
116 | 130 | * 构造器 |
117 | 131 | * |
@@ -1111,6 +1125,7 @@ public DeleteResponse deleteAssistantFile(String assistantId, String fileId) { |
1111 | 1125 | * @return 助手文件列表 |
1112 | 1126 | */ |
1113 | 1127 | public AssistantListResponse<AssistantFileResponse> assistantFiles(String assistantId, PageRequest pageRequest) { |
| 1128 | + pageRequest = Optional.ofNullable(pageRequest).orElse(this.getPageRequest()); |
1114 | 1129 | Single<AssistantListResponse<AssistantFileResponse>> deleteResponse = this.openAiApi.assistantFiles(assistantId, pageRequest.getLimit(), pageRequest.getOrder(), pageRequest.getBefore(), pageRequest.getAfter()); |
1115 | 1130 | return deleteResponse.blockingGet(); |
1116 | 1131 | } |
@@ -1160,6 +1175,223 @@ public DeleteResponse deleteThread(String threadId) { |
1160 | 1175 | return this.openAiApi.deleteThread(threadId).blockingGet(); |
1161 | 1176 | } |
1162 | 1177 |
|
| 1178 | + /** |
| 1179 | + * 为线程创建消息 |
| 1180 | + * |
| 1181 | + * @param threadId 线程id |
| 1182 | + * @param message message参数 |
| 1183 | + * @return |
| 1184 | + * @since 1.1.3 |
| 1185 | + */ |
| 1186 | + public MessageResponse message(String threadId, ThreadMessage message) { |
| 1187 | + return this.openAiApi.message(threadId, message).blockingGet(); |
| 1188 | + } |
| 1189 | + |
| 1190 | + /** |
| 1191 | + * 检索某一个线程对应的消息详细信息 |
| 1192 | + * |
| 1193 | + * @param threadId 线程id |
| 1194 | + * @param messageId 消息id |
| 1195 | + * @return |
| 1196 | + * @since 1.1.3 |
| 1197 | + */ |
| 1198 | + public MessageResponse retrieveMessage(String threadId, String messageId) { |
| 1199 | + return this.openAiApi.retrieveMessage(threadId, messageId).blockingGet(); |
| 1200 | + } |
| 1201 | + |
| 1202 | + /** |
| 1203 | + * 修改某一个线程对应的消息 |
| 1204 | + * |
| 1205 | + * @param threadId 线程id |
| 1206 | + * @param messageId 消息id |
| 1207 | + * @param message 消息体 |
| 1208 | + * @return |
| 1209 | + * @since 1.1.3 |
| 1210 | + */ |
| 1211 | + public MessageResponse modifyMessage(String threadId, String messageId, ModifyMessage message) { |
| 1212 | + return this.openAiApi.modifyMessage(threadId, messageId, message).blockingGet(); |
| 1213 | + } |
| 1214 | + |
| 1215 | + /** |
| 1216 | + * 获取某一个线程的消息集合 |
| 1217 | + * |
| 1218 | + * @param threadId 线程id |
| 1219 | + * @param pageRequest 分页信息 |
| 1220 | + * @return |
| 1221 | + * @since 1.1.3 |
| 1222 | + */ |
| 1223 | + public AssistantListResponse<MessageResponse> messages(String threadId, PageRequest pageRequest) { |
| 1224 | + pageRequest = Optional.ofNullable(pageRequest).orElse(this.getPageRequest()); |
| 1225 | + return this.openAiApi.messages(threadId, |
| 1226 | + pageRequest.getLimit(), |
| 1227 | + pageRequest.getOrder(), |
| 1228 | + pageRequest.getBefore(), |
| 1229 | + pageRequest.getAfter()).blockingGet(); |
| 1230 | + } |
| 1231 | + |
| 1232 | + /** |
| 1233 | + * 检索某一个线程对应某一个消息的一个文件信息 |
| 1234 | + * |
| 1235 | + * @param threadId 线程id |
| 1236 | + * @param messageId 消息id |
| 1237 | + * @param fileId 文件id |
| 1238 | + * @return |
| 1239 | + * @since 1.1.3 |
| 1240 | + */ |
| 1241 | + public MessageFileResponse retrieveMessageFile(String threadId, String messageId, String fileId) { |
| 1242 | + return this.openAiApi.retrieveMessageFile(threadId, messageId, fileId).blockingGet(); |
| 1243 | + } |
| 1244 | + |
| 1245 | + /** |
| 1246 | + * messageFiles集合 |
| 1247 | + * |
| 1248 | + * @param threadId 线程id |
| 1249 | + * @param messageId 消息id |
| 1250 | + * @param pageRequest 分页信息 |
| 1251 | + * @return |
| 1252 | + * @since 1.1.3 |
| 1253 | + */ |
| 1254 | + public AssistantListResponse<MessageFileResponse> messageFiles(String threadId, String messageId, PageRequest pageRequest) { |
| 1255 | + pageRequest = Optional.ofNullable(pageRequest).orElse(this.getPageRequest()); |
| 1256 | + return this.openAiApi.messageFiles(threadId, messageId, |
| 1257 | + pageRequest.getLimit(), |
| 1258 | + pageRequest.getOrder(), |
| 1259 | + pageRequest.getBefore(), |
| 1260 | + pageRequest.getAfter()).blockingGet(); |
| 1261 | + } |
| 1262 | + |
| 1263 | + |
| 1264 | + /** |
| 1265 | + * 创建Run |
| 1266 | + * |
| 1267 | + * @param threadId 线程id |
| 1268 | + * @param run run |
| 1269 | + * @return |
| 1270 | + * @since 1.1.3 |
| 1271 | + */ |
| 1272 | + public RunResponse run(String threadId, Run run) { |
| 1273 | + return this.openAiApi.run(threadId, run).blockingGet(); |
| 1274 | + } |
| 1275 | + |
| 1276 | + |
| 1277 | + /** |
| 1278 | + * 检索run详细信息 |
| 1279 | + * |
| 1280 | + * @param threadId 线程id |
| 1281 | + * @param runId run_id |
| 1282 | + * @return |
| 1283 | + * @since 1.1.3 |
| 1284 | + */ |
| 1285 | + public RunResponse retrieveRun(String threadId, String runId) { |
| 1286 | + return this.openAiApi.retrieveRun(threadId, runId).blockingGet(); |
| 1287 | + } |
| 1288 | + |
| 1289 | + /** |
| 1290 | + * 修改某一个run |
| 1291 | + * |
| 1292 | + * @param threadId 线程id |
| 1293 | + * @param runId run_id |
| 1294 | + * @param run 消息体 |
| 1295 | + * @return |
| 1296 | + * @since 1.1.3 |
| 1297 | + */ |
| 1298 | + public RunResponse modifyRun(String threadId, String runId, ModifyRun run) { |
| 1299 | + return this.openAiApi.modifyRun(threadId, runId, run).blockingGet(); |
| 1300 | + } |
| 1301 | + |
| 1302 | + |
| 1303 | + /** |
| 1304 | + * 获取某一个线程的run集合 |
| 1305 | + * |
| 1306 | + * @param threadId 线程id |
| 1307 | + * @param pageRequest 分页信息 |
| 1308 | + * @return |
| 1309 | + * @since 1.1.3 |
| 1310 | + */ |
| 1311 | + public AssistantListResponse<RunResponse> runs(String threadId, PageRequest pageRequest) { |
| 1312 | + pageRequest = Optional.ofNullable(pageRequest).orElse(this.getPageRequest()); |
| 1313 | + return this.openAiApi.runs(threadId, |
| 1314 | + pageRequest.getLimit(), |
| 1315 | + pageRequest.getOrder(), |
| 1316 | + pageRequest.getBefore(), |
| 1317 | + pageRequest.getAfter()).blockingGet(); |
| 1318 | + } |
| 1319 | + |
| 1320 | + |
| 1321 | + /** |
| 1322 | + * 获取某一个线程的run集合 |
| 1323 | + * |
| 1324 | + * @param threadId 线程id |
| 1325 | + * @param runId run id |
| 1326 | + * @param toolOutputs 为其提交输出的工具列表。 |
| 1327 | + * @return |
| 1328 | + * @since 1.1.3 |
| 1329 | + */ |
| 1330 | + public RunResponse submitToolOutputs(String threadId, String runId, ToolOutputBody toolOutputs) { |
| 1331 | + return this.openAiApi.submitToolOutputs(threadId, runId, toolOutputs).blockingGet(); |
| 1332 | + } |
| 1333 | + |
| 1334 | + |
| 1335 | + /** |
| 1336 | + * 取消正在进行中的run |
| 1337 | + * |
| 1338 | + * @param threadId 线程id |
| 1339 | + * @param runId run id |
| 1340 | + * @return |
| 1341 | + * @since 1.1.3 |
| 1342 | + */ |
| 1343 | + public RunResponse cancelRun(String threadId, String runId) { |
| 1344 | + return this.openAiApi.cancelRun(threadId, runId).blockingGet(); |
| 1345 | + } |
| 1346 | + |
| 1347 | + |
| 1348 | + /** |
| 1349 | + * 创建一个线程并在一个请求中运行它 |
| 1350 | + * |
| 1351 | + * @param threadRun 对象 |
| 1352 | + * @return |
| 1353 | + * @since 1.1.3 |
| 1354 | + */ |
| 1355 | + public RunResponse threadRun(ThreadRun threadRun) { |
| 1356 | + return this.openAiApi.threadRun(threadRun).blockingGet(); |
| 1357 | + } |
| 1358 | + |
| 1359 | + /** |
| 1360 | + * 检索run step详细信息 |
| 1361 | + * |
| 1362 | + * @param threadId 线程id |
| 1363 | + * @param runId run_id |
| 1364 | + * @param stepId step_id |
| 1365 | + * @return |
| 1366 | + * @since 1.1.3 |
| 1367 | + */ |
| 1368 | + public RunStepResponse retrieveRunStep(String threadId, String runId, String stepId) { |
| 1369 | + if (StrUtil.isBlank(stepId)) { |
| 1370 | + log.error("step id不能为空"); |
| 1371 | + throw new BaseException(CommonError.PARAM_ERROR); |
| 1372 | + } |
| 1373 | + return this.openAiApi.retrieveRunStep(threadId, runId, stepId).blockingGet(); |
| 1374 | + } |
| 1375 | + |
| 1376 | + |
| 1377 | + /** |
| 1378 | + * 获取某一个线程的run step集合 |
| 1379 | + * |
| 1380 | + * @param threadId 线程id |
| 1381 | + * @param runId run_id |
| 1382 | + * @param pageRequest 分页信息 |
| 1383 | + * @return |
| 1384 | + * @since 1.1.3 |
| 1385 | + */ |
| 1386 | + public AssistantListResponse<RunStepResponse> runSteps(String threadId, String runId, PageRequest pageRequest) { |
| 1387 | + pageRequest = Optional.ofNullable(pageRequest).orElse(this.getPageRequest()); |
| 1388 | + return this.openAiApi.runSteps(threadId, runId, |
| 1389 | + pageRequest.getLimit(), |
| 1390 | + pageRequest.getOrder(), |
| 1391 | + pageRequest.getBefore(), |
| 1392 | + pageRequest.getAfter()).blockingGet(); |
| 1393 | + } |
| 1394 | + |
1163 | 1395 |
|
1164 | 1396 | public static final class Builder { |
1165 | 1397 | /** |
|
0 commit comments