Spaces:
Runtime error
Runtime error
feat: implementing basic tinydb in memory storage
Browse files- memory/controller.py +29 -0
- memory/db.json +0 -0
- requirements.txt +2 -1
memory/controller.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# minimal memory module for saving and loading converstations
|
| 2 |
+
|
| 3 |
+
# package imports
|
| 4 |
+
from tinydb import TinyDB, Query
|
| 5 |
+
from tinydb.storages import MemoryStorage
|
| 6 |
+
|
| 7 |
+
#temporary json db setup
|
| 8 |
+
db = TinyDB('db.json',storage=MemoryStorage)
|
| 9 |
+
query = Query()
|
| 10 |
+
|
| 11 |
+
def conversation_mapper(data):
|
| 12 |
+
mapping = {
|
| 13 |
+
{
|
| 14 |
+
'user': 'Hello, how are you?',
|
| 15 |
+
'bot': 'I am good, thank you.'
|
| 16 |
+
},
|
| 17 |
+
}
|
| 18 |
+
return mapping
|
| 19 |
+
|
| 20 |
+
# function to dump json data into the db
|
| 21 |
+
def dump (data):
|
| 22 |
+
mapping = conversation_mapper(data)
|
| 23 |
+
doc_id = db.insert(data)
|
| 24 |
+
return doc_id, mapping
|
| 25 |
+
|
| 26 |
+
# function to query data from the db
|
| 27 |
+
def get (doc_id:int):
|
| 28 |
+
data = db.get(doc_id=doc_id)
|
| 29 |
+
return data
|
memory/db.json
ADDED
|
File without changes
|
requirements.txt
CHANGED
|
@@ -6,4 +6,5 @@ accelerate~=0.24.1
|
|
| 6 |
markdown~=3.5.1
|
| 7 |
huggingface_hub~=0.19.4
|
| 8 |
fastapi~=0.104.1
|
| 9 |
-
uvicorn~=0.24.0
|
|
|
|
|
|
| 6 |
markdown~=3.5.1
|
| 7 |
huggingface_hub~=0.19.4
|
| 8 |
fastapi~=0.104.1
|
| 9 |
+
uvicorn~=0.24.0
|
| 10 |
+
tinydb~=4.8.0
|