Skip to content

Commit a159da5

Browse files
authored
[Usntructured loaders] Make Unstructured API URL optional when environment variable is present (#3414)
* Make Unstructured API URL optional when environment variable is present * Fix empty apiUrl option in Unsctructured flowise loader * Add focumentation for env vars
1 parent 15d59a9 commit a159da5

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# S3 File Loader
2+
3+
DS File Loarder integration for Flowise
4+
5+
## 🌱 Env Variables
6+
7+
| Variable | Description | Type | Default |
8+
| ---------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
9+
| UNSTRUCTURED_API_URL | Default `unstructuredApiUrl` for S3 File Loader | String | http://localhost:8000/general/v0/general |
10+
11+
## License
12+
13+
Source code in this repository is made available under the [Apache License Version 2.0](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md).

Diff for: packages/components/nodes/documentloaders/S3File/S3File.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class S3_DocumentLoaders implements INode {
7070
description:
7171
'Your Unstructured.io URL. Read <a target="_blank" href="https://unstructured-io.github.io/unstructured/introduction.html#getting-started">more</a> on how to get started',
7272
type: 'string',
73-
default: 'http://localhost:8000/general/v0/general'
73+
placeholder: process.env.UNSTRUCTURED_API_URL || 'http://localhost:8000/general/v0/general',
74+
optional: !!process.env.UNSTRUCTURED_API_URL
7475
},
7576
{
7677
label: 'Unstructured API KEY',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Unstructured File/Floder Loader
2+
3+
Unstructured File Loader integration for Flowise
4+
5+
## 🌱 Env Variables
6+
7+
| Variable | Description | Type | Default |
8+
| ---------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
9+
| UNSTRUCTURED_API_URL | Default `apiUrl` for Unstructured File/Floder Loader | String | http://localhost:8000/general/v0/general |
10+
11+
## License
12+
13+
Source code in this repository is made available under the [Apache License Version 2.0](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md).

Diff for: packages/components/nodes/documentloaders/Unstructured/Unstructured.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ type Element = {
2929
export class UnstructuredLoader extends BaseDocumentLoader {
3030
public filePath: string
3131

32-
private apiUrl = 'https://api.unstructuredapp.io/general/v0/general'
32+
private apiUrl = process.env.UNSTRUCTURED_API_URL || 'https://api.unstructuredapp.io/general/v0/general'
3333

34-
private apiKey?: string
34+
private apiKey: string | undefined = process.env.UNSTRUCTURED_API_KEY
3535

3636
private strategy: StringWithAutocomplete<UnstructuredLoaderStrategy> = 'hi_res'
3737

@@ -66,10 +66,10 @@ export class UnstructuredLoader extends BaseDocumentLoader {
6666

6767
const options = optionsOrLegacyFilePath
6868
this.apiKey = options.apiKey
69-
this.apiUrl = options.apiUrl ?? this.apiUrl
70-
this.strategy = options.strategy ?? this.strategy
69+
this.apiUrl = options.apiUrl || this.apiUrl
70+
this.strategy = options.strategy || this.strategy
7171
this.encoding = options.encoding
72-
this.ocrLanguages = options.ocrLanguages ?? this.ocrLanguages
72+
this.ocrLanguages = options.ocrLanguages || this.ocrLanguages
7373
this.coordinates = options.coordinates
7474
this.pdfInferTableStructure = options.pdfInferTableStructure
7575
this.xmlKeepTags = options.xmlKeepTags
@@ -128,7 +128,7 @@ export class UnstructuredLoader extends BaseDocumentLoader {
128128
}
129129

130130
const headers = {
131-
'UNSTRUCTURED-API-KEY': this.apiKey ?? ''
131+
'UNSTRUCTURED-API-KEY': this.apiKey || ''
132132
}
133133

134134
const response = await fetch(this.apiUrl, {

Diff for: packages/components/nodes/documentloaders/Unstructured/UnstructuredFile.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class UnstructuredFile_DocumentLoaders implements INode {
6363
description:
6464
'Unstructured API URL. Read <a target="_blank" href="https://docs.unstructured.io/api-reference/api-services/saas-api-development-guide">more</a> on how to get started',
6565
type: 'string',
66-
default: 'http://localhost:8000/general/v0/general'
66+
placeholder: process.env.UNSTRUCTURED_API_URL || 'http://localhost:8000/general/v0/general',
67+
optional: !!process.env.UNSTRUCTURED_API_URL
6768
},
6869
{
6970
label: 'Strategy',

Diff for: packages/components/nodes/documentloaders/Unstructured/UnstructuredFolder.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class UnstructuredFolder_DocumentLoaders implements INode {
5151
description:
5252
'Unstructured API URL. Read <a target="_blank" href="https://unstructured-io.github.io/unstructured/introduction.html#getting-started">more</a> on how to get started',
5353
type: 'string',
54-
default: 'http://localhost:8000/general/v0/general'
54+
placeholder: process.env.UNSTRUCTURED_API_URL || 'http://localhost:8000/general/v0/general',
55+
optional: !!process.env.UNSTRUCTURED_API_URL
5556
},
5657
{
5758
label: 'Strategy',

0 commit comments

Comments
 (0)