Skip to content

Commit e9f1248

Browse files
authored
Add LLamaCloud support (#5)
1 parent 72ba2b6 commit e9f1248

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/DocumentProcessor.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@ enum DocumentProcessor: string
1717
* Uses https://github.com/pymupdf/PyMuPDF as document processor to extract text
1818
*/
1919
case PYMUPDF = 'pymupdf';
20+
21+
/**
22+
* The LLama Parse processor
23+
*
24+
* Uses LLamaCloud https://cloud.llamaindex.ai/ as document processor to extract text
25+
*/
26+
case LLAMAPARSE = 'llama';
2027
}

tests/ParseProcessorSelectionTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,34 @@
6868

6969
$mockClient->assertSentCount(1);
7070
});
71+
72+
test('llamaparse can be selected as processor', function () {
73+
$mockClient = MockClient::global([
74+
ExtractTextRequest::class => MockResponse::fixture('extract-text-empty'),
75+
]);
76+
77+
$connector = new ParseConnector('fake', 'http://localhost:5002');
78+
$connector->withMockClient($mockClient);
79+
80+
$connector->parse(
81+
url: 'http://localhost/empty.pdf',
82+
options: new ParseOption(DocumentProcessor::LLAMAPARSE),
83+
);
84+
85+
$mockClient->assertSent(ExtractTextRequest::class);
86+
87+
$mockClient->assertSent(function (Request $request, Response $response) {
88+
if (! $request instanceof ExtractTextRequest) {
89+
return false;
90+
}
91+
92+
/** @var array */
93+
$body = $request->body()->all();
94+
95+
return $body['url'] === 'http://localhost/empty.pdf'
96+
&& $body['mime_type'] === 'application/pdf'
97+
&& $body['driver'] === 'llama';
98+
});
99+
100+
$mockClient->assertSentCount(1);
101+
});

0 commit comments

Comments
 (0)