|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
"""Notion DB loader for langchain"""
|
|
|
|
|
|
|
|
|
|
from typing import Any, Dict, List
|
|
|
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
@ -19,9 +19,15 @@ class NotionDBLoader(BaseLoader):
|
|
|
|
|
Args:
|
|
|
|
|
integration_token (str): Notion integration token.
|
|
|
|
|
database_id (str): Notion database id.
|
|
|
|
|
request_timeout_sec (int): Timeout for Notion requests in seconds.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, integration_token: str, database_id: str) -> None:
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
integration_token: str,
|
|
|
|
|
database_id: str,
|
|
|
|
|
request_timeout_sec: Optional[int] = 10,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Initialize with parameters."""
|
|
|
|
|
if not integration_token:
|
|
|
|
|
raise ValueError("integration_token must be provided")
|
|
|
|
@ -35,6 +41,7 @@ class NotionDBLoader(BaseLoader):
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"Notion-Version": "2022-06-28",
|
|
|
|
|
}
|
|
|
|
|
self.request_timeout_sec = request_timeout_sec
|
|
|
|
|
|
|
|
|
|
def load(self) -> List[Document]:
|
|
|
|
|
"""Load documents from the Notion database.
|
|
|
|
@ -148,7 +155,7 @@ class NotionDBLoader(BaseLoader):
|
|
|
|
|
url,
|
|
|
|
|
headers=self.headers,
|
|
|
|
|
json=query_dict,
|
|
|
|
|
timeout=10,
|
|
|
|
|
timeout=self.request_timeout_sec,
|
|
|
|
|
)
|
|
|
|
|
res.raise_for_status()
|
|
|
|
|
return res.json()
|
|
|
|
|