forked from run-llama/LlamaIndexTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: LlamaParse json mode returns array + basic example (run-llama#914)
Co-authored-by: Marcus Schiesser <[email protected]> Co-authored-by: Marcus Schiesser <[email protected]>
- Loading branch information
1 parent
83b2f0b
commit c8cfc6c
Showing
4 changed files
with
49 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import fs from "fs/promises"; | ||
import { LlamaParseReader } from "llamaindex"; | ||
|
||
async function main() { | ||
// Load PDF using LlamaParse json mode | ||
const reader = new LlamaParseReader({ resultType: "json" }); | ||
const jsonObjs = await reader.loadJson("../data/uber_10q_march_2022.pdf"); | ||
|
||
// Write the JSON objects to a file | ||
try { | ||
await fs.writeFile("jsonObjs.json", JSON.stringify(jsonObjs, null, 4)); | ||
console.log("Array of JSON objects has been written to jsonObjs.json"); | ||
} catch (e) { | ||
console.error("Error writing jsonObjs.json", e); | ||
} | ||
|
||
const jsonList = jsonObjs[0]["pages"]; | ||
|
||
// Write the list of JSON objects as a single array to a file | ||
try { | ||
await fs.writeFile("jsonList.json", JSON.stringify(jsonList, null, 4)); | ||
console.log( | ||
"List of JSON objects as single array has been written to jsonList.json", | ||
); | ||
} catch (e) { | ||
console.error("Error writing jsonList.json", e); | ||
} | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters