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

fix(cloud): allow filename in llama parse #1364

Merged
merged 6 commits into from
Oct 22, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/cold-beers-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@llamaindex/cloud": patch
---

fix(cloud): allow filename in llama parse
Binary file added examples/data/pto_policy_employee.docx
Binary file not shown.
52 changes: 52 additions & 0 deletions examples/readers/src/llamaparse-docx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Language, LlamaParseReader } from "llamaindex";
import fs from "node:fs";
import path from "node:path";

type LlamaParseReaderParams = Partial<
Omit<LlamaParseReader, "language" | "apiKey">
> & {
language?: Language | Language[] | undefined;
apiKey?: string | undefined;
};

async function main() {
const filePath = "../data/pto_policy_employee.docx";
if (!fs.existsSync(filePath)) {
console.error(`File ${filePath} does not exist`);
process.exit(1);
} else {
console.log(`File ${filePath} exists`);
}

const params: LlamaParseReaderParams = {
verbose: true,
parsingInstruction:
"Extract the text from the document a long with any images and tables. This is a document for a course and the contents of the images are important.",
fastMode: false,
gpt4oMode: true,
useVendorMultimodalModel: true,
vendorMultimodalModelName: "anthropic-sonnet-3.5",
premiumMode: true,
resultType: "markdown",
apiKey: process.env.LLAMA_CLOUD_API_KEY,
doNotCache: true,
};

// set up the llamaparse reader
const reader = new LlamaParseReader(params);

const buffer = fs.readFileSync(filePath);
const documents = await reader.loadDataAsContent(
new Uint8Array(buffer),
path.basename(filePath),
);

let allText = "";
documents.forEach((doc) => {
allText += doc.text;
});

console.log(allText);
}

main().catch(console.error);
Loading