MachineLearningReply/search_mlReply
1
1import pydantic2import os3import fileinput4 5def replace_string_in_files(folder_path, old_str, new_str):6 for subdir, dirs, files in os.walk(folder_path):7 for file in files:8 file_path = os.path.join(subdir, file)9 10 # Check if the file is a text file (you can modify this condition based on your needs)11 if file.endswith(".txt") or file.endswith(".py"):12 # Open the file in place for editing13 with fileinput.FileInput(file_path, inplace=True) as f:14 for line in f:15 # Replace the old string with the new string16 print(line.replace(old_str, new_str), end='')17 18 19def use_pydantic_v1():20 module_file_path = pydantic.__file__21 module_file_path = module_file_path.split('pydantic')[0] + 'haystack' 22 with open(module_file_path+'/schema.py','r') as f:23 haystack_schema_file = f.read()24 25 if 'from pydantic.v1' not in haystack_schema_file:26 replace_string_in_files(module_file_path, 'from pydantic', 'from pydantic.v1')