Skip to content

Commit

Permalink
feat: added upsert_chat function
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamMRS committed Oct 17, 2024
1 parent d3efeac commit fa14f37
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)

#
# Setup
#
print("J is booting up....")
check_folders() # Check directories are made for user data
read_chat("1")
Expand Down
20 changes: 16 additions & 4 deletions core/modules/chat.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import os
import json

def read_chat(id):
def read_chat(id: str) -> dict:
'''
Uses chat_id to get the entire chat JSON file
Uses chat_id to get the chat JSON file and returns a python dict object.
'''
dirname = os.path.dirname(os.path.dirname(__file__)) # Creates folder in core named user_data
filepath = os.path.join(dirname, f'user_data/chats/{id}.json')
# Open and read the JSON file
with open(filepath, 'r') as file:
data = json.load(file)
return data

# Print the data
print(data)
def upsert_chat(chat_object: dict):
'''
Upserts a chat dictionary object, saving it as json file in the user_data folder.
Upserting means to update or create if the file doesn't exist yet. Overwriting previous data.
'''
try:
print("hey")
except Exception as e:
return e


# json.dumps() - From python to json
# json.load() - From json to python
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ services:
llm-service:
build: ./core
restart: unless-stopped
env_file: .env
environment:
- FLASK_ENV=development # Autorestarts flask when code changes are detected
- OPENAI_API_KEY=${OPENAI_API_KEY}
- LANGSMITH_API_KEY=&{LANGSMITH_API_KEY}
- PORT=&{PORT}
volumes:
- ./core:/app # Mount the application code to detect live changes
networks:
Expand All @@ -13,6 +15,7 @@ services:
ports:
- "3000:3000"


networks:
backend:
driver: bridge

0 comments on commit fa14f37

Please sign in to comment.