Spaces:
Sleeping
Sleeping
refactor
Browse files- app.py +11 -13
- model_params.cfg +2 -1
app.py
CHANGED
|
@@ -17,6 +17,7 @@ from dotenv import load_dotenv
|
|
| 17 |
from threading import Lock
|
| 18 |
from gradio.routes import Request
|
| 19 |
from qdrant_client import QdrantClient
|
|
|
|
| 20 |
|
| 21 |
# TESTING DEBUG LOG
|
| 22 |
from auditqa.logging_config import setup_logging
|
|
@@ -44,7 +45,7 @@ scheduler = CommitScheduler(
|
|
| 44 |
repo_id=model_config.get('app','repo_id'),
|
| 45 |
repo_type="dataset",
|
| 46 |
folder_path=JSON_DATASET_DIR,
|
| 47 |
-
path_in_repo=
|
| 48 |
token=SPACES_LOG,
|
| 49 |
every=2) # TESTING: every 2 seconds
|
| 50 |
|
|
@@ -145,10 +146,6 @@ session_manager = SessionManager()
|
|
| 145 |
|
| 146 |
async def chat(query, history, sources, reports, subtype, year, client_ip=None, session_id=None):
|
| 147 |
"""Update chat function to handle session data"""
|
| 148 |
-
# TESTING: DEBUG LOG
|
| 149 |
-
logger.debug(f"Chat function called with query: {query}")
|
| 150 |
-
logger.debug(f"Client IP: {client_ip}")
|
| 151 |
-
logger.debug(f"Session ID: {session_id}")
|
| 152 |
|
| 153 |
if not session_id: # Session managment
|
| 154 |
session_id = session_manager.create_session(client_ip)
|
|
@@ -160,7 +157,7 @@ async def chat(query, history, sources, reports, subtype, year, client_ip=None,
|
|
| 160 |
# Get session data
|
| 161 |
session_data = session_manager.get_session_data(session_id)
|
| 162 |
session_duration = session_manager.get_session_duration(session_id)
|
| 163 |
-
logger.debug(f"Session duration: {session_duration}")
|
| 164 |
|
| 165 |
print(f">> NEW QUESTION : {query}")
|
| 166 |
print(f"history:{history}")
|
|
@@ -220,22 +217,22 @@ async def chat(query, history, sources, reports, subtype, year, client_ip=None,
|
|
| 220 |
timestamp = str(datetime.now().timestamp())
|
| 221 |
logs_data = {
|
| 222 |
"session_id": session_id,
|
| 223 |
-
"client_ip": client_ip,
|
| 224 |
"client_location": session_data['location_info'],
|
| 225 |
"session_duration_seconds": session_duration,
|
| 226 |
-
# "system_prompt": SYSTEM_PROMPT,
|
| 227 |
-
# "sources": sources,
|
| 228 |
-
# "reports": reports,
|
| 229 |
-
# "subtype": subtype,
|
| 230 |
"year": year,
|
| 231 |
"question": query,
|
| 232 |
"retriever": model_config.get('retriever','MODEL'),
|
| 233 |
"endpoint_type": model_config.get('reader','TYPE'),
|
| 234 |
"reader": model_config.get('reader','NVIDIA_MODEL'),
|
| 235 |
-
# "docs": [doc.page_content for doc in context_retrieved],
|
| 236 |
"answer": "",
|
| 237 |
"time": timestamp,
|
| 238 |
}
|
|
|
|
| 239 |
|
| 240 |
if model_config.get('reader','TYPE') == 'NVIDIA':
|
| 241 |
chat_model = nvidia_client()
|
|
@@ -303,8 +300,9 @@ async def chat(query, history, sources, reports, subtype, year, client_ip=None,
|
|
| 303 |
try:
|
| 304 |
# Save log after streaming is complete
|
| 305 |
save_logs(scheduler, JSON_DATASET_PATH, logs_data)
|
|
|
|
| 306 |
except Exception as e:
|
| 307 |
-
|
| 308 |
|
| 309 |
|
| 310 |
|
|
|
|
| 17 |
from threading import Lock
|
| 18 |
from gradio.routes import Request
|
| 19 |
from qdrant_client import QdrantClient
|
| 20 |
+
import json
|
| 21 |
|
| 22 |
# TESTING DEBUG LOG
|
| 23 |
from auditqa.logging_config import setup_logging
|
|
|
|
| 45 |
repo_id=model_config.get('app','repo_id'),
|
| 46 |
repo_type="dataset",
|
| 47 |
folder_path=JSON_DATASET_DIR,
|
| 48 |
+
path_in_repo=model_config.get('app','path_in_repo'),
|
| 49 |
token=SPACES_LOG,
|
| 50 |
every=2) # TESTING: every 2 seconds
|
| 51 |
|
|
|
|
| 146 |
|
| 147 |
async def chat(query, history, sources, reports, subtype, year, client_ip=None, session_id=None):
|
| 148 |
"""Update chat function to handle session data"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
if not session_id: # Session managment
|
| 151 |
session_id = session_manager.create_session(client_ip)
|
|
|
|
| 157 |
# Get session data
|
| 158 |
session_data = session_manager.get_session_data(session_id)
|
| 159 |
session_duration = session_manager.get_session_duration(session_id)
|
| 160 |
+
logger.debug(f"Session duration calculated: {session_duration}")
|
| 161 |
|
| 162 |
print(f">> NEW QUESTION : {query}")
|
| 163 |
print(f"history:{history}")
|
|
|
|
| 217 |
timestamp = str(datetime.now().timestamp())
|
| 218 |
logs_data = {
|
| 219 |
"session_id": session_id,
|
|
|
|
| 220 |
"client_location": session_data['location_info'],
|
| 221 |
"session_duration_seconds": session_duration,
|
| 222 |
+
# "system_prompt": SYSTEM_PROMPT, #REMOVED FOR TESTING
|
| 223 |
+
# "sources": sources, #REMOVED FOR TESTING
|
| 224 |
+
# "reports": reports, #REMOVED FOR TESTING
|
| 225 |
+
# "subtype": subtype, #REMOVED FOR TESTING
|
| 226 |
"year": year,
|
| 227 |
"question": query,
|
| 228 |
"retriever": model_config.get('retriever','MODEL'),
|
| 229 |
"endpoint_type": model_config.get('reader','TYPE'),
|
| 230 |
"reader": model_config.get('reader','NVIDIA_MODEL'),
|
| 231 |
+
# "docs": [doc.page_content for doc in context_retrieved], #REMOVED FOR TESTING
|
| 232 |
"answer": "",
|
| 233 |
"time": timestamp,
|
| 234 |
}
|
| 235 |
+
logger.debug(f"Logs data before save: {json.dumps(logs_data, indent=2)}")
|
| 236 |
|
| 237 |
if model_config.get('reader','TYPE') == 'NVIDIA':
|
| 238 |
chat_model = nvidia_client()
|
|
|
|
| 300 |
try:
|
| 301 |
# Save log after streaming is complete
|
| 302 |
save_logs(scheduler, JSON_DATASET_PATH, logs_data)
|
| 303 |
+
logger.debug(f"Logs saved successfully")
|
| 304 |
except Exception as e:
|
| 305 |
+
logger.error(f"Error saving logs: {str(e)}")
|
| 306 |
|
| 307 |
|
| 308 |
|
model_params.cfg
CHANGED
|
@@ -13,4 +13,5 @@ NVIDIA_MODEL = meta-llama/Llama-3.1-8B-Instruct
|
|
| 13 |
NVIDIA_ENDPOINT = https://huggingface.co/api/integrations/dgx/v1
|
| 14 |
MAX_TOKENS = 512
|
| 15 |
[app]
|
| 16 |
-
repo_id = mtyrrell/audit_chatbot
|
|
|
|
|
|
| 13 |
NVIDIA_ENDPOINT = https://huggingface.co/api/integrations/dgx/v1
|
| 14 |
MAX_TOKENS = 512
|
| 15 |
[app]
|
| 16 |
+
repo_id = mtyrrell/audit_chatbot #GIZ/spaces_log
|
| 17 |
+
path_in_repo = . # audit_chatbot
|