Spaces:
Sleeping
Sleeping
Vela
commited on
Commit
Β·
0e43e5f
1
Parent(s):
d48dc2f
updated supabase files
Browse files- src/backend/api_routes/__pycache__/chat_history_db_api.cpython-313.pyc +0 -0
- src/backend/api_routes/chat_history_db_api.py +16 -1
- src/backend/services/__pycache__/supabase_service.cpython-313.pyc +0 -0
- src/backend/services/supabase_service.py +15 -26
- src/frontend/app/__pycache__/common_functions.cpython-313.pyc +0 -0
- src/frontend/app/__pycache__/pinecone_data_handler.cpython-313.pyc +0 -0
- src/frontend/app/common_functions.py +29 -1
- src/frontend/app/pinecone_data_handler.py +1 -1
- src/frontend/home.py +2 -6
- src/frontend/pages/chatbot.py +8 -6
src/backend/api_routes/__pycache__/chat_history_db_api.cpython-313.pyc
CHANGED
Binary files a/src/backend/api_routes/__pycache__/chat_history_db_api.cpython-313.pyc and b/src/backend/api_routes/__pycache__/chat_history_db_api.cpython-313.pyc differ
|
|
src/backend/api_routes/chat_history_db_api.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from fastapi import APIRouter
|
2 |
from services.schemas import ChatHistoryRequest
|
3 |
from services import supabase_service
|
4 |
from utils import logger
|
@@ -16,5 +16,20 @@ def store_chat_history(chat_history : ChatHistoryRequest):
|
|
16 |
except Exception as e:
|
17 |
raise f"Failed to create {e}"
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
|
|
|
1 |
+
from fastapi import APIRouter,HTTPException,status
|
2 |
from services.schemas import ChatHistoryRequest
|
3 |
from services import supabase_service
|
4 |
from utils import logger
|
|
|
16 |
except Exception as e:
|
17 |
raise f"Failed to create {e}"
|
18 |
|
19 |
+
@router.get('/get-history')
|
20 |
+
def get_chat_history(conversation_id: str):
|
21 |
+
try:
|
22 |
+
chat_history = supabase_service.get_chat_history(conversation_id)
|
23 |
+
logger.info(f"Chat history retrieved successfully for conversation ID: {conversation_id}")
|
24 |
+
return chat_history
|
25 |
+
except Exception as e:
|
26 |
+
logger.error(f"Error retrieving chat history for ID {conversation_id}: {e}")
|
27 |
+
raise HTTPException(
|
28 |
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
29 |
+
detail="Failed to retrieve chat history. Please try again later."
|
30 |
+
)
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
|
35 |
|
src/backend/services/__pycache__/supabase_service.cpython-313.pyc
CHANGED
Binary files a/src/backend/services/__pycache__/supabase_service.cpython-313.pyc and b/src/backend/services/__pycache__/supabase_service.cpython-313.pyc differ
|
|
src/backend/services/supabase_service.py
CHANGED
@@ -52,37 +52,26 @@ def store_chat_history(conversation_id, new_messages):
|
|
52 |
logger.error(f"Error: {e}")
|
53 |
return {"error": str(e)}
|
54 |
|
55 |
-
def get_chat_history(
|
56 |
try:
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
66 |
|
67 |
-
return chat_history
|
68 |
except Exception as e:
|
69 |
logger.error(f"Error retrieving chat history: {e}")
|
70 |
-
return
|
71 |
|
72 |
-
def create_bucket_with_file():
|
73 |
-
bucket_name = "chat-history"
|
74 |
try:
|
75 |
supabase.storage.create_bucket(bucket_name)
|
76 |
-
|
77 |
except Exception as e:
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
conversation_id = "12345"
|
83 |
-
messages = [
|
84 |
-
{"role": "system", "content": "Hello Friend."},
|
85 |
-
]
|
86 |
-
|
87 |
-
|
88 |
-
# store_chat_history(conversation_id,messages)
|
|
|
52 |
logger.error(f"Error: {e}")
|
53 |
return {"error": str(e)}
|
54 |
|
55 |
+
def get_chat_history(conversation_id):
|
56 |
try:
|
57 |
+
file_path = f"chat-history/{conversation_id}.json"
|
58 |
+
existing_data = supabase.storage.from_(SUPABASE_BUCKET).download(file_path)
|
59 |
+
|
60 |
+
if existing_data:
|
61 |
+
chat_data = json.loads(existing_data.decode('utf-8'))
|
62 |
+
logger.info("Chat history retrieved successfully!")
|
63 |
+
return chat_data
|
64 |
+
else:
|
65 |
+
logger.warning("No chat history found for the given conversation ID.")
|
66 |
+
return {"message": "No chat history found."}
|
67 |
|
|
|
68 |
except Exception as e:
|
69 |
logger.error(f"Error retrieving chat history: {e}")
|
70 |
+
return {"error": str(e)}
|
71 |
|
72 |
+
def create_bucket_with_file(bucket_name:str):
|
|
|
73 |
try:
|
74 |
supabase.storage.create_bucket(bucket_name)
|
75 |
+
logger.info(f"Bucket '{bucket_name}' created successfully.")
|
76 |
except Exception as e:
|
77 |
+
logger.error(f"Error creating bucket: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/frontend/app/__pycache__/common_functions.cpython-313.pyc
CHANGED
Binary files a/src/frontend/app/__pycache__/common_functions.cpython-313.pyc and b/src/frontend/app/__pycache__/common_functions.cpython-313.pyc differ
|
|
src/frontend/app/__pycache__/pinecone_data_handler.cpython-313.pyc
CHANGED
Binary files a/src/frontend/app/__pycache__/pinecone_data_handler.cpython-313.pyc and b/src/frontend/app/__pycache__/pinecone_data_handler.cpython-313.pyc differ
|
|
src/frontend/app/common_functions.py
CHANGED
@@ -140,4 +140,32 @@ def store_chat_history_in_db(conversation_id, messages):
|
|
140 |
response = requests.post(API_URL, json=payload)
|
141 |
logger.info("Successfully added the chat in db")
|
142 |
except Exception as e:
|
143 |
-
logger.info(f"Failed to add the chat in db {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
response = requests.post(API_URL, json=payload)
|
141 |
logger.info("Successfully added the chat in db")
|
142 |
except Exception as e:
|
143 |
+
logger.info(f"Failed to add the chat in db {e}")
|
144 |
+
|
145 |
+
def get_chat_history_from_db(conversation_id):
|
146 |
+
try:
|
147 |
+
API_URL = f"http://127.0.0.1:8000/chat-db/get-history"
|
148 |
+
response = requests.post(API_URL,params={"conversation_id": conversation_id})
|
149 |
+
response.raise_for_status()
|
150 |
+
logger.info(f"Successfully retrieved chat history for conversation ID: {conversation_id}")
|
151 |
+
return response.json()
|
152 |
+
except Exception as e:
|
153 |
+
logger.info(f"Failed to get the chat history")
|
154 |
+
return {"error": "Failed to retrieve chat history. Please try again later."}
|
155 |
+
|
156 |
+
def display_chat_history(st):
|
157 |
+
conversation_id = st.session_state.get("conversation_id")
|
158 |
+
if not conversation_id:
|
159 |
+
st.warning("Conversation ID is missing. Please provide a valid ID.")
|
160 |
+
return
|
161 |
+
|
162 |
+
try:
|
163 |
+
chat_history = get_chat_history_from_db(conversation_id)
|
164 |
+
if chat_history and isinstance(chat_history, dict) and 'error' not in chat_history:
|
165 |
+
st.success("Chat history loaded successfully!")
|
166 |
+
if st.sidebar.button(f"Show History for {conversation_id}",key="show_history_button"):
|
167 |
+
st.json(chat_history)
|
168 |
+
else:
|
169 |
+
st.info("No chat history found for this conversation ID or the data format is incorrect.")
|
170 |
+
except Exception as e:
|
171 |
+
st.error(f"Error retrieving chat history: {e}")
|
src/frontend/app/pinecone_data_handler.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import requests
|
2 |
-
from
|
3 |
import streamlit as st
|
4 |
|
5 |
|
|
|
1 |
import requests
|
2 |
+
from app import common_functions
|
3 |
import streamlit as st
|
4 |
|
5 |
|
src/frontend/home.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
from PIL import Image
|
4 |
|
5 |
def render_homepage():
|
@@ -7,6 +7,7 @@ def render_homepage():
|
|
7 |
|
8 |
# Page Configuration
|
9 |
common_functions.config_homepage(st)
|
|
|
10 |
common_functions.set_page_title(st)
|
11 |
|
12 |
|
@@ -21,11 +22,6 @@ def render_homepage():
|
|
21 |
)
|
22 |
|
23 |
with Home:
|
24 |
-
# st.markdown("### π Getting Started")
|
25 |
-
# st.markdown("""
|
26 |
-
# - Select **Admin Portal** for system configurations and data management.
|
27 |
-
# - Go to **Knowledge Base Explorer** to explore and manage knowledge entries.
|
28 |
-
# """)
|
29 |
st.markdown("""
|
30 |
### π Welcome to the Yuvabe Care Companion AI!
|
31 |
This platform offers comprehensive tools to support your healthcare journey. Use the tabs above to navigate:
|
|
|
1 |
import streamlit as st
|
2 |
+
from app import common_functions
|
3 |
from PIL import Image
|
4 |
|
5 |
def render_homepage():
|
|
|
7 |
|
8 |
# Page Configuration
|
9 |
common_functions.config_homepage(st)
|
10 |
+
|
11 |
common_functions.set_page_title(st)
|
12 |
|
13 |
|
|
|
22 |
)
|
23 |
|
24 |
with Home:
|
|
|
|
|
|
|
|
|
|
|
25 |
st.markdown("""
|
26 |
### π Welcome to the Yuvabe Care Companion AI!
|
27 |
This platform offers comprehensive tools to support your healthcare journey. Use the tabs above to navigate:
|
src/frontend/pages/chatbot.py
CHANGED
@@ -29,12 +29,12 @@ def fetch_health_advice(conversation_history):
|
|
29 |
if "conversation_history" not in st.session_state:
|
30 |
st.session_state.conversation_history = initialize_conversation()
|
31 |
|
32 |
-
# Display chat history
|
33 |
-
for message in st.session_state.conversation_history [-NUMBER_OF_MESSAGES_TO_DISPLAY:]:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
# User Input
|
40 |
user_input = st.chat_input("Ask your health-related question:")
|
@@ -60,6 +60,8 @@ if user_input:
|
|
60 |
# Append assistant's reply to conversation history first
|
61 |
st.session_state.conversation_history.append({"role": "assistant", "content": assistant_reply})
|
62 |
common_functions.store_chat_history_in_db(st.session_state.conversation_id,st.session_state.conversation_history)
|
|
|
|
|
63 |
|
64 |
# Display only the assistant's latest response
|
65 |
with st.chat_message('assistant'):
|
|
|
29 |
if "conversation_history" not in st.session_state:
|
30 |
st.session_state.conversation_history = initialize_conversation()
|
31 |
|
32 |
+
# # Display chat history
|
33 |
+
# for message in st.session_state.conversation_history [-NUMBER_OF_MESSAGES_TO_DISPLAY:]:
|
34 |
+
# role = message["role"]
|
35 |
+
# avatar_image = "src/frontend/images/page_icon.jpg" if role == "assistant" else "src/frontend/images/page_icon.jpg" if role == "user" else None
|
36 |
+
# with st.chat_message(role, avatar=avatar_image):
|
37 |
+
# st.write(message["content"])
|
38 |
|
39 |
# User Input
|
40 |
user_input = st.chat_input("Ask your health-related question:")
|
|
|
60 |
# Append assistant's reply to conversation history first
|
61 |
st.session_state.conversation_history.append({"role": "assistant", "content": assistant_reply})
|
62 |
common_functions.store_chat_history_in_db(st.session_state.conversation_id,st.session_state.conversation_history)
|
63 |
+
common_functions.display_chat_history(st)
|
64 |
+
|
65 |
|
66 |
# Display only the assistant's latest response
|
67 |
with st.chat_message('assistant'):
|