Daemontatox commited on
Commit
f94101f
·
verified ·
1 Parent(s): ed50ba3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -54,10 +54,20 @@ class ChatHistory:
54
 
55
  # Function to log questions and answers to a file
56
  def log_to_file(question: str, answer: str):
57
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
58
- log_entry = f"Timestamp: {timestamp}\nQuestion: {question}\nAnswer: {answer}\n\n"
59
- with open("Logs.txt", "a") as log_file:
60
- log_file.write(log_entry)
 
 
 
 
 
 
 
 
 
 
61
 
62
  # Load environment variables and setup
63
  load_dotenv()
@@ -110,7 +120,7 @@ retriever = db.as_retriever(
110
 
111
  llm = ChatGoogleGenerativeAI(
112
  model="gemini-2.0-flash-thinking-exp-01-21",
113
- temperature=0,
114
  max_tokens=None,
115
  timeout=None,
116
  max_retries=2,
@@ -186,8 +196,8 @@ Critical Constraints
186
 
187
  - Strict Context Reliance: Base all responses solely on the provided context and chat history.
188
  - Non-Mawared HR Queries: Politely decline to answer questions unrelated to Mawared HR.
189
- - Answer Format: Always provide accurate answers in numbered steps without revealing your thought process or using code.
190
-
191
  ---
192
 
193
  By adhering to these principles and guidelines, ensure every response is accurate, professional, and easy to follow.
@@ -268,6 +278,7 @@ def ask_question_gradio(question: str, history: List[List[str]]) -> Generator[tu
268
  chat_history.add_message("assistant", response)
269
 
270
  # Log the question and answer to a file
 
271
  log_to_file(question, response)
272
 
273
  except Exception as e:
 
54
 
55
  # Function to log questions and answers to a file
56
  def log_to_file(question: str, answer: str):
57
+ """Logs the question and answer to a file with a timestamp."""
58
+ try:
59
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
60
+ log_entry = f"Timestamp: {timestamp}\nQuestion: {question}\nAnswer: {answer}\n\n"
61
+
62
+ # Debugging: Print the log entry to verify its content
63
+ logger.info(f"Log Entry: {log_entry}")
64
+
65
+ # Open the file in append mode and write the log entry
66
+ with open("Logs.txt", "a") as log_file:
67
+ log_file.write(log_entry)
68
+ logger.info("Successfully wrote to Logs.txt")
69
+ except Exception as e:
70
+ logger.error(f"Failed to write to Logs.txt: {e}")
71
 
72
  # Load environment variables and setup
73
  load_dotenv()
 
120
 
121
  llm = ChatGoogleGenerativeAI(
122
  model="gemini-2.0-flash-thinking-exp-01-21",
123
+ temperature=0.2,
124
  max_tokens=None,
125
  timeout=None,
126
  max_retries=2,
 
196
 
197
  - Strict Context Reliance: Base all responses solely on the provided context and chat history.
198
  - Non-Mawared HR Queries: Politely decline to answer questions unrelated to Mawared HR.
199
+ - Answer Format: Always provide accurate answers in numbered steps without using code.
200
+ - Use Tags like <Thinking> and <Processing> to indicate your process.
201
  ---
202
 
203
  By adhering to these principles and guidelines, ensure every response is accurate, professional, and easy to follow.
 
278
  chat_history.add_message("assistant", response)
279
 
280
  # Log the question and answer to a file
281
+ logger.info("Attempting to log question and answer to Logs.txt")
282
  log_to_file(question, response)
283
 
284
  except Exception as e: