Skip to content

Commit

Permalink
make things even safer
Browse files Browse the repository at this point in the history
  • Loading branch information
e-p-armstrong committed Aug 17, 2024
1 parent f287f53 commit 45044bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions augmentoolkit/control_flow_functions/control_flow_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def convert_revised_questions_to_question_generation_training(qa_tuples_by_parag
else:
question_generation_prompt = os.path.join(obj_conf["PATH"]["PROMPTS"], "qatuples_gen_no_filenames.yaml")

with open(question_generation_prompt, "r",encoding='utf-8') as f:
with open(question_generation_prompt, "r",encoding='utf-8', errors="replace") as f:
qgen_prompt_full = yaml.safe_load(f)

sysprompt = qgen_prompt_full[0]["content"]
Expand Down Expand Up @@ -277,7 +277,7 @@ async def repair_qatuple_context(
# Resume normal control flow
file_path = os.path.join(writepath, f"revised_{idx}.json")
if os.path.exists(file_path):
with open(file_path, "r", encoding="utf-8") as f:
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
content = f.read() # Read the file once and store its content
print(file_path)
if content == "failed":
Expand Down Expand Up @@ -664,7 +664,7 @@ async def vet_question_loop(
if len(existing_files) > 0: # If files exist, skip this paragraph entirely
print(f"Loading file")
for file_path in existing_files:
with open(file_path, "r") as file:
with open(file_path, "r", errors="replace") as file:
file_body = file.read()
if file_body == "failed":
qa_tuple = None
Expand Down Expand Up @@ -901,7 +901,7 @@ async def generate_qatuples_from_para(
if len(existing_files) > 0: # If files exist, skip this paragraph entirely
print(f"Skipping para_{idx} as files already exist; loading said files")
for file_path in existing_files:
with open(file_path, "r") as file:
with open(file_path, "r", errors="replace") as file:
qa_tuple = tuple(json.load(file))
generated_qa_tuples.append(qa_tuple)
return
Expand Down Expand Up @@ -1108,7 +1108,7 @@ def sentence_chunking_algorithm(file_path, max_char_length=1900):
source_name = file_path.replace(".txt", "")


with open(file_path, 'r', encoding='utf-8') as file:
with open(file_path, 'r', encoding='utf-8', errors="replace") as file:
content = file.read()

# try:
Expand Down Expand Up @@ -1367,7 +1367,7 @@ async def create_conversation(
print("Had an error, retrying...", e)
else:
try:
with open(file_path, "r", encoding="utf-8") as f:
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
data = json.load(f)
multi_turn_convs.append(data)
print(f"Skipped generating {file_path} as it already exists")
Expand Down
2 changes: 1 addition & 1 deletion processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ async def run_task_with_limit(task):
for file_name in os.listdir(writepath):
file_path = os.path.join(writepath, file_name)
try: # for each file already generated, see if it succeeded or failed; if it succeeded, append its contents; if it failed, append None for stats logging
with open(file_path, "r", encoding="utf-8") as f:
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
content = f.read()
print(f"Loading file: {file_path}")
if content == "failed":
Expand Down

0 comments on commit 45044bc

Please sign in to comment.