Skip to content

Commit

Permalink
Update hf migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
prajwal-pai77 committed Jan 27, 2025
1 parent 6a073bf commit d90f014
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/pages/Tools/HuggingFaceMigrate/huggingFaceMigrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export const huggingFaceMigrate = async () => {
case "vscode-couchbase.tools.huggingFaceMigrate.listConfigs":
try {
const configs = await HuggingFaceToCouchbase.listConfigs(
message.repositoryPath
message.repositoryPath,
message.trustRemoteCode
);
currentPanel.webview.postMessage({
command:
Expand All @@ -109,6 +110,7 @@ export const huggingFaceMigrate = async () => {
try {
const splits = await HuggingFaceToCouchbase.listSplits(
message.repositoryPath,
message.trustRemoteCode,
message.config
);
currentPanel.webview.postMessage({
Expand All @@ -129,6 +131,7 @@ export const huggingFaceMigrate = async () => {
try {
const fields = await HuggingFaceToCouchbase.listFields(
message.repositoryPath,
message.trustRemoteCode,
message.config,
message.split
);
Expand Down Expand Up @@ -171,6 +174,7 @@ export const huggingFaceMigrate = async () => {
const formData = message.data;
await HuggingFaceToCouchbase.export(
formData.repoLink,
formData.trustRemoteCode,
formData.filePaths,
formData.config,
formData.split,
Expand Down
21 changes: 19 additions & 2 deletions src/tools/HFMigrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class HuggingFaceToCouchbase {
});
}
static async listConfigs(
repositoryPath: string
repositoryPath: string,
trustRemoteCode: string
): Promise<string | undefined> {
const connection = getActiveConnection();
if (!connection) {
Expand All @@ -40,6 +41,10 @@ export class HuggingFaceToCouchbase {
cmd.push("--path");
cmd.push(repositoryPath);
cmd.push('--json-output');
if (trustRemoteCode) {
cmd.push("--trust-remote-code");
}


const command = cmd.join(" ");
const result = await this.runCommand(command); // Run the command and capture the output
Expand All @@ -53,6 +58,7 @@ export class HuggingFaceToCouchbase {

static async listSplits(
repositoryPath: string,
trustRemoteCode: string,
config: string
): Promise<string | undefined> {
const connection = getActiveConnection();
Expand All @@ -75,7 +81,10 @@ export class HuggingFaceToCouchbase {
cmd.push(repositoryPath);
cmd.push('--name');
cmd.push(config);
cmd.push('--json-output')
cmd.push('--json-output');
if (trustRemoteCode) {
cmd.push("--trust-remote-code");
}

const command = cmd.join(" ");
const result = await this.runCommand(command);
Expand All @@ -89,6 +98,7 @@ export class HuggingFaceToCouchbase {

static async listFields(
repositoryPath: string,
trustRemoteCode: string,
config: string,
split: string
): Promise<string | undefined> {
Expand All @@ -115,6 +125,9 @@ export class HuggingFaceToCouchbase {
cmd.push('--split');
cmd.push(split);
cmd.push('--json-output');
if (trustRemoteCode) {
cmd.push("--trust-remote-code");
}
const command = cmd.join(" ");
const result = await this.runCommand(command); // Run the command and capture the output
return result; // Return the output
Expand All @@ -127,6 +140,7 @@ export class HuggingFaceToCouchbase {

static async export(
repoLink: string,
trustRemoteCode: string,
filePaths: string,
config: string,
split: string,
Expand Down Expand Up @@ -171,6 +185,9 @@ export class HuggingFaceToCouchbase {
cmd.push("--split");
cmd.push(split);
}
if (trustRemoteCode) {
cmd.push("--trust-remote-code");
}
cmd.push("--cb-url");
cmd.push(connection.url);
cmd.push("--cb-username");
Expand Down
22 changes: 21 additions & 1 deletion src/webViews/tools/huggingFaceImporter.webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
<br>
<div style="display: flex; align-items: center;">
<div class="radio-group">
<input type="radio" id="useRepo" name="dataMethod" value="repo">
<input type="radio" id="useRepo" name="dataMethod" value="repo" checked>
<label for="useRepo" class="form-label-align">Repo</label>
</div>
<div class="radio-group">
Expand All @@ -335,6 +335,14 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
<div id="pathInputContainer" style="display:none;">
<label for="filePaths">File Paths (comma-separated):</label>
<input type="text" id="filePaths" name="filePaths" placeholder="e.g., /path/to/file1,/path/to/file2">
</div>
<br>
<div class="checkbox-row">
<div class="checkbox-container tooltip">
<input type="checkbox" id="trust-remote-code" name="trust-remote-code" checked>
<label for="trust-remote-code">Trust Remote Code</label>
<span class="tooltiptext">Check to enable Trust remote code flag.</span>
</div>
</div>
<div class="validation-error" id="validation-error-connect"></div>
<div id="configContainer" style="display:none;">
Expand Down Expand Up @@ -451,6 +459,8 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
event.preventDefault();
document.getElementById("validation-error").innerHTML = "";
document.getElementById("validation-error-connect").innerHTML = "";
const trustRemoteCodeElement = document.getElementById("trust-remote-code");
const trustRemoteCode = trustRemoteCodeElement.checked;
// Ensure the Repo option is selected
if (!$('#useRepo').is(':checked')) {
Expand Down Expand Up @@ -480,6 +490,7 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
vscode.postMessage({
command: "vscode-couchbase.tools.huggingFaceMigrate.listConfigs",
repositoryPath: repoLink,
trustRemoteCode: trustRemoteCode,
});
}
Expand Down Expand Up @@ -653,6 +664,8 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
$('#fields').html(''); // Clear existing options
const repoLink = document.getElementById("repoLink").value;
const trustRemoteCodeElement = document.getElementById("trust-remote-code");
const trustRemoteCode = trustRemoteCodeElement.checked;
// Disable splits until data is loaded
$('#splits').prop('disabled', true);
Expand All @@ -661,6 +674,7 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
vscode.postMessage({
command: "vscode-couchbase.tools.huggingFaceMigrate.listSplits",
repositoryPath: repoLink,
trustRemoteCode: trustRemoteCode,
config: selectedConfig,
});
}
Expand All @@ -678,12 +692,15 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
$('#fields').html(''); // Clear existing options
const repoLink = document.getElementById("repoLink").value;
const trustRemoteCodeElement = document.getElementById("trust-remote-code")
const trustRemoteCode = trustRemoteCodeElement.checked;
const selectedConfig = document.getElementById("configs").value;
// Send a message to fetch fields for the selected split
vscode.postMessage({
command: "vscode-couchbase.tools.huggingFaceMigrate.listFields",
repositoryPath: repoLink,
trustRemoteCode: trustRemoteCode,
config: selectedConfig,
split: selectedSplit,
});
Expand Down Expand Up @@ -734,6 +751,8 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
document.getElementById("validation-error").innerHTML = "";
const repoLink = document.getElementById("repoLink").value;
const trustRemoteCodeCheckBox = document.getElementById("trust-remote-code");
const trustRemoteCode = trustRemoteCodeCheckBox.checked;
const bucket = document.getElementById("bucket").value;
const scope = document.getElementById("cbScope").value;
const collection = document.getElementById("cbCollection").value;
Expand All @@ -742,6 +761,7 @@ export const huggingFaceMigrateWebView = async (buckets: string[]): Promise<stri
const dataMethod = $('input[name="dataMethod"]:checked').val();
let formData = {
repoLink,
trustRemoteCode,
bucket,
scope,
collection,
Expand Down

0 comments on commit d90f014

Please sign in to comment.