我目前正在 Node.js 项目中使用 LangChain 库,并尝试使用
langchain/document_loaders/fs/unstructured
模块中的 UnstructedLoader。这是我的代码片段:
import { UnstructuredLoader } from "langchain/document_loaders/fs/unstructured";
const options = {
apiKey: "MY_API_KEY",
};
const loader = new UnstructuredLoader(
"src/document_loaders/example_data/notion.md",
options
);
const docs = await loader.load();
我不确定
apiKey
的选项对象中是否需要 UnstructuredLoader
。有人可以澄清这应该是什么密钥以及我可以在哪里获得它吗?是浪链提供的特定API密钥,还是指外部服务API密钥,例如AWS或其他云提供商?
此外,如果此密钥正常工作需要任何特定的配置步骤或权限,我将不胜感激。
我传递 Open AI API 密钥时出错:
2023-12-06T11:21:21.704Z 65bd9f86-55cc-5ddf-9fb5-c26c0eac0992 ERROR Invoke Error {
"errorType": "Error",
"errorMessage": "Failed to partition file /tmp/README.md with error 401 and message {\"detail\":\"API key is malformed, please type the API key correctly in the header.\"}",
"stack": [
"Error: Failed to partition file /tmp/README.md with error 401 and message {\"detail\":\"API key is malformed, please type the API key correctly in the header.\"}",
" at UnstructuredLoader._partition (/var/task/node_modules/langchain/dist/document_loaders/fs/unstructured.cjs:189:19)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async UnstructuredLoader.load (/var/task/node_modules/langchain/dist/document_loaders/fs/unstructured.cjs:198:26)",
" at async processFile (/var/task/index.js:103:21)",
" at async Runtime.handler (/var/task/index.js:151:5)"
]
}
这是可选的。当您从 api 加载文档时会使用它。来自Python源代码:
def get_elements_from_api(
file_path: Union[str, List[str], None] = None,
file: Union[IO, Sequence[IO], None] = None,
api_url: str = "https://api.unstructured.io/general/v0/general",
api_key: str = "",
**unstructured_kwargs: Any,
) -> List:
"""Retrieves a list of elements from the Unstructured API."""
if isinstance(file, collections.abc.Sequence) or isinstance(file_path, list):
from unstructured.partition.api import partition_multiple_via_api
_doc_elements = partition_multiple_via_api(
filenames=file_path,
files=file,
api_key=api_key,
api_url=api_url,
**unstructured_kwargs,
)
elements = []
for _elements in _doc_elements:
elements.extend(_elements)
return elements
else:
from unstructured.partition.api import partition_via_api
return partition_via_api(
filename=file_path,
file=file,
api_key=api_key,
api_url=api_url,
**unstructured_kwargs,
)