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

Implement pdf content extraction #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"erusev/parsedown": "^1.7",
"henck/rtf-to-html": "^1.2",
"html2text/html2text": "^4.3",
"phpoffice/phpword": "^1.2"
"phpoffice/phpword": "^1.2",
"smalot/pdfparser": "^2.10"
},
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
Expand Down
133 changes: 132 additions & 1 deletion composer.lock

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

8 changes: 8 additions & 0 deletions lib/Service/AssistantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use RtfHtmlPhp\Document;
use RtfHtmlPhp\Html\HtmlFormatter;
use RuntimeException;
use Smalot\PdfParser\Parser;

/**
* @psalm-import-type AssistantTaskProcessingTaskType from ResponseDefinitions
Expand Down Expand Up @@ -613,6 +614,13 @@ public function parseTextFromFile(string $userId, ?string $filePath = null, ?int
$this->tempManager->clean();
break;
}
case 'application/pdf':
{
$parser = new Parser();
$pdf = $parser->parseContent($fileContent);
$text = $pdf->getText();
break;
}
}
return $text;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/TextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const VALID_MIME_TYPES = [
'application/msword', // doc
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // docx
'application/vnd.oasis.opendocument.text', // odt
// 'application/pdf', // Not yet supported
'application/pdf', // pdf
]

const picker = (callback, target) => getFilePickerBuilder(t('assistant', 'Choose a text file'))
Expand Down