Skip to content

Commit

Permalink
feat: Create file management for user_data
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamMRS committed Oct 17, 2024
1 parent c906612 commit d3efeac
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 129 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Custom Ignores
user_data


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
118 changes: 0 additions & 118 deletions core/agent.py

This file was deleted.

2 changes: 1 addition & 1 deletion core/ai_message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Ai_message:
def __init__(self, message:str, token_count:int) -> None:
self.message = message
self.token_count = token_count
self.token_count = token_count
2 changes: 1 addition & 1 deletion core/graphAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import json
from config import OPENAI_API_KEY
from Agents.simpleagent import SimpleAgent
from agent import Agent, Agent1
#from agent import Agent, Agent1
import asyncio
from time import sleep

Expand Down
2 changes: 1 addition & 1 deletion core/graphtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AgentState(TypedDict):
messages: Annotated[Sequence[BaseMessage], operator.add]
sender: str

class gaphtool:
class graphtool:
def __init__(self, graph):
self.graph = graph
self.nodes = graph.nodes()
Expand Down
17 changes: 13 additions & 4 deletions core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
from flask_cors import CORS
from config import PORT
import asyncio
from modules.user_data_setup import check_folders
from modules.chat import read_chat
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)

print("J is booting up....")
check_folders() # Check directories are made for user data
read_chat("1")

#
# Server config
Expand Down Expand Up @@ -42,8 +51,6 @@ def summarize_store():

return {"status": "success", "summary": summary}



#
#
# Socket.IO events below
Expand All @@ -68,10 +75,12 @@ def handle_prompt(data):
socketio.emit("start_message")
asyncio.run(jarvis.run(data['prompt'], socketio), debug=True) # prompts Jarvis and hands off emitting to the graphAgent.

return jsonify({"status": response})
return jsonify({"status": "success"})
except Exception as e:
print(f'Something very bad happened: {e}')
return jsonify({"status": "error"})

if __name__ == '__main__':
socketio.run(app, debug=True, host='0.0.0.0', port=PORT, allow_unsafe_werkzeug=True)
socketio.run(app, debug=True, host='0.0.0.0', port=PORT, allow_unsafe_werkzeug=True)

# hello
15 changes: 15 additions & 0 deletions core/modules/chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import json

def read_chat(id):
'''
Uses chat_id to get the entire chat JSON file
'''
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)

# Print the data
print(data)
18 changes: 18 additions & 0 deletions core/modules/user_data_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

def check_folders():
main_folder = "user_data/"
pathsToCheck = ["chats", "images", "pdfs", "fbx"]
for directory in pathsToCheck:
path = main_folder + directory # creates path user_data/chats for example. Everything should be under user_data as its gitignored.
check_and_create_folder(path) # Does a relative folder check, and builds the directory if it doesn't exist

def check_and_create_folder(path):
dirname = os.path.dirname(os.path.dirname(__file__)) # Creates folder in core named user_data
relativedir = os.path.join(dirname, path)
if not os.path.exists(relativedir):
try:
print("Created user_data director under core folder. This is first-time setup.")
os.makedirs(path)
except Exception as e:
print(e)
5 changes: 1 addition & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ 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 @@ -15,7 +13,6 @@ services:
ports:
- "3000:3000"


networks:
backend:
driver: bridge

0 comments on commit d3efeac

Please sign in to comment.