k-mktr commited on
Commit
66eba7b
·
verified ·
1 Parent(s): 2b882cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -3,6 +3,7 @@ from functools import lru_cache
3
  import random
4
  import requests
5
  import logging
 
6
  import config
7
  import plotly.graph_objects as go
8
  from typing import Dict
@@ -25,15 +26,32 @@ from release_notes import get_release_notes_html
25
 
26
  # Update the logging format to redact URLs
27
  logging.basicConfig(
28
- level=logging.INFO,
29
  format='%(asctime)s - %(levelname)s - %(message)s'
30
  )
31
 
 
 
 
 
 
32
  class RedactURLsFilter(logging.Filter):
33
  def filter(self, record):
34
- # Redact both API URL and Nextcloud URL
35
- record.msg = record.msg.replace(config.API_URL, '[API_ENDPOINT]')
36
- record.msg = record.msg.replace(config.NEXTCLOUD_URL, '[CLOUD_STORAGE]')
 
 
 
 
 
 
 
 
 
 
 
 
37
  return True
38
 
39
  # Apply the filter to all handlers
@@ -100,7 +118,6 @@ def call_ollama_api(model, prompt):
100
  ]
101
 
102
  # Extract thinking part and main content using regex
103
- import re
104
  thinking_match = re.search(r'<think>(.*?)</think>', content, flags=re.DOTALL)
105
 
106
  if thinking_match:
 
3
  import random
4
  import requests
5
  import logging
6
+ import re
7
  import config
8
  import plotly.graph_objects as go
9
  from typing import Dict
 
26
 
27
  # Update the logging format to redact URLs
28
  logging.basicConfig(
29
+ level=logging.WARNING, # Only show warnings and errors
30
  format='%(asctime)s - %(levelname)s - %(message)s'
31
  )
32
 
33
+ # Suppress verbose HTTP request logging
34
+ logging.getLogger("urllib3").setLevel(logging.CRITICAL)
35
+ logging.getLogger("httpx").setLevel(logging.CRITICAL)
36
+ logging.getLogger("openai").setLevel(logging.CRITICAL)
37
+
38
  class RedactURLsFilter(logging.Filter):
39
  def filter(self, record):
40
+ # Redact all URLs using regex pattern
41
+ url_pattern = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
42
+ record.msg = re.sub(url_pattern, '[REDACTED_URL]', str(record.msg))
43
+
44
+ # Remove HTTP status codes
45
+ record.msg = re.sub(r'HTTP/\d\.\d \d+ \w+', '', record.msg)
46
+
47
+ # Remove sensitive API references
48
+ record.msg = record.msg.replace(config.API_URL, '[API]')
49
+ record.msg = record.msg.replace(config.NEXTCLOUD_URL, '[CLOUD]')
50
+
51
+ # Clean up residual artifacts
52
+ record.msg = re.sub(r'\s+', ' ', record.msg).strip()
53
+ record.msg = re.sub(r'("?) \1', '', record.msg) # Remove empty quotes
54
+
55
  return True
56
 
57
  # Apply the filter to all handlers
 
118
  ]
119
 
120
  # Extract thinking part and main content using regex
 
121
  thinking_match = re.search(r'<think>(.*?)</think>', content, flags=re.DOTALL)
122
 
123
  if thinking_match: