Skip to content

Commit

Permalink
fix: use fixed liberta js and wait for complete text upload
Browse files Browse the repository at this point in the history
  • Loading branch information
amiller68 committed Apr 15, 2024
1 parent 3672eb9 commit 50aea0c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "quasar build"
},
"dependencies": {
"@libertai/libertai-js": "0.0.2",
"@libertai/libertai-js": "0.0.3",
"@quasar/extras": "^1.16.4",
"@solana/web3.js": "^1.90.0",
"aleph-sdk-ts": "^3.9.2",
Expand Down
45 changes: 27 additions & 18 deletions src/components/KnowledgeStoreUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,37 @@ export default createUploaderComponent({
}

/**
* Extract tile, text from a file
* @param {File} file
* @returns {Promise<{title: string, text: string}>}
* Extract title and text content from a file.
* Supports PDF and plain text files.
* @param {File} file - The file to process.
* @returns {Promise<{ title: string; text: string }>} - The extracted title and text content.
*/
async function processFile(file) {
const title = file.name;
let text = '';
const reader = new FileReader();
switch (file.type) {
case 'application/pdf':
text = await extractTextFromPdfFile(file);
break;
case 'text/plain':
reader.onload = async (event) => {
text = event.target.result;
};
reader.readAsText(file);
break;
default:
throw new Error('Unsupported file type');
let extractedText = '';

try {
switch (file.type) {
case 'application/pdf':
extractedText = await extractTextFromPdfFile(file);
break;
case 'text/plain':
extractedText = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (event) => resolve(event.target.result);
reader.onerror = (error) => reject(error);
reader.readAsText(file);
});
break;
default:
throw new Error(`Unsupported file type: ${file.type}`);
}
} catch (error) {
console.error('Error processing file:', error);
throw error;
}
return { title, text };

return { title, text: extractedText };
}

/**
Expand Down

0 comments on commit 50aea0c

Please sign in to comment.