15
15
logger = logging .getLogger ("llm_logger" )
16
16
logger .setLevel (logging .INFO )
17
17
logger .propagate = False # Prevent propagation to root logger
18
- file_handler = logging .FileHandler (log_file )
18
+ file_handler = logging .FileHandler (log_file , encoding = 'utf-8' )
19
19
file_handler .setFormatter (
20
20
logging .Formatter ("%(asctime)s - %(levelname)s - %(message)s" )
21
21
)
@@ -36,7 +36,7 @@ def call_llm(prompt: str, use_cache: bool = True) -> str:
36
36
cache = {}
37
37
if os .path .exists (cache_file ):
38
38
try :
39
- with open (cache_file , "r" ) as f :
39
+ with open (cache_file , "r" , encoding = "utf-8" ) as f :
40
40
cache = json .load (f )
41
41
except :
42
42
logger .warning (f"Failed to load cache, starting with empty cache" )
@@ -73,15 +73,15 @@ def call_llm(prompt: str, use_cache: bool = True) -> str:
73
73
cache = {}
74
74
if os .path .exists (cache_file ):
75
75
try :
76
- with open (cache_file , "r" ) as f :
76
+ with open (cache_file , "r" , encoding = "utf-8" ) as f :
77
77
cache = json .load (f )
78
78
except :
79
79
pass
80
80
81
81
# Add to cache and save
82
82
cache [prompt ] = response_text
83
83
try :
84
- with open (cache_file , "w" ) as f :
84
+ with open (cache_file , "w" , encoding = "utf-8" ) as f :
85
85
json .dump (cache , f )
86
86
except Exception as e :
87
87
logger .error (f"Failed to save cache: { e } " )
@@ -161,7 +161,7 @@ def call_llm(prompt: str, use_cache: bool = True) -> str:
161
161
# cache = {}
162
162
# if os.path.exists(cache_file):
163
163
# try:
164
- # with open(cache_file, "r") as f:
164
+ # with open(cache_file, "r", encoding="utf-8" ) as f:
165
165
# cache = json.load(f)
166
166
# except:
167
167
# logger.warning(f"Failed to load cache, starting with empty cache")
@@ -211,15 +211,15 @@ def call_llm(prompt: str, use_cache: bool = True) -> str:
211
211
# cache = {}
212
212
# if os.path.exists(cache_file):
213
213
# try:
214
- # with open(cache_file, "r") as f:
214
+ # with open(cache_file, "r", encoding="utf-8" ) as f:
215
215
# cache = json.load(f)
216
216
# except:
217
217
# pass
218
218
219
219
# # Add to cache and save
220
220
# cache[prompt] = response_text
221
221
# try:
222
- # with open(cache_file, "w") as f:
222
+ # with open(cache_file, "w", encoding="utf-8" ) as f:
223
223
# json.dump(cache, f)
224
224
# except Exception as e:
225
225
# logger.error(f"Failed to save cache: {e}")
0 commit comments