-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Telegram and Text Files connectors #20
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from abc import ABC | ||
from typing import Any, List | ||
|
||
from selfie.connectors.base_connector import BaseConnector | ||
from selfie.database import BaseModel | ||
from selfie.embeddings import EmbeddingDocumentModel, DataIndex | ||
from selfie.parsers.chat import ChatFileParser | ||
from selfie.types.documents import DocumentDTO | ||
from selfie.utils import data_uri_to_string | ||
|
||
|
||
class GoogleMessagesConfiguration(BaseModel): | ||
files: List[str] | ||
|
||
|
||
class GoogleMessagesConnector(BaseConnector, ABC): | ||
def __init__(self): | ||
super().__init__() | ||
self.id = "google_messages" | ||
self.name = "Google Messages" | ||
|
||
def load_document(self, configuration: dict[str, Any]) -> List[DocumentDTO]: | ||
config = GoogleMessagesConfiguration(**configuration) | ||
|
||
return [ | ||
DocumentDTO( | ||
content=data_uri_to_string(data_uri), | ||
content_type="text/plain", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be application/json?
tnunamak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name="todo", | ||
size=len(data_uri_to_string(data_uri).encode('utf-8')) | ||
) | ||
for data_uri in config.files | ||
] | ||
|
||
def validate_configuration(self, configuration: dict[str, Any]): | ||
# TODO: check if file can be read from path | ||
pass | ||
|
||
def transform_for_embedding(self, configuration: dict[str, Any], documents: List[DocumentDTO]) -> List[EmbeddingDocumentModel]: | ||
return [ | ||
embeddingDocumentModel | ||
for document in documents | ||
for embeddingDocumentModel in DataIndex.map_share_gpt_data( | ||
ChatFileParser().parse_document( | ||
document=document.content, | ||
parser_type="google_messages", | ||
mask=False, | ||
document_name=document.name, | ||
).conversations, | ||
source="google_messages", | ||
source_document_id=document.id | ||
) | ||
] |
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,9 @@ | ||
## Export Instructions | ||
|
||
Google Takeout is a service that allows you to download a copy of your data stored within Google products. To export your Google Hangouts chat history, follow the instructions below. | ||
|
||
1. Go to <a href="https://takeout.google.com" target="_blank">Google Takeout</a> and log in to your Google account. | ||
2. Select "Deselect all" and then scroll down to select "Messages" from the list of Google products. (note: `Messages` may not appear in the list if you have not used Google Messages in the past) | ||
3. Click "Next step" and choose your delivery method, frequency, and file type. | ||
4. Click "Create export" to start the process. Once completed, you will receive an email with a link to download your exported data. | ||
5. Download the .zip file and extract the `.json` files in the `Messages` folder to access your chat files. |
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,14 @@ | ||
{ | ||
"title": "Upload Google Messages Conversations", | ||
"type": "object", | ||
"properties": { | ||
"files": { | ||
"type": "array", | ||
"title": "Files", | ||
"description": "Upload .json files exported from Google Messages", | ||
"items": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"files": { | ||
"ui:widget": "nativeFile", | ||
"ui:options": { | ||
"accept": ".json" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this on the roadmap? I thought we were going with the approach of "one connector for each data source" vs "support all llamahub loaders", because the E2E flow for each connector varies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a general-purpose LlamaHub loader should be possible, probably with some limitations (some loaders need additional python dependencies), but I've removed it until we can clarify further.