refactor: use chonkie locally - #474
Conversation
|
@adiologydev is attempting to deploy a commit to the Sim Studio Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
There was a problem hiding this comment.
PR Summary
Major refactoring to enable local Chonkie integration and expand file parsing capabilities for improved self-hosting support.
- File parsing system expanded in
apps/sim/lib/file-parsers/with new TXT and MD parsers, but contains critical bugs inparseBufferimplementations and token counting - Removed cloud dependency by eliminating
CHONKIE_API_KEYfromapps/sim/lib/env.tsand updating imports from 'chonkie/cloud' to 'chonkie' apps/sim/lib/documents/document-processor.tssimplified by removing recipe and lang options, now using create() method for chunker instantiation- Both new parsers in
txt-parser.tsandmd-parser.tsneed significant improvements in error handling and buffer processing before production use
6 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile
| it('should parse MD files successfully', async () => { | ||
| const expectedResult = { | ||
| content: 'Parsed MD content', | ||
| metadata: { | ||
| characterCount: 100, | ||
| tokenCount: 10, | ||
| }, | ||
| } | ||
|
|
||
| mockMdParseFile.mockResolvedValueOnce(expectedResult) | ||
| mockExistsSync.mockReturnValue(true) | ||
|
|
||
| const { parseFile } = await import('./index') | ||
| const result = await parseFile('/test/files/document.md') | ||
| }) |
There was a problem hiding this comment.
logic: Missing assertion for result value - this test doesn't verify the parsing output matches expected result
| it('should parse MD files successfully', async () => { | |
| const expectedResult = { | |
| content: 'Parsed MD content', | |
| metadata: { | |
| characterCount: 100, | |
| tokenCount: 10, | |
| }, | |
| } | |
| mockMdParseFile.mockResolvedValueOnce(expectedResult) | |
| mockExistsSync.mockReturnValue(true) | |
| const { parseFile } = await import('./index') | |
| const result = await parseFile('/test/files/document.md') | |
| }) | |
| const result = await parseFile('/test/files/document.md') | |
| expect(result).toEqual(expectedResult) |
| logger.info('Parsing buffer, size:', buffer.length) | ||
|
|
||
| // Extract content | ||
| const result = await readFile(buffer, 'utf-8') |
There was a problem hiding this comment.
logic: Critical error: readFile expects a file path, not a Buffer. Use buffer.toString('utf-8') instead.
| const result = await readFile(buffer, 'utf-8') | |
| const result = buffer.toString('utf-8') |
| logger.info('Parsing buffer, size:', buffer.length) | ||
|
|
||
| // Extract content | ||
| const result = await readFile(buffer, 'utf-8') |
There was a problem hiding this comment.
logic: readFile cannot be used on a buffer. Use buffer.toString('utf-8') instead
| const result = await readFile(buffer, 'utf-8') | |
| const result = buffer.toString('utf-8') |
Description
Uses chonkie locally instead of cloud to make self-hosting easy.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
Checklist:
bun run test)Security Considerations:
Additional Information:
Any additional information, configuration or data that might be necessary to reproduce the issue or use the feature.