forked from danswer-ai/danswer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from mindvalley/feat/add-at-connector
Adding support for AT connector
- Loading branch information
Showing
11 changed files
with
163 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
from typing import Any | ||
|
||
from danswer.configs.app_configs import INDEX_BATCH_SIZE | ||
from danswer.configs.constants import DocumentSource | ||
from danswer.connectors.interfaces import GenerateDocumentsOutput | ||
from danswer.connectors.interfaces import LoadConnector | ||
from danswer.connectors.interfaces import PollConnector | ||
from danswer.connectors.interfaces import SecondsSinceUnixEpoch | ||
from danswer.connectors.models import Document | ||
from danswer.connectors.models import Section | ||
from pyairtable import Api as AirtableApi | ||
|
||
|
||
class AirtableClientNotSetUpError(PermissionError): | ||
def __init__(self) -> None: | ||
super().__init__("Airtable Client is not set up, was load_credentials called?") | ||
|
||
|
||
class AirtableConnector(LoadConnector, PollConnector): | ||
def __init__( | ||
self, | ||
base_id: str, | ||
table_name_or_id: str, | ||
batch_size: int = INDEX_BATCH_SIZE, | ||
) -> None: | ||
self.base_id = base_id | ||
self.table_name_or_id = table_name_or_id | ||
self.batch_size = batch_size | ||
self.airtable_client: AirtableApi | None = None | ||
|
||
def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: | ||
self.airtable_client = AirtableApi(credentials["airtable_access_token"]) | ||
|
||
return None | ||
|
||
def poll_source( | ||
self, start: SecondsSinceUnixEpoch | None, end: SecondsSinceUnixEpoch | None | ||
) -> GenerateDocumentsOutput: | ||
if not self.airtable_client: | ||
raise AirtableClientNotSetUpError() | ||
|
||
table = self.airtable_client.table(self.base_id, self.table_name_or_id) | ||
all_records = table.all() | ||
|
||
record_documents = [] | ||
for record in all_records: | ||
record_document = Document( | ||
id=str(record.get("id")), | ||
sections=[ | ||
Section( | ||
link=f"https://airtable.com/{self.base_id}/{self.table_name_or_id}/", | ||
text=json.dumps(record.get("fields")), | ||
) | ||
], | ||
source=DocumentSource.AIRTABLE, | ||
semantic_identifier=f"Airtable Base ID: {self.base_id}. Table Name or ID: {self.table_name_or_id}", | ||
metadata={ | ||
"type": "airtable", | ||
"created_time": record.get("createdTime"), | ||
}, | ||
) | ||
record_documents.append(record_document) | ||
|
||
yield record_documents | ||
|
||
def load_from_state(self) -> GenerateDocumentsOutput: | ||
if not self.airtable_client: | ||
raise AirtableClientNotSetUpError() | ||
return self.poll_source(None, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,4 @@ zenpy==2.0.41 | |
dropbox==11.36.2 | ||
boto3-stubs[s3]==1.34.133 | ||
ultimate_sitemap_parser==0.5 | ||
pyairtable==3.0.0a3 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,6 +212,7 @@ export interface UserGroup { | |
} | ||
|
||
const validSources = [ | ||
"airtable", | ||
"web", | ||
"github", | ||
"gitlab", | ||
|