File size: 3,346 Bytes
ddf3d8a
4f52ef2
ddf3d8a
171e985
240897b
171e985
 
c5ec18a
171e985
 
b409e9d
171e985
b409e9d
171e985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b409e9d
 
171e985
 
 
fa54c46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abe7a86
 
 
 
fa54c46
 
 
 
 
 
 
 
abe7a86
 
 
 
 
 
35cca5f
 
abe7a86
fa54c46
 
 
 
abe7a86
 
 
 
 
 
c5ec18a
abe7a86
fa54c46
abe7a86
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import logging #### todo add transformer logs
import streamlit as st
#from transformers.utils import logging
# Configure the logging settings for transformers
transformers_logger = logging.getLogger("transformers.tools.agents")
transformers_logger.setLevel(logging.INFO)  # Set the desired logging level

log_enabled = True


##################################### logger #################################

 


def log_response(response):
    if log_enabled:
        with st.chat_message("ai"):
            st.markdown("Agent Response\n {}".format(response))
    print(response)

# Custom logging handler to append log messages to the chat
class ChatHandler(logging.Handler):
    def __init__(self):
        super().__init__()


    def emit(self, record):
        log_message = self.format(record)
        #with st.chat_message("ai"):
        st.markdown(f"Log: {log_message}")
        with st.chat_message("ai"):
            st.markdown("Agent Response\n {}".format(record))

# Add the custom handler to the transformers_logger
chat_handler = ChatHandler()
transformers_logger.addHandler(chat_handler)



import socket
import threading
import logging

class IRCLogger:
    def __init__(self, server, port, nickname, channel):
        self.server = server
        self.port = port
        self.nickname = nickname
        self.channel = channel
        self.socket = socket.socket()
        self.socket.connect((self.server, self.port))

        # Configure logging
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.INFO)

        # Create a stream handler and set its level to INFO
        handler = logging.StreamHandler()
        handler.setLevel(logging.INFO)

        # Create a formatter and set the format
        formatter = logging.Formatter('%(asctime)s - %(message)s')
        handler.setFormatter(formatter)

        # Add the handler to the logger
        self.logger.addHandler(handler)

        # Join the IRC channel
        self.join_channel()

        # Start a thread to handle incoming messages
        receive_thread = threading.Thread(target=self.receive_messages)
        receive_thread.start()

    def send_message(self, message):
        self.socket.send(bytes("PRIVMSG {} :{}\r\n".format(self.channel, message), "UTF-8"))

    def join_channel(self):
        self.socket.send(bytes("NICK {}\r\n".format(self.nickname), "UTF-8"))
        self.socket.send(bytes("USER {} 0 * :{}\r\n".format(self.nickname, self.nickname), "UTF-8"))
        self.socket.send(bytes("JOIN {}\r\n".format(self.channel), "UTF-8"))

    def receive_messages(self):
        while True:
            data = self.socket.recv(4096).decode("UTF-8")
            if data.startswith("PING"):
                self.socket.send(bytes("PONG {}\r\n".format(data.split()[1]), "UTF-8"))
            else:
                if not data.startswith("-"):
                    self.logger.info(data)

    def log_message(self, message):
        self.logger.info(message)
        self.send_message(message)

if __name__ == "__main__":
    # Configure logging
    logging.basicConfig(level=logging.INFO)

    server = "irc.efnet.org"
    port = 6667
    nickname = "HFLogBB"
    channel = "#hflogs"

#    logger = IRCLogger(server, port, nickname, channel)
#    logger.log_message("This is a test log message from the IRC logger.")