Skip to content

Commit 2afe6f6

Browse files
authored
Merge pull request #112 from rossdonald/utf-bom-handling
fix: update file opening encoding to utf-8-sig to handle files with BOM
2 parents 8cf3b6e + 9e82cc8 commit 2afe6f6

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

utils/call_llm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
logger = logging.getLogger("llm_logger")
1616
logger.setLevel(logging.INFO)
1717
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')
1919
file_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}")

utils/crawl_github_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def should_include_file(file_path: str, file_name: str) -> bool:
104104

105105
# Read content
106106
try:
107-
with open(abs_path, "r", encoding="utf-8") as f:
107+
with open(abs_path, "r", encoding="utf-8-sig") as f:
108108
content = f.read()
109109
files[rel_path] = content
110110
print(f"Added {rel_path} ({file_size} bytes)")

utils/crawl_local_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def crawl_local_files(
3232
gitignore_spec = None
3333
if os.path.exists(gitignore_path):
3434
try:
35-
with open(gitignore_path, "r", encoding="utf-8") as f:
35+
with open(gitignore_path, "r", encoding="utf-8-sig") as f:
3636
gitignore_patterns = f.readlines()
3737
gitignore_spec = pathspec.PathSpec.from_lines("gitwildmatch", gitignore_patterns)
3838
print(f"Loaded .gitignore patterns from {gitignore_path}")
@@ -113,7 +113,7 @@ def crawl_local_files(
113113

114114
# --- File is being processed ---
115115
try:
116-
with open(filepath, "r", encoding="utf-8") as f:
116+
with open(filepath, "r", encoding="utf-8-sig") as f:
117117
content = f.read()
118118
files_dict[relpath] = content
119119
except Exception as e:

0 commit comments

Comments
 (0)