-
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.
* add firestore_sdk ad session_manager * save user chats on firestore * pass down session_id for a deterministic workflow * handle conversion of chat object to/fro a dict * remove references to langchain * reuse a previously downloaded audiofile if it's processable * render audiocast metdata on share page * cleanup * temp remove audio_enchancement
- Loading branch information
1 parent
3973781
commit 82db371
Showing
16 changed files
with
322 additions
and
150 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
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,58 @@ | ||
import logging | ||
from typing import Dict, Literal | ||
|
||
from firebase_admin.firestore import client, firestore | ||
|
||
firestore_client = client() | ||
server_timestamp = firestore.SERVER_TIMESTAMP | ||
increment = firestore.Increment | ||
arrayUnion = firestore.ArrayUnion | ||
arrayRemove = firestore.ArrayRemove | ||
|
||
|
||
Collection = Literal["audiora_sessions", "audiora_audiocasts"] | ||
|
||
collections: Dict[Collection, Collection] = { | ||
"audiora_sessions": "audiora_sessions", | ||
"audiora_audiocasts": "audiora_audiocasts", | ||
} | ||
|
||
|
||
class DBManager: | ||
def __init__(self, scope: str): | ||
self.logger = logging.getLogger(scope) | ||
|
||
@property | ||
def timestamp(self): | ||
return server_timestamp | ||
|
||
def _get_collection(self, collection: Collection): | ||
return firestore_client.collection(collections[collection]) | ||
|
||
def _create_document(self, collection: Collection, data: Dict): | ||
return self._get_collection(collection).add( | ||
{**data, "created_at": self.timestamp, "updated_at": self.timestamp} | ||
) | ||
|
||
def _set_document(self, collection: Collection, doc_id: str, data: Dict): | ||
return ( | ||
self._get_collection(collection) | ||
.document(doc_id) | ||
.set({**data, "created_at": self.timestamp, "updated_at": self.timestamp}) | ||
) | ||
|
||
def _update_document(self, collection: Collection, doc_id: str, data: Dict): | ||
return ( | ||
self._get_collection(collection) | ||
.document(doc_id) | ||
.update({**data, "updated_at": self.timestamp}) | ||
) | ||
|
||
def _delete_document(self, collection: Collection, doc_id: str): | ||
return self._get_collection(collection).document(doc_id).delete() | ||
|
||
def _get_document(self, collection: Collection, doc_id: str): | ||
return self._get_collection(collection).document(doc_id).get() | ||
|
||
def _get_documents(self, collection: Collection): | ||
return self._get_collection(collection).stream() |
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
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
Oops, something went wrong.