Skip to content
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

Fix GetTasksForQueueAsync #534

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public async Task<IReadOnlyList<ClearMLTask>> GetTasksForQueueAsync(
var body = new JsonObject { ["queue"] = queueId };
JsonObject? result = await CallAsync("queues", "get_by_id", body, cancellationToken);
var tasks = (JsonArray?)result?["data"]?["queue"]?["entries"];
IEnumerable<string> taskIds = tasks?.Select(t => (string)t?["id"]!) ?? new List<string>();
IEnumerable<string> taskIds = tasks?.Select(t => (string)t?["task"]!) ?? new List<string>();
return await GetTasksByIdAsync(taskIds, cancellationToken);
}

Expand Down
52 changes: 33 additions & 19 deletions src/Serval/test/Serval.E2ETests/ServalApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,26 @@ public async Task NmtQueueMultiple()
const int NUM_ENGINES = 10;
const int NUM_WORKERS = 8;
string[] engineIds = new string[NUM_ENGINES];
string[] books = ["MAT.txt", "1JN.txt", "2JN.txt"];
TranslationParallelCorpusConfig train_corpus = await _helperClient.MakeParallelTextCorpus(
books,
"es",
"en",
false
);
TranslationParallelCorpusConfig pretranslate_corpus = await _helperClient.MakeParallelTextCorpus(
["3JN.txt"],
"es",
"en",
true
);
for (int i = 0; i < NUM_ENGINES; i++)
{
_helperClient.InitTranslationBuildConfig();
engineIds[i] = await _helperClient.CreateNewEngineAsync("Nmt", "es", "en", $"NMT1_{i}");
string engineId = engineIds[i];
string[] books = ["MAT.txt", "1JN.txt", "2JN.txt"];
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, books, "es", "en", false);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, ["3JN.txt"], "es", "en", true);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, train_corpus, false);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, pretranslate_corpus, true);
await _helperClient.StartBuildAsync(engineId);
//Ensure that tasks are enqueued roughly in order
await Task.Delay(1_000);
Expand Down Expand Up @@ -213,8 +225,20 @@ public async Task NmtLargeBatchAndDownload()
TranslationEngine engine = await _helperClient.TranslationEnginesClient.GetAsync(engineId);
Assert.That(engine.IsModelPersisted, Is.True);
string[] books = ["bible_LARGEFILE.txt"];
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, books, "es", "en", false);
string cId = await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, ["3JN.txt"], "es", "en", true);
TranslationParallelCorpusConfig train_corpus = await _helperClient.MakeParallelTextCorpus(
books,
"es",
"en",
false
);
TranslationParallelCorpusConfig pretranslate_corpus = await _helperClient.MakeParallelTextCorpus(
["3JN.txt"],
"es",
"en",
true
);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, train_corpus, false);
string cId = await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, pretranslate_corpus, true);
await _helperClient.BuildEngineAsync(engineId);
await Task.Delay(1000);
IList<Pretranslation> lTrans = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync(
Expand Down Expand Up @@ -259,13 +283,8 @@ public async Task CircuitousRouteGetWordGraphAsync()
Assert.That(ex.StatusCode, Is.EqualTo(409));

//Add corpus
string cId = await _helperClient.AddParallelTextCorpusToEngineAsync(
smtEngineId,
["2JN.txt", "3JN.txt"],
"es",
"en",
false
);
var corpus1 = await _helperClient.MakeParallelTextCorpus(["2JN.txt", "3JN.txt"], "es", "en", false);
string cId = await _helperClient.AddParallelTextCorpusToEngineAsync(smtEngineId, corpus1, false);

//Build the new engine
await _helperClient.BuildEngineAsync(smtEngineId);
Expand All @@ -274,13 +293,8 @@ public async Task CircuitousRouteGetWordGraphAsync()
await _helperClient.TranslationEnginesClient.DeleteParallelCorpusAsync(smtEngineId, cId);

// Add corpus
await _helperClient.AddParallelTextCorpusToEngineAsync(
smtEngineId,
["1JN.txt", "2JN.txt", "3JN.txt"],
"es",
"en",
false
);
var corpus2 = await _helperClient.MakeParallelTextCorpus(["1JN.txt", "2JN.txt", "3JN.txt"], "es", "en", false);
await _helperClient.AddParallelTextCorpusToEngineAsync(smtEngineId, corpus2, false);

//Build the new engine
await _helperClient.BuildEngineAsync(smtEngineId);
Expand Down
14 changes: 11 additions & 3 deletions src/Serval/test/Serval.E2ETests/ServalClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ bool pretranslate
return response.Id;
}

public async Task<string> AddParallelTextCorpusToEngineAsync(
string engineId,
public async Task<TranslationParallelCorpusConfig> MakeParallelTextCorpus(
string[] filesToAdd,
string sourceLanguage,
string targetLanguage,
Expand Down Expand Up @@ -290,12 +289,21 @@ bool pretranslate
TranslationParallelCorpusConfig parallelCorpusConfig =
new() { SourceCorpusIds = { sourceCorpus.Id }, TargetCorpusIds = { targetCorpus.Id } };

return parallelCorpusConfig;
}

public async Task<string> AddParallelTextCorpusToEngineAsync(
string engineId,
TranslationParallelCorpusConfig parallelCorpusConfig,
bool pretranslate
)
{
var parallelCorpus = await TranslationEnginesClient.AddParallelCorpusAsync(engineId, parallelCorpusConfig);

if (pretranslate)
{
TranslationBuildConfig.Pretranslate!.Add(
new PretranslateCorpusConfig { ParallelCorpusId = parallelCorpus.Id, TextIds = filesToAdd.ToList() }
new PretranslateCorpusConfig { ParallelCorpusId = parallelCorpus.Id }
);
}

Expand Down
Loading