Skip to content

Commit

Permalink
fix: ensure cache files are UTF-8 encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
zhudotexe committed Oct 10, 2024
1 parent ac2b373 commit 5e19c27
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fanoutqa/eval/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def get_llm_factuality(question: DevQuestion, answer: str, cache_key=None)
ans_hash = hashlib.sha256(answer.encode()).hexdigest()[:8]
cache_filename = LLM_CACHE_DIR / f"factual-{cache_key}-{question.id}-{ans_hash}.txt"
if cache_filename.exists():
return cache_filename.read_text()
return cache_filename.read_text(encoding="utf-8")

# ask the LLM if it is subjective
prompt = factuality_prompt(question.question, str_answer(question.answer), answer)
Expand All @@ -51,5 +51,5 @@ async def get_llm_factuality(question: DevQuestion, answer: str, cache_key=None)

if cache_key:
# noinspection PyUnboundLocalVariable
cache_filename.write_text(resp)
cache_filename.write_text(resp, encoding="utf-8")
return resp
4 changes: 2 additions & 2 deletions fanoutqa/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def wiki_content(doc: Evidence) -> str:
# get the cached content, if available
cache_filename = WIKI_CACHE_DIR / f"{doc.pageid}-dated.md"
if cache_filename.exists():
return cache_filename.read_text()
return cache_filename.read_text(encoding="utf-8")

# otherwise retrieve it from Wikipedia
resp = wikipedia.get("", params={"format": "json", "action": "parse", "oldid": doc.revid, "prop": "text"})
Expand All @@ -90,5 +90,5 @@ def wiki_content(doc: Evidence) -> str:

# MD it, cache it, and return
text = markdownify(html)
cache_filename.write_text(text)
cache_filename.write_text(text, encoding="utf-8")
return text
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "fanoutqa"
version = "1.1.0"
version = "1.1.1"
authors = [
{ name = "Andrew Zhu", email = "[email protected]" },
{ name = "Alyssa Hwang", email = "[email protected]" },
Expand Down

0 comments on commit 5e19c27

Please sign in to comment.