forked from vana-com/personal-server
-
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.
feat: Telegram and Text Files connectors (vana-com#20)
- Loading branch information
Showing
21 changed files
with
354 additions
and
53 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
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="application/json", | ||
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.