feat: Log LLM responses to console
- Add a StreamHandler to the logger to output all logs to the console. - Log the LLM response to the console for real-time monitoring. - Update PROGRESS.md to reflect the completion of the task. - Fix a syntax error in monitor_agent.py.
This commit is contained in:
@@ -70,7 +70,7 @@
|
|||||||
|
|
||||||
- [x] Change baseline calculations to only use integers instead of floats.
|
- [x] Change baseline calculations to only use integers instead of floats.
|
||||||
- [x] Add a log file that only keeps records for the past 24 hours.
|
- [x] Add a log file that only keeps records for the past 24 hours.
|
||||||
- [ ] Log all LLM responses to the console.
|
- [x] Log all LLM responses to the console.
|
||||||
- [ ] Reduce alerts to only happen between 9am and 12am.
|
- [ ] Reduce alerts to only happen between 9am and 12am.
|
||||||
- [ ] Get hostnames of devices in Nmap scan.
|
- [ ] Get hostnames of devices in Nmap scan.
|
||||||
- [ ] Filter out RTT fluctuations below 10 seconds.
|
- [ ] Filter out RTT fluctuations below 10 seconds.
|
||||||
|
|||||||
@@ -26,10 +26,15 @@ logger = logging.getLogger(__name__)
|
|||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
# Create a handler that rotates logs daily, keeping 1 backup
|
# Create a handler that rotates logs daily, keeping 1 backup
|
||||||
handler = TimedRotatingFileHandler(LOG_FILE, when="midnight", interval=1, backupCount=1)
|
file_handler = TimedRotatingFileHandler(LOG_FILE, when="midnight", interval=1, backupCount=1)
|
||||||
handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
|
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
|
||||||
|
|
||||||
logger.addHandler(handler)
|
# Create a handler for console output
|
||||||
|
console_handler = logging.StreamHandler()
|
||||||
|
console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
|
||||||
|
|
||||||
|
logger.addHandler(file_handler)
|
||||||
|
logger.addHandler(console_handler)
|
||||||
|
|
||||||
|
|
||||||
LOG_POSITION_FILE = 'log_position.txt'
|
LOG_POSITION_FILE = 'log_position.txt'
|
||||||
@@ -257,7 +262,9 @@ def analyze_data_with_llm(data, baselines):
|
|||||||
end_index = sanitized_response.rfind('}')
|
end_index = sanitized_response.rfind('}')
|
||||||
if start_index != -1 and end_index != -1:
|
if start_index != -1 and end_index != -1:
|
||||||
json_string = sanitized_response[start_index:end_index+1]
|
json_string = sanitized_response[start_index:end_index+1]
|
||||||
return json.loads(json_string)
|
llm_response = json.loads(json_string)
|
||||||
|
logger.info(f"LLM Response: {llm_response}")
|
||||||
|
return llm_response
|
||||||
else:
|
else:
|
||||||
# Handle cases where the response is not valid JSON
|
# Handle cases where the response is not valid JSON
|
||||||
logger.warning(f"LLM returned a non-JSON response: {sanitized_response}")
|
logger.warning(f"LLM returned a non-JSON response: {sanitized_response}")
|
||||||
|
|||||||
Reference in New Issue
Block a user