Skip to content

refactor: use chonkie locally - #474

Closed
adiologydev wants to merge 2 commits into
simstudioai:mainfrom
adiologydev:refactor/chonkie-local
Closed

refactor: use chonkie locally#474
adiologydev wants to merge 2 commits into
simstudioai:mainfrom
adiologydev:refactor/chonkie-local

Conversation

@adiologydev

Copy link
Copy Markdown
Contributor

Description

Uses chonkie locally instead of cloud to make self-hosting easy.

Type of change

Please delete options that are not relevant.

  • Code refactoring (no functional changes)

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:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass locally and in CI (bun run test)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • I have updated version numbers as needed (if needed)
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Security Considerations:

  • My changes do not introduce any new security vulnerabilities
  • I have considered the security implications of my changes

Additional Information:

Any additional information, configuration or data that might be necessary to reproduce the issue or use the feature.

@vercel
vercel Bot temporarily deployed to Preview – docs June 10, 2025 20:08 Inactive
@vercel

vercel Bot commented Jun 10, 2025

Copy link
Copy Markdown

@adiologydev is attempting to deploy a commit to the Sim Studio Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jun 10, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Jun 10, 2025 8:08pm

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in parseBuffer implementations and token counting
  • Removed cloud dependency by eliminating CHONKIE_API_KEY from apps/sim/lib/env.ts and updating imports from 'chonkie/cloud' to 'chonkie'
  • apps/sim/lib/documents/document-processor.ts simplified by removing recipe and lang options, now using create() method for chunker instantiation
  • Both new parsers in txt-parser.ts and md-parser.ts need significant improvements in error handling and buffer processing before production use

6 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile

Comment on lines +262 to +276
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')
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Missing assertion for result value - this test doesn't verify the parsing output matches expected result

Suggested change
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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Critical error: readFile expects a file path, not a Buffer. Use buffer.toString('utf-8') instead.

Suggested change
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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: readFile cannot be used on a buffer. Use buffer.toString('utf-8') instead

Suggested change
const result = await readFile(buffer, 'utf-8')
const result = buffer.toString('utf-8')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant