From c0c3817cb2f0e0bde39f214807695fa5e7c3634c Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Tue, 10 Jan 2023 21:46:56 -0800 Subject: [PATCH] cr --- .github/workflows/file-check.yml | 21 ++++++++++++++++++++ Makefile | 4 ++++ ci_scripts/file-check.py | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 .github/workflows/file-check.yml create mode 100644 Makefile create mode 100644 ci_scripts/file-check.py diff --git a/.github/workflows/file-check.yml b/.github/workflows/file-check.yml new file mode 100644 index 0000000..cd77c88 --- /dev/null +++ b/.github/workflows/file-check.yml @@ -0,0 +1,21 @@ +name: file-check + +on: + push: + branches: [master] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + steps: + - uses: actions/checkout@v3 + - name: Install langchain + run: | + pipx install -U langchain + - name: Analysing the files with our Make command + run: | + make file-check diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..52a39a4 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: file-check + +file-check: + python ci_scripts/file-check.py diff --git a/ci_scripts/file-check.py b/ci_scripts/file-check.py new file mode 100644 index 0000000..67581e1 --- /dev/null +++ b/ci_scripts/file-check.py @@ -0,0 +1,33 @@ +from pathlib import Path + +from langchain.prompts import load_prompt + +BASE_FOLDER = Path("prompts") +folders = BASE_FOLDER.glob("**") + + +def check_files(files): + if len(files) != 2: + raise ValueError(f"Each directory should have two files, got {len(files)}") + file_names = [f.name for f in files] + if "README.md" not in file_names: + raise ValueError(f"Expected to find a README.md file, but found {files}") + other_file = [file for file in files if file.name != "README.md"][0] + if other_file.suffix in (".json", ".yaml"): + load_prompt(other_file) + # TODO: testing for python files + + +def check_all_folders(): + for folder in folders: + folder_path = Path(folder) + files = [x for x in folder_path.iterdir() if x.is_file()] + if len(files) > 0: + try: + check_files(files) + except Exception as e: + raise ValueError(f"Found error with {folder}: {e}") + + +if __name__ == "__main__": + check_all_folders()