2
2
3
3
import com .crowdin .client .ai .model .AiProvider ;
4
4
import com .crowdin .client .ai .model .AiProviderRequest ;
5
+ import com .crowdin .client .ai .model .AiReportGenerate ;
6
+ import com .crowdin .client .ai .model .AiReportFormat ;
5
7
import com .crowdin .client .ai .model .Credentials ;
6
8
import com .crowdin .client .ai .model .AiProviderModel ;
7
9
import com .crowdin .client .ai .model .AiSetting ;
12
14
import com .crowdin .client .ai .model .FineTuningJob ;
13
15
import com .crowdin .client .ai .model .FineTuningJobRequest ;
14
16
import com .crowdin .client .ai .model .FineTuningJobRequest .Hyperparameters ;
17
+ import com .crowdin .client .ai .model .GenerateAiReportRequest ;
18
+ import com .crowdin .client .ai .model .GenerateAiReportRequestSchema ;
19
+ import com .crowdin .client .core .model .DownloadLink ;
15
20
import com .crowdin .client .core .model .Pagination ;
16
21
import com .crowdin .client .core .model .PatchRequest ;
17
22
import com .crowdin .client .core .model .PatchOperation ;
33
38
import org .apache .http .client .methods .HttpPost ;
34
39
import org .junit .jupiter .api .Test ;
35
40
36
-
37
41
import static org .junit .jupiter .api .Assertions .assertEquals ;
38
42
import static org .junit .jupiter .api .Assertions .assertNotNull ;
39
43
@@ -52,17 +56,20 @@ public class AIApiTest extends TestClient {
52
56
private static final long size = 1L ;
53
57
private static final String status = "finished" ;
54
58
private static final String jobIdentifier = "50fb3506-4127-4ba8-8296-f97dc7e3e0c3" ;
59
+ private static final String aiReportId = "50fb3506-4127-4ba8-8296-f97dc7e3e0c3" ;
55
60
private static final TimeZone tz = TimeZone .getTimeZone ("GMT" );
56
61
private final Calendar calendar = GregorianCalendar .getInstance (tz );
57
62
58
-
59
63
private static final String FINE_TUNING_DATASET_GENERATION_STATUS_PATH = "%s/users/%d/ai/prompts/%d/fine-tuning/datasets/%s" ;
60
64
private static final String GENERATE_FINE_TUNING_DATASET_PATH = "%s/users/%d/ai/prompts/%d/fine-tuning/datasets" ;
61
65
private static final String GET_FINE_TUNING_EVENT_LIST_PATH = "%s/users/%d/ai/prompts/%d/fine-tuning/jobs/%s/events" ;
62
66
private static final String GET_FINE_TUNING_JOB_LIST_PATH = "%s/users/%d/ai/prompts/fine-tuning/jobs" ;
63
67
private static final String CREATE_FINE_TUNING_JOB_PATH = "%s/users/%d/ai/prompts/%d/fine-tuning/jobs" ;
64
68
private static final String GET_FINE_TUNING_JOB_STATUS_PATH = "%s/users/%d/ai/prompts/%d/fine-tuning/jobs/%s" ;
65
69
private static final String FINE_TUNING_DATASET_DOWNLOAD_PATH = "%s/users/%d/ai/prompts/%d/fine-tuning/datasets/%s/download" ;
70
+ private static final String GENERATE_AI_REPORT_PATH = "%s/users/%d/ai/reports" ;
71
+ private static final String CHECK_AI_REPORT_GENERATION_PATH = "%s/users/%d/ai/reports/%s" ;
72
+ private static final String DOWNLOAD_AI_REPORT_PATH = "%s/users/%d/ai/reports/%s/download" ;
66
73
private static final String GET_SETTINGS = "%s/users/%d/ai/settings" ;
67
74
private static final String LIST_AI_PROVIDERS = "%s/users/%d/ai/providers" ;
68
75
private static final String GET_AI_PROVIDER = "%s/users/%d/ai/providers/%d" ;
@@ -73,6 +80,7 @@ private Date getDateTime(int year, int month, int date, int hour, int minute, in
73
80
calendar .set (Calendar .MILLISECOND , 0 );
74
81
return calendar .getTime ();
75
82
}
83
+
76
84
@ Override
77
85
public List <RequestMock > getMocks () {
78
86
return Arrays .asList (
@@ -83,6 +91,10 @@ public List<RequestMock> getMocks() {
83
91
RequestMock .build (String .format (CREATE_FINE_TUNING_JOB_PATH , this .url , userId , aiPromptId ), HttpPost .METHOD_NAME , "api/ai/fineTuningJobRequest.json" , "api/ai/fineTuningJobResponse.json" ),
84
92
RequestMock .build (String .format (GET_FINE_TUNING_JOB_STATUS_PATH , this .url , userId , aiPromptId , jobIdentifier ), HttpGet .METHOD_NAME , "api/ai/fineTuningJobStatusResponse.json" ),
85
93
RequestMock .build (String .format (FINE_TUNING_DATASET_DOWNLOAD_PATH , this .url , userId , aiPromptId , jobIdentifier ), HttpGet .METHOD_NAME , "api/ai/downloadFineTuningDataset.json" ),
94
+ RequestMock .build (String .format (GENERATE_AI_REPORT_PATH , this .url , userId ), HttpPost .METHOD_NAME , "api/ai/generateAiReportRequest.json" , "api/ai/generateAiReportResponse.json" ),
95
+ RequestMock .build (String .format (CHECK_AI_REPORT_GENERATION_PATH , this .url , userId , aiReportId ), HttpGet .METHOD_NAME , "api/ai/checkAiReportGenerationStatusResponse.json" ),
96
+ RequestMock .build (String .format (DOWNLOAD_AI_REPORT_PATH , this .url , userId , aiReportId ), HttpGet .METHOD_NAME , "api/ai/downloadAiReportResponse.json" ),
97
+ RequestMock .build (String .format (FINE_TUNING_DATASET_DOWNLOAD_PATH , this .url , userId , aiPromptId , jobIdentifier ), HttpGet .METHOD_NAME , "api/ai/downloadFineTuningDataset.json" ),
86
98
RequestMock .build (String .format (GET_SETTINGS , this .url , userId ), HttpGet .METHOD_NAME , "api/ai/getAiSettingResponse.json" ),
87
99
RequestMock .build (String .format (GET_SETTINGS , this .url , userId ), HttpPatch .METHOD_NAME , "api/ai/editAiSettingRequest.json" , "api/ai/getAiSettingResponse.json" ),
88
100
RequestMock .build (String .format (FINE_TUNING_DATASET_DOWNLOAD_PATH , this .url , userId , aiPromptId , jobIdentifier ), HttpGet .METHOD_NAME , "api/ai/downloadFineTuningDataset.json" ),
@@ -95,7 +107,6 @@ public List<RequestMock> getMocks() {
95
107
);
96
108
}
97
109
98
-
99
110
@ Test
100
111
public void datasetGenerationStatusTest () {
101
112
Date dateCreated = getDateTime (year , month , date , hour , minutes , seconds );
@@ -199,6 +210,43 @@ public void downloadFineTuningDatasetTest() {
199
210
assertNotNull (responseObject .getData ().getUrl ());
200
211
}
201
212
213
+ @ Test
214
+ public void generateAiReportTest () {
215
+ final Date dateFrom = getDateTime (year , month , date , hour , minutes , seconds );
216
+ final Date dateTo = getDateTime (year , month , date , hour , minutes , seconds );
217
+
218
+ GenerateAiReportRequestSchema schema = new GenerateAiReportRequestSchema ();
219
+ schema .setDateFrom (dateFrom );
220
+ schema .setDateTo (dateTo );
221
+ schema .setFormat (AiReportFormat .JSON );
222
+ schema .setProjectIds (Collections .singletonList (0L ));
223
+ schema .setPromptIds (Collections .singletonList (0L ));
224
+ schema .setUserIds (Collections .singletonList (userId ));
225
+
226
+ GenerateAiReportRequest request = new GenerateAiReportRequest ();
227
+ request .setType ("tokens-usage-raw-data" );
228
+ request .setSchema (schema );
229
+
230
+ ResponseObject <AiReportGenerate > responseObject = this .getAiApi ().generateAiReport (userId , request );
231
+ assertNotNull (responseObject .getData ());
232
+ assertEquals (responseObject .getData ().getAttributes ().getReportType (), request .getType ());
233
+ }
234
+
235
+ @ Test
236
+ public void checkAiReportGenerationStatusTest () {
237
+ final Date dateCreated = getDateTime (year , month , date , hour , minutes , seconds );
238
+ ResponseObject <AiReportGenerate > responseObject = this .getAiApi ().checkAiReportGenerationStatus (userId , aiReportId );
239
+ assertNotNull (responseObject .getData ());
240
+ assertEquals (responseObject .getData ().getCreatedAt (), dateCreated );
241
+ }
242
+
243
+ @ Test
244
+ public void downloadAiReportTest () {
245
+ ResponseObject <DownloadLink > responseObject = this .getAiApi ().downloadAiReport (userId , aiReportId );
246
+ assertNotNull (responseObject .getData ());
247
+ assertNotNull (responseObject .getData ().getUrl ());
248
+ }
249
+
202
250
@ Test
203
251
public void getAiSettingTest () {
204
252
AiSetting aiSetting = this .getAiApi ().getAiSetting (userId ).getData ();
0 commit comments