-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2101227
commit b6a57c8
Showing
24 changed files
with
850 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package com.crowdin.client.ai; | ||
|
||
import com.crowdin.client.ai.model.FineTuningDatasetDownload; | ||
import com.crowdin.client.ai.model.FineTuningDatasetDownloadResponse; | ||
import com.crowdin.client.ai.model.FineTuningDatasetRequest; | ||
import com.crowdin.client.ai.model.FineTuningDatasetResponse; | ||
import com.crowdin.client.ai.model.FineTuningDatasetResponse.FineTuningDatasetData; | ||
import com.crowdin.client.ai.model.FineTuningEvent; | ||
import com.crowdin.client.ai.model.FineTuningEventResponseList; | ||
import com.crowdin.client.ai.model.FineTuningJob; | ||
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.core.CrowdinApi; | ||
import com.crowdin.client.core.http.HttpRequestConfig; | ||
import com.crowdin.client.core.model.ClientConfig; | ||
import com.crowdin.client.core.model.Credentials; | ||
import com.crowdin.client.core.model.ResponseList; | ||
import com.crowdin.client.core.model.ResponseObject; | ||
|
||
public class AIApi extends CrowdinApi { | ||
|
||
public AIApi(Credentials credentials) { | ||
super(credentials); | ||
} | ||
|
||
public AIApi(Credentials credentials, ClientConfig clientConfig) { | ||
super(credentials, clientConfig); | ||
} | ||
|
||
/** | ||
* @param userId user identifier | ||
* @param aiPromptId AI prompt identifier | ||
* @param jobIdentifier AI prompt fine-tuning dataset generation identifier, consists of 36 characters | ||
* @return dataset generation status | ||
* @see <ul> | ||
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.prompts.fine-tuning.datasets.get" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.datasets.get" target="_blank"><b>Enterprise API Documentation</b></li> | ||
* </ul> | ||
* */ | ||
|
||
public ResponseObject<FineTuningDatasetData> getFineTuningDatasetGenerationStatus( | ||
final long userId, final long aiPromptId, final String jobIdentifier) { | ||
String url = String.format("%s/users/%d/ai/prompts/%d/fine-tuning/datasets/%s", this.url, userId, aiPromptId, jobIdentifier); | ||
FineTuningDatasetResponse response = this.httpClient.get(url, new HttpRequestConfig(), FineTuningDatasetResponse.class); | ||
return ResponseObject.of(response.getData()); | ||
} | ||
|
||
/** | ||
* @param userId user identifier | ||
* @param aiPromptId AI prompt identifier | ||
* @param request request body | ||
* @return fine-tuning dataset | ||
* @see <ul> | ||
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.datasets.post" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.datasets.post" target="_blank"><b>Enterprise API Documentation</b></li> | ||
* </ul> | ||
* */ | ||
public ResponseObject<FineTuningDatasetData> generateFineTuningDataset( | ||
final long userId, final long aiPromptId, final FineTuningDatasetRequest request) { | ||
String url = String.format("%s/users/%d/ai/prompts/%d/fine-tuning/datasets", this.url, userId, aiPromptId); | ||
FineTuningDatasetResponse response = this.httpClient.post(url, request, new HttpRequestConfig(), FineTuningDatasetResponse.class); | ||
return ResponseObject.of(response.getData()); | ||
} | ||
|
||
/** | ||
* @param userId user identifier | ||
* @param aiPromptId AI prompt identifier | ||
* @param jobIdentifier AI prompt fine-tuning dataset generation identifier, consists of 36 characters | ||
* @return fine-tuning event list | ||
* @see <ul> | ||
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.events.getMany" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.events.getMany" target="_blank"><b>Enterprise API Documentation</b></li> | ||
* </ul> | ||
* */ | ||
|
||
public ResponseList<FineTuningEvent> getFineTuningEventList( | ||
final long userId, final long aiPromptId, final String jobIdentifier) { | ||
String url = String.format("%s/users/%d/ai/prompts/%d/fine-tuning/jobs/%s/events", this.url, userId, aiPromptId, jobIdentifier); | ||
FineTuningEventResponseList responseList = this.httpClient.get(url, new HttpRequestConfig(), FineTuningEventResponseList.class); | ||
return FineTuningEventResponseList.to(responseList); | ||
} | ||
|
||
/** | ||
* @param userId user identifier | ||
* @return fine-tuning job list | ||
* @see <ul> | ||
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.getMany" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.getMany" target="_blank"><b>Enterprise API Documentation</b></li> | ||
* </ul> | ||
* */ | ||
|
||
public ResponseList<FineTuningJob> getFineTuningJobList(final long userId) { | ||
String url = String.format("%s/users/%d/ai/prompts/fine-tuning/jobs", this.url, userId); | ||
FineTuningJobResponseList responseList = this.httpClient.get(url, new HttpRequestConfig(), FineTuningJobResponseList.class); | ||
return FineTuningJobResponseList.to(responseList); | ||
} | ||
/** | ||
* @param userId user identifier | ||
* @param aiPromptId AI prompt identifier | ||
* @param request request body | ||
* @return AI Prompt Fine-Tuning Dataset Job | ||
* @see <ul> | ||
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.post" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.post" target="_blank"><b>Enterprise API Documentation</b></li> | ||
* </ul> | ||
* */ | ||
|
||
public ResponseObject<FineTuningJob> createFineTuningJob(final long userId, final long aiPromptId, final FineTuningJobRequest request) { | ||
String url = String.format("%s/users/%d/ai/prompts/%d/fine-tuning/jobs", this.url, userId, aiPromptId); | ||
FineTuningJobResponseObject responseObject = this.httpClient.post(url, request, new HttpRequestConfig(), FineTuningJobResponseObject.class); | ||
return ResponseObject.of(responseObject.getData()); | ||
} | ||
|
||
/** | ||
* @param userId user identifier | ||
* @param aiPromptId AI prompt identifier | ||
* @param jobIdentifier AI prompt fine-tuning dataset generation identifier, consists of 36 characters | ||
* @return AI Prompt Fine-Tuning Dataset Job Status | ||
* @see <ul> | ||
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.get" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.get" target="_blank"><b>Enterprise API Documentation</b></li> | ||
* </ul> | ||
* */ | ||
|
||
public ResponseObject<FineTuningJob> getFineTuningJobStatus(final long userId, final long aiPromptId, final String jobIdentifier) { | ||
String url = String.format("%s/users/%d/ai/prompts/%d/fine-tuning/jobs/%s", this.url, userId, aiPromptId, jobIdentifier); | ||
FineTuningJobResponseObject responseObject = this.httpClient.get(url, new HttpRequestConfig(), FineTuningJobResponseObject.class); | ||
return ResponseObject.of(responseObject.getData()); | ||
} | ||
|
||
/** | ||
* @param userId user identifier | ||
* @param aiPromptId AI prompt identifier | ||
* @param jobIdentifier AI prompt fine-tuning dataset generation identifier, consists of 36 characters | ||
* @return AI Prompt Fine-Tuning Dataset Download URL | ||
* @see <ul> | ||
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.get" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.prompts.fine-tuning.jobs.get" target="_blank"><b>Enterprise API Documentation</b></li> | ||
* </ul> | ||
* */ | ||
|
||
public ResponseObject<FineTuningDatasetDownload> downloadFineTuningDatasetDownload(final long userId, final long aiPromptId, final String jobIdentifier) { | ||
String url = String.format("%s/users/%d/ai/prompts/%d/fine-tuning/datasets/%s/download", this.url, userId, aiPromptId, jobIdentifier); | ||
FineTuningDatasetDownloadResponse response = this.httpClient.get(url, new HttpRequestConfig(), FineTuningDatasetDownloadResponse.class); | ||
return ResponseObject.of(response.getData()); | ||
} | ||
|
||
} | ||
|
10 changes: 10 additions & 0 deletions
10
src/main/java/com/crowdin/client/ai/model/FineTuningDatasetDownload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.crowdin.client.ai.model; | ||
|
||
import java.util.Date; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FineTuningDatasetDownload { | ||
private String url; | ||
private Date expireIn; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/crowdin/client/ai/model/FineTuningDatasetDownloadResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.crowdin.client.ai.model; | ||
|
||
import java.util.Date; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FineTuningDatasetDownloadResponse { | ||
private FineTuningDatasetDownload data; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/crowdin/client/ai/model/FineTuningDatasetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.crowdin.client.ai.model; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FineTuningDatasetRequest { | ||
private List<Long> projectIds; | ||
private List<Long> tmIds; | ||
private String purpose; | ||
private Date dateFrom; | ||
private Date dateTo; | ||
private Long maxFileSize; | ||
private Long minExamplesCount; | ||
private Long maxExamplesCount; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/crowdin/client/ai/model/FineTuningDatasetResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.crowdin.client.ai.model; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FineTuningDatasetResponse { | ||
private FineTuningDatasetData data; | ||
|
||
@Data | ||
public static class FineTuningDatasetData { | ||
private String identifier; | ||
private String status; | ||
private Long progress; | ||
private DatasetAttributes attributes; | ||
private Date createdAt; | ||
private Date updatedAt; | ||
private Date startedAt; | ||
} | ||
|
||
@Data | ||
public static class DatasetAttributes { | ||
private List<Long> projectIds; | ||
private List<Long> tmIds; | ||
private String purpose; | ||
private Date dateFrom; | ||
private Date dateTo; | ||
private Long maxFileSize; | ||
private Long minExamplesCount; | ||
private Long maxExamplesCount; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/crowdin/client/ai/model/FineTuningEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.crowdin.client.ai.model; | ||
|
||
import java.util.Date; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FineTuningEvent { | ||
private String id; | ||
private String type; | ||
private String message; | ||
private FineTuningEventData data; | ||
private Date createdAt; | ||
|
||
@Data | ||
public static class FineTuningEventData { | ||
private Long step; | ||
private Long totalSteps; | ||
private Double trainingLoss; | ||
private Double validationLoss; | ||
private Double fullValidationLoss; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/crowdin/client/ai/model/FineTuningEventResponseList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.crowdin.client.ai.model; | ||
|
||
import com.crowdin.client.core.model.Pagination; | ||
import com.crowdin.client.core.model.ResponseList; | ||
import com.crowdin.client.core.model.ResponseObject; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FineTuningEventResponseList { | ||
private List<FineTuningEventResponseObject> data; | ||
private Pagination pagination; | ||
|
||
public static ResponseList<FineTuningEvent> to(FineTuningEventResponseList eventResponseList) { | ||
return ResponseList.of( | ||
eventResponseList.getData() | ||
.stream() | ||
.map(FineTuningEventResponseObject::getData) | ||
.map(ResponseObject::of).collect(Collectors.toList()), | ||
eventResponseList.getPagination() | ||
); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/crowdin/client/ai/model/FineTuningEventResponseObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 FineTuningEventResponseObject { | ||
private FineTuningEvent data; | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/crowdin/client/ai/model/FineTuningJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.crowdin.client.ai.model; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FineTuningJob { | ||
private String identifier; | ||
private String status; | ||
private Long progress; | ||
private JobAttribute attributes; | ||
private Date createdAt; | ||
private Date updatedAt; | ||
private Date startedAt; | ||
private Date finishedAt; | ||
|
||
@Data | ||
public static class JobAttribute { | ||
private Boolean dryRun; | ||
private Long aiPromptId; | ||
private Hyperparameters hyperparameters; | ||
private Options trainignOptions; | ||
private Options validationOptions; | ||
private String baseModel; | ||
private String fineTunedModel; | ||
private Long trainedTokensCount; | ||
private String trainingDatasetUrl; | ||
private String validationDatasetUrl; | ||
private Metadata metadata; | ||
} | ||
|
||
@Data | ||
public static class Hyperparameters { | ||
private Long batchSize; | ||
private Long learningRateMultiplier; | ||
private Long nEpochs; | ||
} | ||
|
||
@Data | ||
public static class Options { | ||
private List<Long> projectIds; | ||
private List<Long> tmIds; | ||
private Date dateFrom; | ||
private Date dateTo; | ||
private Long maxFileSize; | ||
private Long minExamplesCount; | ||
private Long maxExamplesCount; | ||
} | ||
|
||
@Data | ||
public static class Metadata { | ||
private Double cost; | ||
private String costCurrency; | ||
} | ||
} |
Oops, something went wrong.