1515logger = logging .getLogger ("llm_logger" )
1616logger .setLevel (logging .INFO )
1717logger .propagate = False # Prevent propagation to root logger
18- file_handler = logging .FileHandler (log_file )
18+ file_handler = logging .FileHandler (log_file , encoding = 'utf-8' )
1919file_handler .setFormatter (
2020 logging .Formatter ("%(asctime)s - %(levelname)s - %(message)s" )
2121)
@@ -36,7 +36,7 @@ def call_llm(prompt: str, use_cache: bool = True) -> str:
3636 cache = {}
3737 if os .path .exists (cache_file ):
3838 try :
39- with open (cache_file , "r" ) as f :
39+ with open (cache_file , "r" , encoding = "utf-8" ) as f :
4040 cache = json .load (f )
4141 except :
4242 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:
7373 cache = {}
7474 if os .path .exists (cache_file ):
7575 try :
76- with open (cache_file , "r" ) as f :
76+ with open (cache_file , "r" , encoding = "utf-8" ) as f :
7777 cache = json .load (f )
7878 except :
7979 pass
8080
8181 # Add to cache and save
8282 cache [prompt ] = response_text
8383 try :
84- with open (cache_file , "w" ) as f :
84+ with open (cache_file , "w" , encoding = "utf-8" ) as f :
8585 json .dump (cache , f )
8686 except Exception as e :
8787 logger .error (f"Failed to save cache: { e } " )
@@ -161,7 +161,7 @@ def call_llm(prompt: str, use_cache: bool = True) -> str:
161161# cache = {}
162162# if os.path.exists(cache_file):
163163# try:
164- # with open(cache_file, "r") as f:
164+ # with open(cache_file, "r", encoding="utf-8" ) as f:
165165# cache = json.load(f)
166166# except:
167167# 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:
211211# cache = {}
212212# if os.path.exists(cache_file):
213213# try:
214- # with open(cache_file, "r") as f:
214+ # with open(cache_file, "r", encoding="utf-8" ) as f:
215215# cache = json.load(f)
216216# except:
217217# pass
218218
219219# # Add to cache and save
220220# cache[prompt] = response_text
221221# try:
222- # with open(cache_file, "w") as f:
222+ # with open(cache_file, "w", encoding="utf-8" ) as f:
223223# json.dump(cache, f)
224224# except Exception as e:
225225# logger.error(f"Failed to save cache: {e}")
0 commit comments