run-llama / create-llama

The easiest way to get started with LlamaIndex
MIT License
882 stars 111 forks source link

Cannot upload PDF files: Provide Uint8Array rather than Buffer #198

Closed SebastianVomMeer closed 2 months ago

SebastianVomMeer commented 2 months ago

After creating a new application with version 0.1.25 I cannot upload PDF files with the web interface.

The POST to http://localhost:3000/api/chat/upload responds with 500:

{"error":"Please provide binary data as `Uint8Array`, rather than `Buffer`."}

Related log:

Processing uploaded document of type: application/pdf
[Upload API] Error: Please provide binary data as `Uint8Array`, rather than `Buffer`.
    at /app/.next/server/chunks/602.js:9:144687
    at tH (/app/.next/server/chunks/602.js:9:145105)
    at i (/app/.next/server/chunks/804.js:1:153)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async l (/app/.next/server/chunks/804.js:1:780)
    at async u (/app/.next/server/chunks/804.js:1:1174)
    at async T (/app/.next/server/app/api/chat/upload/route.js:4:322)
    at async w.loadDataAsContent (/app/.next/server/app/api/chat/upload/route.js:4:146)
    at async S (/app/.next/server/app/api/chat/upload/route.js:4:976)
    at async R (/app/.next/server/app/api/chat/upload/route.js:5:793)
    at async L (/app/.next/server/app/api/chat/upload/route.js:5:1071)
    at async /app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36258
    at async eR.execute (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:26874)
    at async eR.handle (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:37512)
    at async doRender (/app/node_modules/next/dist/server/base-server.js:1377:42)
    at async cacheEntry.responseCache.get.routeKind (/app/node_modules/next/dist/server/base-server.js:1599:28)

This fails when the application runs locally on my Ubuntu 20.04 machine as well as inside a docker container with image nextjs-docker (started as described in your generated README.md). It happens in Chrome and Firefox.

I use azure-openai as model provider but I don't think that this is related. Indexing PDFs with npm run generate works just fine.


✔ What is your project named? … my-app
✔ Which template would you like to use? › Agentic RAG (single agent)
✔ Which framework would you like to use? › NextJS
✔ Would you like to set up observability? › No
✔ Please provide your OpenAI API key (leave blank to skip): … 
✔ Which data source would you like to use? › Use an example PDF (you can add your own data files later)
✔ Would you like to add another data source? › No
✔ Would you like to use LlamaParse (improved parser for RAG - requires API key)? … no / yes › No
✔ Would you like to use a vector database? › No, just store the data in the file system
✔ Would you like to build an agent using tools? If so, select the tools here, otherwise just press enter › 
✔ How would you like to proceed? › Generate code and install dependencies (~2 min)
SebastianVomMeer commented 2 months ago

Converting the fileBuffer in app/api/chat/llamaindex/documents/helper.ts seems to be a workaround for me, but I don't have a clue about this topic.

  console.log(`Processing uploaded document of type: ${mimeType}`);
  return await reader.loadDataAsContent(new Uint8Array(fileBuffer));
marcusschiesser commented 2 months ago

Thanks. Fixed in Release 0.1.26