Skip to content
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

langchain[minor]: Add missing props to UnstructuredLoader #4733

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions langchain/src/document_loaders/fs/unstructured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export type UnstructuredLoaderOptions = {
hiResModelName?: StringWithAutocomplete<HiResModelName>;
includePageBreaks?: boolean;
chunkingStrategy?: StringWithAutocomplete<ChunkingStrategy>;
multiPageSections?: boolean;
combineUnderNChars?: number;
newAfterNChars?: number;
maxCharacters?: number;
};

type UnstructuredDirectoryLoaderOptions = UnstructuredLoaderOptions & {
Expand Down Expand Up @@ -154,6 +158,14 @@ export class UnstructuredLoader extends BaseDocumentLoader {

private chunkingStrategy?: StringWithAutocomplete<ChunkingStrategy>;

private multiPageSections?: boolean;

private combineUnderNChars?: number;

private newAfterNChars?: number;

private maxCharacters?: number;

constructor(
filePathOrLegacyApiUrl: string,
optionsOrLegacyFilePath: UnstructuredLoaderOptions | string = {}
Expand Down Expand Up @@ -181,6 +193,10 @@ export class UnstructuredLoader extends BaseDocumentLoader {
this.hiResModelName = options.hiResModelName;
this.includePageBreaks = options.includePageBreaks;
this.chunkingStrategy = options.chunkingStrategy;
this.multiPageSections = options.multiPageSections;
this.combineUnderNChars = options.combineUnderNChars;
this.newAfterNChars = options.newAfterNChars;
this.maxCharacters = options.maxCharacters;
}
}

Expand Down Expand Up @@ -226,6 +242,21 @@ export class UnstructuredLoader extends BaseDocumentLoader {
if (this.chunkingStrategy) {
formData.append("chunking_strategy", this.chunkingStrategy);
}
if (this.multiPageSections !== undefined) {
formData.append(
"multipage_sections",
this.multiPageSections ? "true" : "false"
);
}
if (this.combineUnderNChars !== undefined) {
formData.append("combine_under_n_chars", String(this.combineUnderNChars));
}
if (this.newAfterNChars !== undefined) {
formData.append("new_after_n_chars", String(this.newAfterNChars));
}
if (this.maxCharacters !== undefined) {
formData.append("max_characters", String(this.maxCharacters));
}

const headers = {
"UNSTRUCTURED-API-KEY": this.apiKey ?? "",
Expand Down
Loading