Compare commits

..

3 Commits

Author SHA1 Message Date
github-actions[bot] e0af059221 Release 0.4.11 (#1008)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-07-02 15:07:03 -07:00
Alex Yang 8bf5b4acfd fix: llama parse input spreadsheet (#1007) 2024-07-02 14:48:51 -07:00
Alex Yang 93a003baa0 ci: pre release (#1005) 2024-07-02 00:40:45 -07:00
25 changed files with 233 additions and 121 deletions
+28
View File
@@ -0,0 +1,28 @@
name: Publish Preview
on: [pull_request]
jobs:
pre_release:
name: Pre Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm run build
- name: Pre Release
run: pnpx pkg-pr-new publish ./packages/*
+7
View File
@@ -1,5 +1,12 @@
# docs
## 0.0.37
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.0.36
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.36",
"version": "0.0.37",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
@@ -1,5 +1,13 @@
# @llamaindex/autotool-02-next-example
## 0.1.21
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
- @llamaindex/autotool@1.0.0
## 0.1.20
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/autotool-02-next-example",
"private": true,
"version": "0.1.20",
"version": "0.1.21",
"scripts": {
"dev": "next dev",
"build": "next build",
+1 -1
View File
@@ -51,7 +51,7 @@
"unplugin": "^1.10.1"
},
"peerDependencies": {
"llamaindex": "^0.4.10",
"llamaindex": "^0.4.11",
"openai": "^4",
"typescript": "^4"
},
+7
View File
@@ -1,5 +1,12 @@
# @llamaindex/community
## 0.0.15
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.0.14
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/community",
"description": "Community package for LlamaIndexTS",
"version": "0.0.14",
"version": "0.0.15",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+7
View File
@@ -1,5 +1,12 @@
# @llamaindex/experimental
## 0.0.46
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.0.45
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/experimental",
"description": "Experimental package for LlamaIndexTS",
"version": "0.0.45",
"version": "0.0.46",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+6
View File
@@ -1,5 +1,11 @@
# llamaindex
## 0.4.11
### Patch Changes
- 8bf5b4a: fix: llama parse input spreadsheet
## 0.4.10
### Patch Changes
@@ -1,5 +1,12 @@
# @llamaindex/cloudflare-worker-agent-test
## 0.0.30
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.0.29
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloudflare-worker-agent-test",
"version": "0.0.29",
"version": "0.0.30",
"type": "module",
"private": true,
"scripts": {
@@ -1,5 +1,12 @@
# @llamaindex/next-agent-test
## 0.1.30
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.1.29
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-agent-test",
"version": "0.1.29",
"version": "0.1.30",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,12 @@
# test-edge-runtime
## 0.1.29
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.1.28
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/nextjs-edge-runtime-test",
"version": "0.1.28",
"version": "0.1.29",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,12 @@
# @llamaindex/next-node-runtime
## 0.0.11
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.0.10
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-node-runtime-test",
"version": "0.0.10",
"version": "0.0.11",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,12 @@
# @llamaindex/waku-query-engine-test
## 0.0.30
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.0.29
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/waku-query-engine-test",
"version": "0.0.29",
"version": "0.0.30",
"type": "module",
"private": true,
"scripts": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llamaindex",
"version": "0.4.10",
"version": "0.4.11",
"license": "MIT",
"type": "module",
"keywords": [
@@ -1,105 +1,100 @@
import { Document } from "@llamaindex/core/schema";
import { fs, getEnv } from "@llamaindex/env";
import { filetypemime } from "magic-bytes.js";
import { filetypeinfo } from "magic-bytes.js";
import { FileReader, type Language, type ResultType } from "./type.js";
const SupportedFiles: { [key: string]: string } = {
".pdf": "application/pdf",
// Documents and Presentations
".602": "application/x-t602",
".abw": "application/x-abiword",
".cgm": "image/cgm",
".cwk": "application/x-cwk",
".doc": "application/msword",
".docx":
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".docm": "application/vnd.ms-word.document.macroEnabled.12",
".dot": "application/msword",
".dotm": "application/vnd.ms-word.template.macroEnabled.12",
".dotx":
"application/vnd.openxmlformats-officedocument.wordprocessingml.template",
".hwp": "application/x-hwp",
".key": "application/x-iwork-keynote-sffkey",
".lwp": "application/vnd.lotus-wordpro",
".mw": "application/macwriteii",
".mcw": "application/macwriteii",
".pages": "application/x-iwork-pages-sffpages",
".pbd": "application/x-pagemaker",
".ppt": "application/vnd.ms-powerpoint",
".pptm": "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
".pptx":
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
".pot": "application/vnd.ms-powerpoint",
".potm": "application/vnd.ms-powerpoint.template.macroEnabled.12",
".potx":
"application/vnd.openxmlformats-officedocument.presentationml.template",
".rtf": "application/rtf",
".sda": "application/vnd.stardivision.draw",
".sdd": "application/vnd.stardivision.impress",
".sdp": "application/sdp",
".sdw": "application/vnd.stardivision.writer",
".sgl": "application/vnd.stardivision.writer",
".sti": "application/vnd.sun.xml.impress.template",
".sxi": "application/vnd.sun.xml.impress",
".sxw": "application/vnd.sun.xml.writer",
".stw": "application/vnd.sun.xml.writer.template",
".sxg": "application/vnd.sun.xml.writer.global",
".txt": "text/plain",
".uof": "application/vnd.uoml+xml",
".uop": "application/vnd.openofficeorg.presentation",
".uot": "application/x-uo",
".vor": "application/vnd.stardivision.writer",
".wpd": "application/wordperfect",
".wps": "application/vnd.ms-works",
".xml": "application/xml",
".zabw": "application/x-abiword",
// Images
".epub": "application/epub+zip",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".bmp": "image/bmp",
".svg": "image/svg+xml",
".tiff": "image/tiff",
".webp": "image/webp",
// Web
".htm": "text/html",
".html": "text/html",
// Spreadsheets
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
".xls": "application/vnd.ms-excel",
".xlsm": "application/vnd.ms-excel.sheet.macroEnabled.12",
".xlsb": "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
".xlw": "application/vnd.ms-excel",
".csv": "text/csv",
".dif": "application/x-dif",
".sylk": "text/vnd.sylk",
".slk": "text/vnd.sylk",
".prn": "application/x-prn",
".numbers": "application/x-iwork-numbers-sffnumbers",
".et": "application/vnd.ms-excel",
".ods": "application/vnd.oasis.opendocument.spreadsheet",
".fods": "application/vnd.oasis.opendocument.spreadsheet",
".uos1": "application/vnd.uoml+xml",
".uos2": "application/vnd.uoml+xml",
".dbf": "application/vnd.dbf",
".wk1": "application/vnd.lotus-1-2-3",
".wk2": "application/vnd.lotus-1-2-3",
".wk3": "application/vnd.lotus-1-2-3",
".wk4": "application/vnd.lotus-1-2-3",
".wks": "application/vnd.lotus-1-2-3",
".123": "application/vnd.lotus-1-2-3",
".wq1": "application/x-lotus",
".wq2": "application/x-lotus",
".wb1": "application/x-quattro-pro",
".wb2": "application/x-quattro-pro",
".wb3": "application/x-quattro-pro",
".qpw": "application/x-quattro-pro",
".xlr": "application/vnd.ms-works",
".eth": "application/ethos",
".tsv": "text/tab-separated-values",
};
const SUPPORT_FILE_EXT: string[] = [
".pdf",
// document and presentations
".602",
".abw",
".cgm",
".cwk",
".doc",
".docx",
".docm",
".dot",
".dotm",
".hwp",
".key",
".lwp",
".mw",
".mcw",
".pages",
".pbd",
".ppt",
".pptm",
".pptx",
".pot",
".potm",
".potx",
".rtf",
".sda",
".sdd",
".sdp",
".sdw",
".sgl",
".sti",
".sxi",
".sxw",
".stw",
".sxg",
".txt",
".uof",
".uop",
".uot",
".vor",
".wpd",
".wps",
".xml",
".zabw",
".epub",
// images
".jpg",
".jpeg",
".png",
".gif",
".bmp",
".svg",
".tiff",
".webp",
// web
".htm",
".html",
// spreadsheets
".xlsx",
".xls",
".xlsm",
".xlsb",
".xlw",
".csv",
".dif",
".sylk",
".slk",
".prn",
".numbers",
".et",
".ods",
".fods",
".uos1",
".uos2",
".dbf",
".wk1",
".wk2",
".wk3",
".wk4",
".wks",
".123",
".wq1",
".wq2",
".wb1",
".wb2",
".wb3",
".qpw",
".xlr",
".eth",
".tsv",
];
/**
* Represents a reader for parsing files using the LlamaParse API.
@@ -165,7 +160,7 @@ export class LlamaParseReader extends FileReader {
fileName?: string,
): Promise<string> {
// Load data, set the mime type
const { mimeType, extension } = await this.getMimeType(data);
const { mime, extension } = await LlamaParseReader.getMimeType(data);
if (this.verbose) {
const name = fileName ? fileName : extension;
@@ -173,7 +168,7 @@ export class LlamaParseReader extends FileReader {
}
const body = new FormData();
body.set("file", new Blob([data], { type: mimeType }), fileName);
body.set("file", new Blob([data], { type: mime }), fileName);
const LlamaParseBodyParams = {
language: this.language,
@@ -378,19 +373,23 @@ export class LlamaParseReader extends FileReader {
return images;
}
private async getMimeType(
static async getMimeType(
data: Uint8Array,
): Promise<{ mimeType: string; extension: string }> {
const mimes = filetypemime(data); // Get an array of possible MIME types
const extension = Object.keys(SupportedFiles).find(
(ext) => SupportedFiles[ext] === mimes[0],
); // Find the extension for the first MIME type
if (!extension) {
const supportedExtensions = Object.keys(SupportedFiles).join(", ");
): Promise<{ mime: string; extension: string }> {
const typeinfos = filetypeinfo(data);
// find the first type info that matches the supported MIME types
// It could be happened that docx file is recognized as zip file, so we need to check the mime type
const info = typeinfos.find((info) => {
if (info.extension && SUPPORT_FILE_EXT.includes(`.${info.extension}`)) {
return info;
}
});
if (!info || !info.mime || !info.extension) {
const ext = SUPPORT_FILE_EXT.join(", ");
throw new Error(
`File has type "${mimes[0]}" which does not match supported MIME Types. Supported formats include: ${supportedExtensions}`,
`File has type which does not match supported MIME Types. Supported formats include: ${ext}`,
);
}
return { mimeType: mimes[0], extension }; // Return the first MIME type and its corresponding extension
return { mime: info.mime, extension: info.extension };
}
}
Binary file not shown.
@@ -0,0 +1,15 @@
import { LlamaParseReader } from "llamaindex";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, test } from "vitest";
const fixturesDir = fileURLToPath(new URL("./fixtures", import.meta.url));
test("file type should be detected correctly", async () => {
const xlsx = join(fixturesDir, "test.xlsx");
const buffer = await readFile(xlsx);
const { mime, extension } = await LlamaParseReader.getMimeType(buffer);
expect(mime).toBe("application/vnd.oasis.opendocument.spreadsheet");
expect(extension).toBe("ods");
});