-
Notifications
You must be signed in to change notification settings - Fork 375
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: use Blob instead of File #1231
Merged
himself65
merged 18 commits into
run-llama:main
from
himself65:himself65/20240919/ignore
Sep 19, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
93c9320
fix: use Blob instead of File
himself65 3c9f06d
fixup! changelog
himself65 84d332c
fix: remove TOS.pdf
himself65 4c0a987
ci: user
himself65 57b34a1
ci: password & user
himself65 fc089d7
ci: fix
himself65 a424b70
fix: pgConfig
himself65 342c93a
fix: pwd
himself65 b893f06
fix: user
himself65 3c139f3
fix: user
himself65 275c5d1
fix: crypto is not defined in nodejs18
himself65 cb5929e
fix: env
himself65 bbcc85a
fix: debug
himself65 2cfa74a
fix: debug
himself65 c0b1dd5
fix: ci
himself65 7ab2850
fix: ci
himself65 eba925f
fix: remove log
himself65 94476ca
fix: use dotenv
himself65 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,7 @@ | ||
--- | ||
"@llamaindex/cloud": patch | ||
--- | ||
|
||
fix: backport for node.js 18 | ||
|
||
There could have one missing API in the node.js 18, so we need to backport it to make it work. |
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
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 @@ | ||
POSTGRES_USER=runner |
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
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
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,176 @@ | ||
/** | ||
* DO NOT PUT THIS TEST CASE FROM VITEST TO NODE.JS TEST RUNNER | ||
* | ||
* msw has side effect that will replace the global fetch function, | ||
* which will cause the test runner to hang indefinitely for some reason. | ||
* but vitest will start new process for each test case, so it's safe to use msw in vitest, | ||
* in the meanwhile, node.js test runner only run in single process. | ||
*/ | ||
import { faker } from "@faker-js/faker"; | ||
import { http, HttpResponse } from "msw"; | ||
import { setupServer } from "msw/node"; | ||
import { fileURLToPath } from "node:url"; | ||
import { afterAll, afterEach, beforeAll, expect, test } from "vitest"; | ||
|
||
const jobsHashMap = new Map<string, boolean>(); | ||
|
||
const handlers = [ | ||
http.post("https://api.cloud.llamaindex.ai/api/v1/parsing/upload", () => { | ||
return HttpResponse.json({ | ||
id: faker.string.uuid(), | ||
}); | ||
}), | ||
http.get( | ||
"https://api.cloud.llamaindex.ai/api/v1/parsing/job/:id", | ||
({ params }): HttpResponse => { | ||
const jobId = params.id as string; | ||
if (jobsHashMap.has(jobId)) { | ||
return HttpResponse.json({ | ||
id: jobId, | ||
status: "SUCCESS", | ||
}); | ||
} else { | ||
jobsHashMap.set(jobId, true); | ||
} | ||
return HttpResponse.json({ | ||
id: jobId, | ||
status: "PENDING", | ||
}); | ||
}, | ||
), | ||
http.get( | ||
"https://api.cloud.llamaindex.ai/api/v1/parsing/job/:id/result/markdown", | ||
() => { | ||
const job_metadata = { | ||
credits_used: faker.number.int({ min: 1, max: 10 }), | ||
credits_max: 1000, | ||
job_credits_usage: faker.number.int({ min: 1, max: 10 }), | ||
job_pages: faker.number.int({ min: 0, max: 5 }), | ||
job_is_cache_hit: faker.datatype.boolean(), | ||
}; | ||
return HttpResponse.json({ | ||
markdown: faker.lorem.paragraphs({ | ||
min: 3, | ||
max: 1000, | ||
}), | ||
job_metadata, | ||
}); | ||
}, | ||
), | ||
http.get( | ||
"https://api.cloud.llamaindex.ai/api/v1/parsing/job/:id/result/text", | ||
() => { | ||
const job_metadata = { | ||
credits_used: faker.number.int({ min: 1, max: 10 }), | ||
credits_max: 1000, | ||
job_credits_usage: faker.number.int({ min: 1, max: 10 }), | ||
job_pages: faker.number.int({ min: 0, max: 5 }), | ||
job_is_cache_hit: faker.datatype.boolean(), | ||
}; | ||
return HttpResponse.json({ | ||
text: faker.lorem.paragraphs({ | ||
min: 3, | ||
max: 1000, | ||
}), | ||
job_metadata, | ||
}); | ||
}, | ||
), | ||
http.get( | ||
"https://api.cloud.llamaindex.ai/api/v1/parsing/job/:id/result/json", | ||
() => { | ||
const pages = Array.from({ length: 1 }, () => ({ | ||
page: 1, | ||
text: faker.lorem.paragraphs(2), | ||
md: `# ${faker.lorem.sentence()}\n\n${faker.lorem.paragraph()}`, | ||
images: [ | ||
{ | ||
name: faker.system.fileName(), | ||
height: faker.number.int({ min: 100, max: 500 }), | ||
width: faker.number.int({ min: 600, max: 1600 }), | ||
x: faker.number.int({ min: 0, max: 50 }), | ||
y: faker.number.int({ min: 0, max: 50 }), | ||
original_width: faker.number.int({ min: 1800, max: 2000 }), | ||
original_height: faker.number.int({ min: 400, max: 600 }), | ||
}, | ||
], | ||
items: [ | ||
{ | ||
type: "heading", | ||
lvl: 1, | ||
value: faker.lorem.sentence(), | ||
md: `# ${faker.lorem.sentence()}`, | ||
bBox: { | ||
x: faker.number.float({ min: 20, max: 40 }), | ||
y: faker.number.float({ min: 20, max: 30 }), | ||
w: faker.number.float({ min: 300, max: 400 }), | ||
h: faker.number.float({ min: 30, max: 50 }), | ||
}, | ||
}, | ||
{ | ||
type: "table", | ||
rows: [ | ||
[faker.lorem.word(), faker.lorem.sentence()], | ||
[faker.lorem.word(), faker.lorem.sentence()], | ||
[faker.lorem.word(), faker.lorem.sentence()], | ||
[faker.lorem.word(), faker.lorem.sentence()], | ||
], | ||
md: faker.lorem.sentences(4), | ||
isPerfectTable: faker.datatype.boolean(), | ||
csv: faker.lorem.sentences(4), | ||
}, | ||
{ | ||
type: "text", | ||
value: faker.lorem.paragraphs(2), | ||
md: faker.lorem.paragraphs(2), | ||
bBox: { | ||
x: faker.number.float({ min: 5, max: 10 }), | ||
y: faker.number.float({ min: 20, max: 30 }), | ||
w: faker.number.float({ min: 800, max: 900 }), | ||
h: faker.number.float({ min: 30, max: 50 }), | ||
}, | ||
}, | ||
], | ||
})); | ||
|
||
const response = { | ||
pages, | ||
job_metadata: { | ||
credits_used: faker.number.int({ min: 1, max: 10 }), | ||
credits_max: 1000, | ||
job_credits_usage: faker.number.int({ min: 1, max: 10 }), | ||
job_pages: faker.number.int({ min: 0, max: 5 }), | ||
job_is_cache_hit: faker.datatype.boolean(), | ||
}, | ||
}; | ||
return HttpResponse.json(response); | ||
}, | ||
), | ||
]; | ||
|
||
const server = setupServer(...handlers); | ||
|
||
beforeAll(() => { | ||
server.listen({ | ||
onUnhandledRequest: "error", | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
server.resetHandlers(); | ||
}); | ||
|
||
afterAll(() => { | ||
server.close(); | ||
}); | ||
|
||
test("llama parse should return a successful document", async () => { | ||
const { LlamaParseReader } = await import("@llamaindex/cloud/reader"); | ||
const reader = new LlamaParseReader({ | ||
verbose: false, | ||
apiKey: "llx-fake-api-key", | ||
}); | ||
const fileUrl = new URL("../../../../examples/data/TOS.pdf", import.meta.url); | ||
const documents = await reader.loadData(fileURLToPath(fileUrl)); | ||
expect(documents.length).toBe(1); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is confusing, nodejs test runner actually doesn't read environment variable by default