Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LlamaIndexTS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
LlamaIndexTS
Commits
17724d96
Unverified
Commit
17724d96
authored
8 months ago
by
Diego Ferreiro Val
Committed by
GitHub
8 months ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: add support for buffer on loadJSON API on LlamaParseReader (#1069)
Co-authored-by:
Alex Yang
<
himself65@outlook.com
>
parent
6776910c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/llamaindex/src/readers/LlamaParseReader.ts
+9
-4
9 additions, 4 deletions
packages/llamaindex/src/readers/LlamaParseReader.ts
with
9 additions
and
4 deletions
packages/llamaindex/src/readers/LlamaParseReader.ts
+
9
−
4
View file @
17724d96
...
@@ -330,13 +330,18 @@ export class LlamaParseReader extends FileReader {
...
@@ -330,13 +330,18 @@ export class LlamaParseReader extends FileReader {
* Loads data from a file and returns an array of JSON objects.
* Loads data from a file and returns an array of JSON objects.
* To be used with resultType = "json"
* To be used with resultType = "json"
*
*
* @param {string} file - The path to the file
to be loaded.
* @param {string} file
PathOrContent
- The
file
path to the file
or the content of the file as a Buffer
* @return {Promise<Record<string, any>[]>} A Promise that resolves to an array of JSON objects.
* @return {Promise<Record<string, any>[]>} A Promise that resolves to an array of JSON objects.
*/
*/
async
loadJson
(
file
:
string
):
Promise
<
Record
<
string
,
any
>
[]
>
{
async
loadJson
(
filePathOrContent
:
string
|
Uint8Array
,
):
Promise
<
Record
<
string
,
any
>
[]
>
{
let
jobId
;
let
jobId
;
const
isFilePath
=
typeof
filePathOrContent
===
"
string
"
;
try
{
try
{
const
data
=
await
fs
.
readFile
(
file
);
const
data
=
isFilePath
?
await
fs
.
readFile
(
filePathOrContent
)
:
filePathOrContent
;
// Creates a job for the file
// Creates a job for the file
jobId
=
await
this
.
createJob
(
data
);
jobId
=
await
this
.
createJob
(
data
);
if
(
this
.
verbose
)
{
if
(
this
.
verbose
)
{
...
@@ -346,7 +351,7 @@ export class LlamaParseReader extends FileReader {
...
@@ -346,7 +351,7 @@ export class LlamaParseReader extends FileReader {
// Return results as an array of JSON objects (same format as Python version of the reader)
// Return results as an array of JSON objects (same format as Python version of the reader)
const
resultJson
=
await
this
.
getJobResult
(
jobId
,
"
json
"
);
const
resultJson
=
await
this
.
getJobResult
(
jobId
,
"
json
"
);
resultJson
.
job_id
=
jobId
;
resultJson
.
job_id
=
jobId
;
resultJson
.
file_path
=
file
;
resultJson
.
file_path
=
isFilePath
?
filePathOrContent
:
undefined
;
return
[
resultJson
];
return
[
resultJson
];
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
`Error while parsing the file under job id
${
jobId
}
`
,
e
);
console
.
error
(
`Error while parsing the file under job id
${
jobId
}
`
,
e
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment