Skip to content

Commit

Permalink
db schema verified and functional
Browse files Browse the repository at this point in the history
Signed-off-by: Rishi <[email protected]>
  • Loading branch information
rshrc committed Oct 18, 2023
1 parent 580cfea commit 6aec691
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,5 @@ tmp/*

utils/data.yaml
output.mp3
gconfig.json
gconfig.json
conversations.db
13 changes: 8 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import os
from typing import Any, Dict, NoReturn
from typing import Any, Dict, NoReturn, Union

import requests as r
import yaml

dir = os.getcwd()

def get_configuration(url, device_uuid):
url = f"{url}/api/j3devices/{device_uuid}/"
def get_configuration(url: str, device_uuid: Union[str, None]) -> Union[str, r.Response]:
if device_uuid is None:
return "No Device Set Yet!"

url = f"{url}api/j3devices/{device_uuid}/"
response = r.get(url)

return response
Expand All @@ -20,11 +23,11 @@ def generate_config(user_id: int) -> NoReturn:
}
}

with open(f"{dir}/utils/data.yaml", 'w') as file:
with open(f"{dir}/utilities/data.yaml", 'w') as file:
yaml.safe_dump(data, file, default_flow_style=False)

def read_config() -> Dict[str, Any]:
file: str = f'{dir}/utils/data.yaml'
file: str = f'{dir}/utilities/data.yaml'

with open(file, 'r') as f:
data: Dict[str, Any] = yaml.safe_load(f)
Expand Down
3 changes: 3 additions & 0 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
from sqlalchemy import Column, DateTime, Integer, String, create_engine, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from conversation import Base

engine = create_engine('sqlite:///conversations.db')
Base.metadata.create_all(engine)


Session = scoped_session(sessionmaker(bind=engine))

6 changes: 0 additions & 6 deletions dev

This file was deleted.

34 changes: 25 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import multiprocessing
import os
import sys

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = f"{os.getcwd()}/gconfig.json"

Expand All @@ -17,6 +18,9 @@
from icecream.icecream import IceCreamDebugger
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
# from conversation import store_data
from config import get_configuration
from utils import store_data, get_last_n

# from db.utils import get_data_in_date_range, get_last_n, store_data
from disply_lib import DisplayController
Expand Down Expand Up @@ -44,8 +48,19 @@
BASE_URL = os.getenv('BASE_URL')
WAKE_WORD = os.getenv('WAKE_WORD').lower()

test_device_uuid = "5caa2cef-3411-4368-9a6d-f9eefe9c34f9"


# Configure Device etc
# configuration = get_configuration()
configuration = get_configuration(BASE_URL, test_device_uuid)

if isinstance(configuration, str):
print(configuration)
elif isinstance(configuration, r.Response):
print(configuration.text)
else:
print("Unexpected type of configuration data.")


# Number of conversations that are kept track of, depend on get_configuration
MEMORY_CONTEXT = 5
Expand Down Expand Up @@ -89,14 +104,14 @@ def check_similar_song(user_input: str, directory_path: str):
def update_conversation(input, output):

# store in DB
# store_data(input, output)
pass
store_data(input, output)

# Single Operation Conversation
conversation.extend([
{'role': 'user', 'content': input},
{'role': 'assistant', 'content': output}
])
print("Conversation Updated")
# conversation.extend([
# {'role': 'user', 'content': input},
# {'role': 'assistant', 'content': output}
# ])
# print("Conversation Updated")


@timing
Expand Down Expand Up @@ -165,6 +180,7 @@ async def process_input(recognized_text):
print(data)

# not gonna take conversation, to reduce token utilization

if False and len(conversation) > 0:
data['conversation'] = json.dumps(conversation[:MEMORY_CONTEXT])

Expand All @@ -180,7 +196,7 @@ async def process_input(recognized_text):
# print(f"Response : {conversation}")
display_controller.render_text_threaded_v2(speech)
# await output_voice(speech)
tts.text_to_speech(speech, "output.mp3")
#tts.text_to_speech(speech, "output.mp3")


def voice_filler():
Expand Down
1 change: 0 additions & 1 deletion null

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions utilities/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
user:
id: 3
File renamed without changes.

0 comments on commit 6aec691

Please sign in to comment.