Update logger.py
Browse files
logger.py
CHANGED
@@ -1,5 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
def log_response(response):
|
2 |
if log_enabled:
|
3 |
with st.chat_message("ai"):
|
4 |
st.markdown("Agent Response\n {}".format(response))
|
5 |
-
print(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging #### todo add transformer logs
|
2 |
+
|
3 |
+
# Configure the logging settings for transformers
|
4 |
+
transformers_logger = logging.getLogger("transformers.file_utils")
|
5 |
+
transformers_logger.setLevel(logging.INFO) # Set the desired logging level
|
6 |
+
|
7 |
def log_response(response):
|
8 |
if log_enabled:
|
9 |
with st.chat_message("ai"):
|
10 |
st.markdown("Agent Response\n {}".format(response))
|
11 |
+
print(response)
|
12 |
+
|
13 |
+
# Custom logging handler to append log messages to the chat
|
14 |
+
class ChatHandler(logging.Handler):
|
15 |
+
def __init__(self):
|
16 |
+
super().__init__()
|
17 |
+
|
18 |
+
def emit(self, record):
|
19 |
+
log_message = self.format(record)
|
20 |
+
with st.chat_message("ai"):
|
21 |
+
st.markdown(f"Log: {log_message}")
|
22 |
+
|
23 |
+
# Add the custom handler to the transformers_logger
|
24 |
+
chat_handler = ChatHandler()
|
25 |
+
transformers_logger.addHandler(chat_handler)
|