import re import logging import json from langchain.schema import ( HumanMessage, SystemMessage, ) import requests from datetime import datetime from uuid import uuid4 # TESTING DEBUG LOG from auditqa.logging_config import setup_logging setup_logging() import logging logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) # Ensure debug logging is enabled # def save_logs(scheduler, JSON_DATASET_PATH, logs, feedback=None) -> None: # """ Every interaction with app saves the log of question and answer, # this is to get the usage statistics of app and evaluate model performances. # Also saves user feedback (when provided). # """ # if feedback: # logs["feedback"] = feedback #optional # with scheduler.lock: # with open(JSON_DATASET_PATH, 'a') as f: # json.dump(logs, f) # f.write("\n") # print("logging done") import os from pathlib import Path def save_logs(JSON_DATASET_PATH: str, logs: dict, feedback: str = None) -> None: """ Every interaction with app saves the log of question and answer, this is to get the usage statistics of app and evaluate model performances. Also saves user feedback (when provided). """ try: # Create directory if it doesn't exist os.makedirs(os.path.dirname(JSON_DATASET_PATH), exist_ok=True) if feedback: logs["feedback"] = feedback logger.debug(f"Adding feedback to logs: {feedback}") with open(JSON_DATASET_PATH, 'a') as f: json.dump(logs, f) f.write("\n") logger.info(f"Successfully saved logs to {JSON_DATASET_PATH}") except Exception as e: logger.error(f"Failed to save logs to {JSON_DATASET_PATH}: {str(e)}") raise def get_message_template(type, SYSTEM_PROMPT, USER_PROMPT): if type == 'NVIDIA': messages = [{"role": "system", "content": SYSTEM_PROMPT}, {"role":"user","content":USER_PROMPT}] elif type == 'DEDICATED': messages = [ SystemMessage(content=SYSTEM_PROMPT), HumanMessage(content=USER_PROMPT),] else: messages = None return messages def make_html_source(source,i): """ takes the text and converts it into html format for display in "source" side tab """ meta = source.metadata content = source.page_content.strip() name = meta['subtype'] card = f"""
{content}