-
Notifications
You must be signed in to change notification settings - Fork 33
feat(ai): add file translation methods support #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -470,6 +470,79 @@ public async Task<AiSettings> EditAiSettings(long? userId, IEnumerable<AiSetting | |||||||
| return _jsonParser.ParseResponseObject<AiSettings>(result.JsonObject); | ||||||||
| } | ||||||||
|
|
||||||||
| #endregion | ||||||||
|
|
||||||||
| #region File Translations | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// AI File Translations. Documentation: | ||||||||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.post">Crowdin File Based API</a> | ||||||||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.post">Crowdin String Based API</a> | ||||||||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.post">Crowdin Enterprise API</a> | ||||||||
| /// </summary> | ||||||||
| [PublicAPI] | ||||||||
| public async Task<AiFileTranslationsStatus> AiFileTranslations(long? userId, AiFileTranslationsRequest request) | ||||||||
| { | ||||||||
| string url = AddUserIdIfAvailable(userId, "/ai/file-translations"); | ||||||||
| CrowdinApiResult result = await _apiClient.SendPostRequest(url, request); | ||||||||
| return _jsonParser.ParseResponseObject<AiFileTranslationsStatus>(result.JsonObject); | ||||||||
| } | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Get File Translations Status. Documentation: | ||||||||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.get">Crowdin File Based API</a> | ||||||||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.get">Crowdin String Based API</a> | ||||||||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.get">Crowdin Enterprise API</a> | ||||||||
| /// </summary> | ||||||||
| [PublicAPI] | ||||||||
| public async Task<AiFileTranslationsStatus> GetFileTranslationsStatus(long? userId, string jobIdentifier) | ||||||||
| { | ||||||||
| string url = AddUserIdIfAvailable(userId, $"/ai/file-translations/{jobIdentifier}"); | ||||||||
| CrowdinApiResult result = await _apiClient.SendGetRequest(url); | ||||||||
| return _jsonParser.ParseResponseObject<AiFileTranslationsStatus>(result.JsonObject); | ||||||||
| } | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Cancel File Translations. Documentation: | ||||||||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.delete">Crowdin File Based API</a> | ||||||||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.delete">Crowdin String Based API</a> | ||||||||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.delete">Crowdin Enterprise API</a> | ||||||||
| /// </summary> | ||||||||
| [PublicAPI] | ||||||||
| public async Task CancelFileTranslations(long? userId, string jobIdentifier) | ||||||||
| { | ||||||||
| string url = AddUserIdIfAvailable(userId, $"/ai/file-translations/{jobIdentifier}"); | ||||||||
| HttpStatusCode statusCode = await _apiClient.SendDeleteRequest(url); | ||||||||
| Utils.ThrowIfStatusNot204(statusCode, $"File Translation {jobIdentifier} removal failed"); | ||||||||
| } | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Download Translated File. Documentation: | ||||||||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.download">Crowdin File Based API</a> | ||||||||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.download">Crowdin String Based API</a> | ||||||||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.download">Crowdin Enterprise API</a> | ||||||||
| /// </summary> | ||||||||
|
||||||||
| /// </summary> | |
| /// </summary> | |
| [PublicAPI] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
|
|
||
| using System.Collections.Generic; | ||
| using Crowdin.Api.SourceFiles; | ||
| using JetBrains.Annotations; | ||
| using Newtonsoft.Json; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Crowdin.Api.AI | ||
| { | ||
| [PublicAPI] | ||
| public class AiFileTranslationsRequest | ||
| { | ||
| [JsonProperty("storageId")] | ||
| public long StorageId { get; set; } | ||
|
|
||
| [JsonProperty("sourceLanguageId")] | ||
| public string? SourceLanguageId { get; set; } | ||
|
|
||
| [JsonProperty("targetLanguageId")] | ||
| public string TargetLanguageId { get; set; } = null!; | ||
|
|
||
| [JsonProperty("type")] | ||
| public ProjectFileType? Type { get; set; } | ||
|
|
||
| [JsonProperty("parserVersion")] | ||
| public int? ParserVersion { get; set; } | ||
|
|
||
| [JsonProperty("tmIds")] | ||
| public ICollection<long>? TmIds { get; set; } | ||
|
|
||
| [JsonProperty("glossaryIds")] | ||
| public ICollection<long>? GlossaryIds { get; set; } | ||
|
|
||
| [JsonProperty("aiPromptId")] | ||
| public long? AiPromptId { get; set; } | ||
|
|
||
| [JsonProperty("aiProviderId")] | ||
| public long? AiProviderId { get; set; } | ||
|
|
||
| [JsonProperty("aiModelId")] | ||
| public string? AiModelId { get; set; } | ||
|
|
||
| [JsonProperty("instructions")] | ||
| public ICollection<string>? Instructions { get; set; } | ||
|
|
||
| [JsonProperty("attachmentIds")] | ||
| public ICollection<long>? AttachmentIds { get; set; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
|
|
||
| using System.ComponentModel; | ||
| using JetBrains.Annotations; | ||
|
|
||
| namespace Crowdin.Api.AI | ||
| { | ||
| [PublicAPI] | ||
| public enum AiFileTranslationsStage | ||
| { | ||
| [Description("start")] | ||
| Start, | ||
|
|
||
| [Description("import")] | ||
| Import, | ||
|
|
||
| [Description("translate")] | ||
| Translate, | ||
|
|
||
| [Description("export")] | ||
| Export, | ||
|
|
||
| [Description("done")] | ||
| Done | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
|
|
||
| using System; | ||
| using Crowdin.Api.SourceFiles; | ||
| using JetBrains.Annotations; | ||
| using Newtonsoft.Json; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Crowdin.Api.AI | ||
| { | ||
| [PublicAPI] | ||
| public class AiFileTranslationsStatus | ||
| { | ||
| [JsonProperty("identifier")] | ||
| public string Identifier { get; set; } = null!; | ||
|
|
||
| [JsonProperty("status")] | ||
| public OperationStatus Status { get; set; } | ||
|
|
||
| [JsonProperty("progress")] | ||
| public int Progress { get; set; } | ||
|
|
||
| [JsonProperty("attributes")] | ||
| public AttributesObject Attributes { get; set; } = null!; | ||
|
|
||
| [PublicAPI] | ||
| public class AttributesObject | ||
| { | ||
| [JsonProperty("stage")] | ||
| public AiFileTranslationsStage Stage { get; set; } | ||
|
|
||
| [JsonProperty("error")] | ||
| public ErrorObject? Error { get; set; } | ||
|
|
||
| [JsonProperty("downloadName")] | ||
| public string? DownloadName { get; set; } | ||
|
|
||
| [JsonProperty("sourceLanguageId")] | ||
| public string? SourceLanguageId { get; set; } | ||
|
|
||
| [JsonProperty("targetLanguageId")] | ||
| public string? TargetLanguageId { get; set; } | ||
|
|
||
| [JsonProperty("originalFileName")] | ||
| public string? OriginalFileName { get; set; } | ||
|
|
||
| [JsonProperty("detectedType")] | ||
| public ProjectFileType? DetectedType { get; set; } | ||
|
|
||
| [JsonProperty("parserVersion")] | ||
| public int? ParserVersion { get; set; } | ||
|
|
||
| [PublicAPI] | ||
| public class ErrorObject | ||
| { | ||
| [JsonProperty("stage")] | ||
| public AiFileTranslationsStage Stage { get; set; } | ||
|
|
||
| [JsonProperty("message")] | ||
| public string Message { get; set; } = null!; | ||
| } | ||
| } | ||
|
|
||
| [JsonProperty("createdAt")] | ||
| public DateTimeOffset CreatedAt { get; set; } | ||
|
|
||
| [JsonProperty("updatedAt")] | ||
| public DateTimeOffset? UpdatedAt { get; set; } | ||
|
|
||
| [JsonProperty("startedAt")] | ||
| public DateTimeOffset? StartedAt { get; set; } | ||
|
|
||
| [JsonProperty("finishedAt")] | ||
| public DateTimeOffset? FinishedAt { get; set; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,50 @@ Task<AiPromptResource> EditAiPrompt( | |
|
|
||
| Task<AiSettings> EditAiSettings(long? userId, IEnumerable<AiSettingsPatch> patches); | ||
|
|
||
| #endregion | ||
|
|
||
| #region File Translations | ||
|
|
||
| /// <summary> | ||
| /// AI File Translations. Documentation: | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.post">Crowdin File Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.post">Crowdin String Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.post">Crowdin Enterprise API</a> | ||
| /// </summary> | ||
| Task<AiFileTranslationsStatus> AiFileTranslations(long? userId, AiFileTranslationsRequest request); | ||
|
|
||
|
Comment on lines
+113
to
+120
|
||
| /// <summary> | ||
| /// Get File Translations Status. Documentation: | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.get">Crowdin File Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.get">Crowdin String Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.get">Crowdin Enterprise API</a> | ||
| /// </summary> | ||
| Task<AiFileTranslationsStatus> GetFileTranslationsStatus(long? userId, string jobIdentifier); | ||
|
|
||
| /// <summary> | ||
| /// Cancel File Translations. Documentation: | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.delete">Crowdin File Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.delete">Crowdin String Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.delete">Crowdin Enterprise API</a> | ||
| /// </summary> | ||
| Task CancelFileTranslations(long? userId, string jobIdentifier); | ||
|
|
||
| /// <summary> | ||
| /// Download Translated File. Documentation: | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.download">Crowdin File Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.download">Crowdin String Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.download">Crowdin Enterprise API</a> | ||
| /// </summary> | ||
| Task<DownloadLink> DownloadTranslatedFile(long? userId, string jobIdentifier); | ||
|
|
||
| /// <summary> | ||
| /// Download Translated File Strings. Documentation: | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.download-strings">Crowdin File Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/AI/operation/api.users.ai.file-translations.download-strings">Crowdin String Based API</a> | ||
| /// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.download-strings">Crowdin Enterprise API</a> | ||
| /// </summary> | ||
| Task<DownloadLink> DownloadTranslatedFileStrings(long? userId, string jobIdentifier); | ||
|
|
||
| #endregion | ||
|
|
||
| Task<AiProxyChatCompletion> CreateAiProxyChatCompletion( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||||
| using Xunit; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| namespace Crowdin.Api.UnitTesting | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| public static class CommonResponsesAssertUtils | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| public static void Assert_DownloadLink(DownloadLink? expectedDownloadLink) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| ArgumentNullException.ThrowIfNull(expectedDownloadLink); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Assert.Equal("https://test.com", expectedDownloadLink.Url); | ||||||||||||||||||||||||||
| Assert.Equal(DateTimeOffset.Parse("2019-09-20T10:31:21+00:00"), expectedDownloadLink.ExpireIn); | ||||||||||||||||||||||||||
|
Comment on lines
+9
to
+14
|
||||||||||||||||||||||||||
| public static void Assert_DownloadLink(DownloadLink? expectedDownloadLink) | |
| { | |
| ArgumentNullException.ThrowIfNull(expectedDownloadLink); | |
| Assert.Equal("https://test.com", expectedDownloadLink.Url); | |
| Assert.Equal(DateTimeOffset.Parse("2019-09-20T10:31:21+00:00"), expectedDownloadLink.ExpireIn); | |
| public static void Assert_DownloadLink(DownloadLink? downloadLink) | |
| { | |
| ArgumentNullException.ThrowIfNull(downloadLink); | |
| Assert.Equal("https://test.com", downloadLink.Url); | |
| Assert.Equal(DateTimeOffset.Parse("2019-09-20T10:31:21+00:00"), downloadLink.ExpireIn); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation method name
AiFileTranslations(...)is noun-like and inconsistent with the executor's other verb-based method names. If you rename the interface method for consistency/clarity, update this implementation accordingly to keep the public API self-explanatory.