From a25bdb20a52e7574cf6cd2a214f99df785136b92 Mon Sep 17 00:00:00 2001 From: tahmidefaz Date: Mon, 29 Jul 2024 22:38:10 -0400 Subject: [PATCH] do not gracefully fail on YAML validation fail --- example/main.py | 3 ++- pyproject.toml | 2 +- src/seedling/reader.py | 25 +++++-------------------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/example/main.py b/example/main.py index 781de55..bd6d185 100644 --- a/example/main.py +++ b/example/main.py @@ -17,12 +17,13 @@ def main(user_message): if __name__ == "__main__": messages = [ + "Are you human?", "do some magic on spotify!", "I want to make sure that I attend my friend's brithday party later this year", "I feel like eating out tonight", "It's so dark in this room... I can't see anything... help!", "anything interesting happened in the world of AI today?", - "look for a flight form New York to Los Angeles for July 28th", + "look for a flight from Denver to Honolulu for July 28th", "what's the weather in Seattle today?" ] diff --git a/pyproject.toml b/pyproject.toml index 7562770..3d5b593 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "seedling" -version = "0.2.0" +version = "0.2.1" description = "A simple library for intent recognition using LLMs." authors = [{name = "Tahmid Efaz"}] license = {file = "LICENSE"} diff --git a/src/seedling/reader.py b/src/seedling/reader.py index bcbbf9c..6d33242 100644 --- a/src/seedling/reader.py +++ b/src/seedling/reader.py @@ -42,24 +42,6 @@ } -def is_valid(filename: str, data: dict) -> bool: - """Validates data against a JSON schema. - - Args: - filename: The name of the file being validated. - data: The file data to validate. - - Returns: - True if the data is valid, False otherwise. - """ - try: - jsonschema.validate(instance=data, schema=SCHEMA) - except jsonschema.exceptions.ValidationError as e: - print(f"{filename} is invalid: {e}") - return False - return True - - def read(directory: str) -> list: """Reads YAML files in a directory, validates it using a JSONschema and returns an array of dictionaries. @@ -77,7 +59,10 @@ def read(directory: str) -> list: for yaml_file in yaml_files: with open(yaml_file, 'r', encoding='UTF-8') as f: data = yaml.safe_load(f) - if is_valid(yaml_file, data): - all_topic_info.append(data) + + # Validate against JSONschema, and fail script when validation do not pass + jsonschema.validate(instance=data, schema=SCHEMA) + + all_topic_info.append(data) return all_topic_info