Chris4K commited on
Commit
fa54c46
·
1 Parent(s): 568e154
Files changed (2) hide show
  1. controller.py +16 -1
  2. utils/logger.py +56 -1
controller.py CHANGED
@@ -14,10 +14,22 @@ Classes:
14
  """
15
  import os
16
  from app_agent_config import AgentConfig # Importing AgentConfig class from app_agent_config module
17
- from utils.logger import log_response # Importing log_response function from utils.logger module
18
  from model.custom_agent import CustomHfAgent # Importing CustomHfAgent class from model.custom_agent module
19
  from model.conversation_chain_singleton import ConversationChainSingleton # Importing ConversationChainSingleton class from model.conversation_chain_singleton module
20
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def cut_text_after_keyword(text, keyword):
22
  """
23
  Cuts text after the occurrence of a keyword.
@@ -57,6 +69,8 @@ class Controller:
57
  """
58
  def __init__(self):
59
  self.agent_config = AgentConfig() # Initialize AgentConfig instance
 
 
60
 
61
  image = [] # Class attribute for storing image data
62
 
@@ -70,6 +84,7 @@ class Controller:
70
  Returns:
71
  - str: The response from the Hugging Face model.
72
  """
 
73
  log_response("User input \n {}".format(user_message))
74
  log_response("selected_tools \n {}".format(self.agent_config.s_tool_checkboxes))
75
  log_response("url_endpoint \n {}".format(self.agent_config.url_endpoint))
 
14
  """
15
  import os
16
  from app_agent_config import AgentConfig # Importing AgentConfig class from app_agent_config module
17
+ from utils.logger import log_response, IRCLogger # Importing log_response function from utils.logger module
18
  from model.custom_agent import CustomHfAgent # Importing CustomHfAgent class from model.custom_agent module
19
  from model.conversation_chain_singleton import ConversationChainSingleton # Importing ConversationChainSingleton class from model.conversation_chain_singleton module
20
 
21
+ import logging
22
+
23
+ logging.basicConfig(level=logging.INFO)
24
+
25
+ server = "irc.efnet.org"
26
+ port = 6667
27
+ nickname = "HFLogger"
28
+ channel = "#hflogs"
29
+
30
+ logger = IRCLogger(server, port, nickname, channel)
31
+ logger.log_message("This is a test log message from the IRC logger.")
32
+
33
  def cut_text_after_keyword(text, keyword):
34
  """
35
  Cuts text after the occurrence of a keyword.
 
69
  """
70
  def __init__(self):
71
  self.agent_config = AgentConfig() # Initialize AgentConfig instance
72
+ logger.log_message("This is a test log message from the IRC logger.")
73
+
74
 
75
  image = [] # Class attribute for storing image data
76
 
 
84
  Returns:
85
  - str: The response from the Hugging Face model.
86
  """
87
+ logger.log_message("This is a test log message from the IRC logger.")
88
  log_response("User input \n {}".format(user_message))
89
  log_response("selected_tools \n {}".format(self.agent_config.s_tool_checkboxes))
90
  log_response("url_endpoint \n {}".format(self.agent_config.url_endpoint))
utils/logger.py CHANGED
@@ -33,4 +33,59 @@ class ChatHandler(logging.Handler):
33
 
34
  # Add the custom handler to the transformers_logger
35
  chat_handler = ChatHandler()
36
- transformers_logger.addHandler(chat_handler)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  # Add the custom handler to the transformers_logger
35
  chat_handler = ChatHandler()
36
+ transformers_logger.addHandler(chat_handler)
37
+
38
+
39
+
40
+ import socket
41
+ import threading
42
+ import logging
43
+
44
+ class IRCLogger:
45
+ def __init__(self, server, port, nickname, channel):
46
+ self.server = server
47
+ self.port = port
48
+ self.nickname = nickname
49
+ self.channel = channel
50
+ self.socket = socket.socket()
51
+ self.socket.connect((self.server, self.port))
52
+
53
+ # Configure logging
54
+ self.logger = logging.getLogger(__name__)
55
+ self.logger.setLevel(logging.INFO)
56
+
57
+ # Create a stream handler and set its level to INFO
58
+ handler = logging.StreamHandler()
59
+ handler.setLevel(logging.INFO)
60
+
61
+ # Create a formatter and set the format
62
+ formatter = logging.Formatter('%(asctime)s - %(message)s')
63
+ handler.setFormatter(formatter)
64
+
65
+ # Add the handler to the logger
66
+ self.logger.addHandler(handler)
67
+
68
+ # Join the IRC channel
69
+ self.join_channel()
70
+
71
+ def send_message(self, message):
72
+ self.socket.send(bytes("PRIVMSG {} :{}\r\n".format(self.channel, message), "UTF-8"))
73
+
74
+ def join_channel(self):
75
+ self.socket.send(bytes("NICK {}\r\n".format(self.nickname), "UTF-8"))
76
+ self.socket.send(bytes("USER {} 0 * :{}\r\n".format(self.nickname, self.nickname), "UTF-8"))
77
+ self.socket.send(bytes("JOIN {}\r\n".format(self.channel), "UTF-8"))
78
+
79
+ def log_message(self, message):
80
+ self.logger.info(message)
81
+ self.send_message(message)
82
+
83
+ if __name__ == "__main__":
84
+ # Configure logging
85
+ logging.basicConfig(level=logging.INFO)
86
+
87
+ server = "irc.efnet.org"
88
+ port = 6667
89
+ nickname = "HFLogger"
90
+ channel = "#hflogs"
91
+