[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
This commit is contained in:
Jérémy JOURDIN
2024-11-01 23:03:53 +01:00
committed by GitHub
parent 15d59a9052
commit a159da5bfe
6 changed files with 38 additions and 9 deletions
@@ -29,9 +29,9 @@ type Element = {
export class UnstructuredLoader extends BaseDocumentLoader {
public filePath: string
private apiUrl = 'https://api.unstructuredapp.io/general/v0/general'
private apiUrl = process.env.UNSTRUCTURED_API_URL || 'https://api.unstructuredapp.io/general/v0/general'
private apiKey?: string
private apiKey: string | undefined = process.env.UNSTRUCTURED_API_KEY
private strategy: StringWithAutocomplete<UnstructuredLoaderStrategy> = 'hi_res'
@@ -66,10 +66,10 @@ export class UnstructuredLoader extends BaseDocumentLoader {
const options = optionsOrLegacyFilePath
this.apiKey = options.apiKey
this.apiUrl = options.apiUrl ?? this.apiUrl
this.strategy = options.strategy ?? this.strategy
this.apiUrl = options.apiUrl || this.apiUrl
this.strategy = options.strategy || this.strategy
this.encoding = options.encoding
this.ocrLanguages = options.ocrLanguages ?? this.ocrLanguages
this.ocrLanguages = options.ocrLanguages || this.ocrLanguages
this.coordinates = options.coordinates
this.pdfInferTableStructure = options.pdfInferTableStructure
this.xmlKeepTags = options.xmlKeepTags
@@ -128,7 +128,7 @@ export class UnstructuredLoader extends BaseDocumentLoader {
}
const headers = {
'UNSTRUCTURED-API-KEY': this.apiKey ?? ''
'UNSTRUCTURED-API-KEY': this.apiKey || ''
}
const response = await fetch(this.apiUrl, {