Skip to content

Commit

Permalink
feat: add AI report methods
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfmanfp committed Oct 30, 2024
1 parent a333c8c commit 0b0c97e
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 32 deletions.
52 changes: 52 additions & 0 deletions src/main/java/com/crowdin/client/ai/AIApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.crowdin.client.ai.model.AiProviderResponseList;
import com.crowdin.client.ai.model.AiProviderRequest;
import com.crowdin.client.ai.model.AiProviderResponseObject;
import com.crowdin.client.ai.model.AiReportGenerate;
import com.crowdin.client.ai.model.AiReportGenerateResponse;
import com.crowdin.client.ai.model.AiSettingResponse;
import com.crowdin.client.ai.model.AiSetting;
import com.crowdin.client.ai.model.FineTuningDatasetDownload;
Expand All @@ -19,10 +21,15 @@
import com.crowdin.client.ai.model.FineTuningJobRequest;
import com.crowdin.client.ai.model.FineTuningJobResponseList;
import com.crowdin.client.ai.model.FineTuningJobResponseObject;
import com.crowdin.client.ai.model.GenerateAiReportRequest;
import com.crowdin.client.core.CrowdinApi;
import com.crowdin.client.core.http.HttpRequestConfig;
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
import com.crowdin.client.core.http.exceptions.HttpException;
import com.crowdin.client.core.model.ClientConfig;
import com.crowdin.client.core.model.Credentials;
import com.crowdin.client.core.model.DownloadLink;
import com.crowdin.client.core.model.DownloadLinkResponseObject;
import com.crowdin.client.core.model.PatchRequest;
import com.crowdin.client.core.model.ResponseList;
import com.crowdin.client.core.model.ResponseObject;
Expand Down Expand Up @@ -161,6 +168,51 @@ public ResponseObject<FineTuningDatasetDownload> downloadFineTuningDataset(final
return ResponseObject.of(response.getData());
}

/**
* @param userId user identifier
* @param request request object
* @return AI report generation status
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.users.ai.reports.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.reports.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<AiReportGenerate> generateAiReport(final Long userId, final GenerateAiReportRequest request) throws HttpException, HttpBadRequestException {
String url = getAIPath(userId, "ai/reports");
AiReportGenerateResponse response = this.httpClient.post(url, request, new HttpRequestConfig(), AiReportGenerateResponse.class);
return ResponseObject.of(response.getData());
}

/**
* @param userId user identifier
* @param aiReportId AI report identifier, consists of 36 characters
* @return AI report generation status
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.users.ai.reports.get" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.reports.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<AiReportGenerate> checkAiReportGenerationStatus(final Long userId, final String aiReportId) throws HttpException, HttpBadRequestException {
String url = getAIPath(userId, String.format("ai/reports/%s", aiReportId));
AiReportGenerateResponse response = this.httpClient.get(url, new HttpRequestConfig(), AiReportGenerateResponse.class);
return ResponseObject.of(response.getData());
}

/**
* @param userId user identifier
* @param reportId AI report identifier, consists of 36 characters
* @return AI report download URL
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.users.ai.reports.download.download" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.reports.download.download" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<DownloadLink> downloadAiReport(final Long userId, final String reportId) throws HttpException, HttpBadRequestException {
String url = getAIPath(userId, String.format("ai/reports/%s/download", reportId));
DownloadLinkResponseObject response = this.httpClient.get(url, new HttpRequestConfig(), DownloadLinkResponseObject.class);
return ResponseObject.of(response.getData());
}

/**
* @param userId user identifier
* @return AI settings
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/crowdin/client/ai/model/AiReportAttributes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.crowdin.client.ai.model;

import lombok.Data;

@Data
public class AiReportAttributes {
private AiReportFormat format;
private String reportType;
private Object schema;
}
16 changes: 16 additions & 0 deletions src/main/java/com/crowdin/client/ai/model/AiReportFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.crowdin.client.ai.model;

import com.crowdin.client.core.model.EnumConverter;

public enum AiReportFormat implements EnumConverter<AiReportFormat> {
JSON, CSV;

public static AiReportFormat from(String value) {
return AiReportFormat.valueOf(value.toUpperCase());
}

@Override
public Object to(AiReportFormat v) {
return v.name().toLowerCase();
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/crowdin/client/ai/model/AiReportGenerate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.crowdin.client.ai.model;

import lombok.Data;

import java.util.Date;

@Data
public class AiReportGenerate {
private String identifier;
private String status;
private int progress;
private AiReportAttributes attributes;
private Date createdAt;
private Date updatedAt;
private Date startedAt;
private Date finishedAt;
private String eta;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.crowdin.client.ai.model;

import lombok.Data;

@Data
public class AiReportGenerateResponse {
private AiReportGenerate data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.crowdin.client.ai.model;

import lombok.Data;

@Data
public class GenerateAiReportRequest {
private String type;
private GenerateAiReportRequestSchema schema;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.crowdin.client.ai.model;

import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class GenerateAiReportRequestSchema {
private Date dateFrom;
private Date dateTo;
private AiReportFormat format;
private List<Long> projectIds;
private List<Long> promptIds;
private List<Long> userIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.util.StdDateFormat;
import lombok.SneakyThrows;

import java.text.SimpleDateFormat;

public class JacksonJsonTransformer implements JsonTransformer {

private final ObjectMapper objectMapper;
Expand Down Expand Up @@ -48,7 +47,7 @@ public JacksonJsonTransformer() {
.addDeserializer(StringsExporterSettingsResource.class, new StringsExporterSettingsDeserializer(cleanObjectMapper));
this.objectMapper = cleanObjectMapper.copy()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"))
.setDateFormat(new StdDateFormat())
.registerModule(module)
.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
Expand Down
Loading

0 comments on commit 0b0c97e

Please sign in to comment.