-
-
Notifications
You must be signed in to change notification settings - Fork 13.2k
β¨ feat: Add configurable PDF processing method with Unstructured #5927
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8745ca5
β¨ feat: Add configurable PDF processing method with Unstructured
fzlzjerry 06cbc84
π§ fix: Update import path for env utility in ContentChunk module
fzlzjerry 76bdec6
Merge branch 'main' into fix/unstructured_io
fzlzjerry d868e7b
Merge branch 'main' into fix/unstructured_io
fzlzjerry f9b7751
Merge branch 'main' into fix/unstructured_io
fzlzjerry c67fb33
Merge branch 'main' into fix/unstructured_io
fzlzjerry e8f0b03
Merge branch 'lobehub:main' into fix/unstructured_io
fzlzjerry 4de5511
feat: add USE_UNSTRUCTURED_FOR_PDF environment variable to knowledge β¦
fzlzjerry 79a6da5
Merge branch 'main' into fix/unstructured_io
fzlzjerry d6301bb
Delete src/server/utils/env.ts
fzlzjerry c132ff3
feat: implement ChunkingRuleParser for file type and service mapping
fzlzjerry 6c3f3f4
Merge branch 'main' into fix/unstructured_io
fzlzjerry b82f9fe
refactor: remove USE_UNSTRUCTURED_FOR_PDF from knowledge environment β¦
fzlzjerry 32771f5
test: add unit tests for ChunkingRuleParser functionality
fzlzjerry ef63c8a
Merge branch 'main' into fix/unstructured_io
fzlzjerry e878342
refactor: remove isUsingUnstructured method from ContentChunk class
fzlzjerry bd7d700
Merge branch 'main' into fix/unstructured_io
fzlzjerry 044c33d
refactor: update ChunkingService type and clean up ContentChunk rules
fzlzjerry 4df73f7
refactor: simplify ChunkingRuleParser and update ContentChunk module
fzlzjerry 9b4038a
refactor: update ContentChunk module import for ChunkingService
fzlzjerry 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 hidden or 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 |
---|---|---|
@@ -1,19 +1,18 @@ | ||
import { createEnv } from '@t3-oss/env-nextjs'; | ||
import { z } from 'zod'; | ||
|
||
export const getKnowledgeConfig = () => { | ||
return createEnv({ | ||
runtimeEnv: { | ||
DEFAULT_FILES_CONFIG: process.env.DEFAULT_FILES_CONFIG, | ||
UNSTRUCTURED_API_KEY: process.env.UNSTRUCTURED_API_KEY, | ||
UNSTRUCTURED_SERVER_URL: process.env.UNSTRUCTURED_SERVER_URL, | ||
}, | ||
server: { | ||
DEFAULT_FILES_CONFIG: z.string().optional(), | ||
UNSTRUCTURED_API_KEY: z.string().optional(), | ||
UNSTRUCTURED_SERVER_URL: z.string().optional(), | ||
}, | ||
}); | ||
}; | ||
|
||
export const knowledgeEnv = getKnowledgeConfig(); | ||
export const knowledgeEnv = createEnv({ | ||
runtimeEnv: { | ||
DEFAULT_FILES_CONFIG: process.env.DEFAULT_FILES_CONFIG, | ||
UNSTRUCTURED_API_KEY: process.env.UNSTRUCTURED_API_KEY, | ||
UNSTRUCTURED_SERVER_URL: process.env.UNSTRUCTURED_SERVER_URL, | ||
USE_UNSTRUCTURED_FOR_PDF: process.env.USE_UNSTRUCTURED_FOR_PDF, | ||
FILE_TYPE_CHUNKING_RULES: process.env.FILE_TYPE_CHUNKING_RULES || 'pdf=unstructured', | ||
}, | ||
server: { | ||
DEFAULT_FILES_CONFIG: z.string().optional(), | ||
UNSTRUCTURED_API_KEY: z.string().optional(), | ||
UNSTRUCTURED_SERVER_URL: z.string().optional(), | ||
USE_UNSTRUCTURED_FOR_PDF: z.string().optional(), | ||
}, | ||
}); |
arvinxx marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
arvinxx marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,29 @@ | ||
type ChunkingService = 'unstructured' | 'doc2x' | 'default'; | ||
|
||
interface FileTypeRule { | ||
fileType: string; | ||
services: ChunkingService[]; | ||
} | ||
|
||
export class ChunkingRuleParser { | ||
static parse(rulesStr: string): Record<string, ChunkingService[]> { | ||
const rules: Record<string, ChunkingService[]> = {}; | ||
|
||
// Split by semicolon for different file types | ||
const fileTypeRules = rulesStr.split(';'); | ||
|
||
for (const rule of fileTypeRules) { | ||
const [fileType, services] = rule.split('='); | ||
if (!fileType || !services) continue; | ||
|
||
// Split services by comma and validate each service | ||
rules[fileType.toLowerCase()] = services | ||
.split(',') | ||
.map(s => s.trim().toLowerCase()) | ||
.filter((s): s is ChunkingService => | ||
['unstructured', 'doc2x', 'default'].includes(s)); | ||
} | ||
|
||
return rules; | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.