in use-cases/model-fine-tuning-pipeline/model-eval/src/validate_fine_tuned_model.py [0:0]
def extract_product_names(self, predictions_file: str) -> list[str]:
product_names = []
current_product = ""
# Read and process the text file
with open(predictions_file, "r") as file:
for line in file:
line = line.strip()
# Check for the delimiter
# if line == "Prompt:":
if line == "----------":
if current_product: # Ensure a product was found
product_names.append(current_product)
else:
product_names.append(
None
) # When there is no product name in the prediction
current_product = "" # Reset for the next product
elif line.startswith("Product Name:"):
if not current_product:
current_product = line.split(": ")[1]
return product_names