Skip to content

Commit

Permalink
fix: proper lfs model downloading for bergamot
Browse files Browse the repository at this point in the history
  • Loading branch information
Fevol committed Jul 2, 2024
1 parent 9e33e17 commit 6f937dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from "./types";

export const BERGAMOT_REPOSITORY = "https://raw.githubusercontent.com/mozilla/firefox-translations-models/main";
export const BERGAMOT_LFS_REPOSITORY = "https://github.com/mozilla/firefox-translations-models/raw/main";
export const BERGAMOT_LFS_REPOSITORY = "https://github.com/mozilla/firefox-translations-models.git/info/lfs/objects/batch";
/**
* @remark This was changed from archived firefox-translations repository on account of the binary not being up-to-date anymore.
* I tried determining whether it could be found in the firefox source code, but it doesn't seem to be distributed there either.
Expand Down
27 changes: 26 additions & 1 deletion src/ui/pages/settings-tabs/TranslatorSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,34 @@
const path = `${plugin.app.vault.configDir}/plugins/translate/models/bergamot/${model.locale}/${modelfile.name}`;
const stats = await plugin.app.vault.adapter.stat(path);
if (stats && stats.size === modelfile.size) continue;
const file = await requestUrl({
let file = await requestUrl({
url: bergamotFileUrl(model, modelfile),
});
if (file.text) {
const lfs_data = {
operation: "download",
transfer: ["basic"],
objects: [
{
oid: file.text.match(/oid sha256:(.*)/)[1],
size: parseInt(file.text.match(/size (.*)/)[1]),
},
],
};
const lfs_location = await requestUrl({
url: BERGAMOT_LFS_REPOSITORY,
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/vnd.git-lfs+json",
},
body: JSON.stringify(lfs_data),
});

file = await requestUrl({
url: lfs_location.json.objects[0].actions.download.href,
});
}

let execution_time = (Date.now() - start_time) / 1000;

Expand Down

0 comments on commit 6f937dd

Please sign in to comment.