-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move queue endpoint Resolve reviewer comments Updated from reviewer comments IsSupportedNatively InternalCode UpdatedNames Optional name and InternalCode Update endpoint Update controllers to kebab case - PascalCase internally Update documentation Add pascal case tests updates from reviewer comments respond to reviewer comments. Strip out name from GRPC call
- Loading branch information
1 parent
d78c8ed
commit 19016e8
Showing
17 changed files
with
727 additions
and
241 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,8 @@ | ||
namespace Serval.Translation.Contracts; | ||
|
||
public class LanguageInfoDto | ||
{ | ||
public string EngineType { get; set; } = default!; | ||
public bool IsNative { get; set; } = default!; | ||
public string? InternalCode { get; set; } = default!; | ||
} |
104 changes: 104 additions & 0 deletions
104
src/Serval.Translation/Controllers/TranslationEngineTypesController.cs
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,104 @@ | ||
namespace Serval.Translation.Controllers; | ||
|
||
[ApiVersion(1.0)] | ||
[Route("api/v{version:apiVersion}/translation/engine-types")] | ||
[OpenApiTag("Translation Engines")] | ||
public class TranslationController(IAuthorizationService authService, IEngineService engineService) | ||
: ServalControllerBase(authService) | ||
{ | ||
private readonly IEngineService _engineService = engineService; | ||
|
||
/// <summary> | ||
/// Get queue information for a given engine type | ||
/// </summary> | ||
/// <param name="engineType">A valid engine type: smt-transfer, nmt, or echo</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <response code="200">Queue information for the specified engine type</response> | ||
/// <response code="401">The client is not authenticated</response> | ||
/// <response code="403">The authenticated client cannot perform the operation</response> | ||
/// <response code="503">A necessary service is currently unavailable. Check `/health` for more details. </response> | ||
[Authorize(Scopes.ReadTranslationEngines)] | ||
[HttpGet("{engineType}/queues")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status503ServiceUnavailable)] | ||
public async Task<ActionResult<QueueDto>> GetQueueAsync( | ||
[NotNull] string engineType, | ||
CancellationToken cancellationToken | ||
) | ||
{ | ||
try | ||
{ | ||
return Map( | ||
await _engineService.GetQueueAsync(engineType.ToPascalCase(), cancellationToken: cancellationToken) | ||
); | ||
} | ||
catch (InvalidOperationException ioe) | ||
{ | ||
return BadRequest(ioe.Message); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get infromation regarding a language for a given engine type | ||
/// </summary> | ||
/// <remarks> | ||
/// This endpoint is to support Nmt models. It specifies the ISO 639-3 code that the language maps to | ||
/// and whether it is supported in the NLLB 200 model without training. This is useful for determining if a | ||
/// language is an appropriate candidate for a source language or if two languages can be translated between | ||
/// **Base Models available** | ||
/// * **NLLB-200**: This is the only current base transaltion model available. | ||
/// * The languages included in the base model are [here](https://github.com/facebookresearch/flores/blob/main/nllb_seed/README.md) | ||
/// without training. | ||
/// Response format: | ||
/// * **EngineType**: See above | ||
/// * **IsNative**: Whether the base translation model supports this language without fine-tuning. | ||
/// * **InternalCode**: The translation models language code that the language maps to according to [these rules](https://github.com/sillsdev/serval/wiki/FLORES%E2%80%90200-Language-Code-Resolution-for-NMT-Engine). | ||
/// </remarks> | ||
/// <param name="engineType">A valid engine type: nmt or echo</param> | ||
/// <param name="language">The language to retrieve information on.</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <response code="200">Language information for the specified engine type</response> | ||
/// <response code="401">The client is not authenticated</response> | ||
/// <response code="403">The authenticated client cannot perform the operation</response> | ||
/// <response code="405">The method is not supported</response> | ||
[Authorize(Scopes.ReadTranslationEngines)] | ||
[HttpGet("{engineType}/languages/{language}")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status405MethodNotAllowed)] | ||
public async Task<ActionResult<LanguageInfoDto>> GetLanguageInfoAsync( | ||
[NotNull] string engineType, | ||
[NotNull] string language, | ||
CancellationToken cancellationToken | ||
) | ||
{ | ||
try | ||
{ | ||
return Map( | ||
await _engineService.GetLanguageInfoAsync( | ||
engineType: engineType.ToPascalCase(), | ||
language: language, | ||
cancellationToken: cancellationToken | ||
) | ||
); | ||
} | ||
catch (InvalidOperationException ioe) | ||
{ | ||
return BadRequest(ioe.Message); | ||
} | ||
} | ||
|
||
private static QueueDto Map(Queue source) => | ||
new() { Size = source.Size, EngineType = source.EngineType.ToKebabCase() }; | ||
|
||
private static LanguageInfoDto Map(LanguageInfo source) => | ||
new() | ||
{ | ||
EngineType = source.EngineType.ToKebabCase(), | ||
IsNative = source.IsNative, | ||
InternalCode = source.InternalCode | ||
}; | ||
} |
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
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 @@ | ||
namespace Serval.Translation.Models; | ||
|
||
public class LanguageInfo | ||
{ | ||
public string EngineType { get; set; } = default!; | ||
public bool IsNative { get; set; } = default!; | ||
public string? InternalCode { get; set; } = default!; | ||
} |
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
Oops, something went wrong.