Skip to content

Commit

Permalink
Basic config passing as string --ECL
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Sep 14, 2023
1 parent 1ed350f commit 16b278a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4317,6 +4317,9 @@ public partial class TranslationBuild
[Newtonsoft.Json.JsonProperty("dateFinished", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.DateTimeOffset? DateFinished { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? Options { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down Expand Up @@ -4358,6 +4361,9 @@ public partial class TranslationBuildConfig
[Newtonsoft.Json.JsonProperty("pretranslate", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IList<PretranslateCorpusConfig>? Pretranslate { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? Options { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down
3 changes: 2 additions & 1 deletion src/Serval.Grpc/Protos/serval/translation/v1/engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ message StartBuildRequest {
string engine_type = 1;
string engine_id = 2;
string build_id = 3;
repeated Corpus corpora = 4;
string options = 4;
repeated Corpus corpora = 5;
}

message CancelBuildRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
namespace Serval.Translation.Contracts;
using System.Text.Json.Nodes;

namespace Serval.Translation.Contracts;

public class TranslationBuildConfigDto
{
public IList<PretranslateCorpusConfigDto>? Pretranslate { get; set; }

public string? Options { get; set; }
}
1 change: 1 addition & 0 deletions src/Serval.Translation/Contracts/TranslationBuildDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public class TranslationBuildDto
/// </summary>
public JobState State { get; set; }
public DateTime? DateFinished { get; set; }
public string? Options { get; set; }
}
20 changes: 18 additions & 2 deletions src/Serval.Translation/Controllers/TranslationEnginesController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Serval.Translation.Controllers;
using System.Text.Json;

namespace Serval.Translation.Controllers;

[ApiVersion(1.0)]
[Route("api/v{version:apiVersion}/translation/engines")]
Expand Down Expand Up @@ -784,6 +786,10 @@ CancellationToken cancellationToken
{
return BadRequest(ioe.Message);
}
catch (ArgumentException ae)
{
return BadRequest(ae.Message);
}
if (!await _engineService.StartBuildAsync(build, cancellationToken))
return NotFound();

Expand Down Expand Up @@ -976,6 +982,15 @@ private static Build Map(Engine engine, TranslationBuildConfigDto source)
}
build.Pretranslate = pretranslateCorpora;
}
try
{
JsonSerializer.Deserialize<JsonObject>(source.Options ?? "{}");
}
catch (Exception e)
{
throw new ArgumentException($"Unable to parse field 'options' : {e.Message}");
}
build.Options = source.Options;
return build;
}

Expand Down Expand Up @@ -1013,7 +1028,8 @@ private TranslationBuildDto Map(Build source)
PercentCompleted = source.PercentCompleted,
Message = source.Message,
State = source.State,
DateFinished = source.DateFinished
DateFinished = source.DateFinished,
Options = source.Options
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Serval.Translation/Models/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class Build : IEntity
public string? Message { get; set; }
public JobState State { get; set; } = JobState.Pending;
public DateTime? DateFinished { get; set; }
public string? Options { get; set; }
}
1 change: 1 addition & 0 deletions src/Serval.Translation/Services/EngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public async Task<bool> StartBuildAsync(Build build, CancellationToken cancellat
EngineType = engine.Type,
EngineId = engine.Id,
BuildId = build.Id,
Options = build.Options,
Corpora =
{
engine.Corpora.Select(c =>
Expand Down
1 change: 1 addition & 0 deletions src/Serval.Translation/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
global using System.Diagnostics.CodeAnalysis;
global using System.Linq.Expressions;
global using System.Text.Json.Nodes;
global using Asp.Versioning;
global using Grpc.Core;
global using Grpc.Net.ClientFactory;
Expand Down

0 comments on commit 16b278a

Please sign in to comment.