-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All examples must adhere to a strict format. We'll be adding a directory with "unstructured" examples that don't adhere.
- Loading branch information
1 parent
dd2740d
commit 8aa989d
Showing
7 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
digraph { | ||
graph [compound=false concentrate=false rankdir=TB ranksep=0.4] | ||
human_input [label=human_input shape=box style=rounded] | ||
input__prompt [label="input: prompt" shape=oval style=dashed] | ||
input__prompt -> human_input | ||
ai_response [label=ai_response shape=box style=rounded] | ||
safety_check [label=safety_check shape=box style=rounded] | ||
unsafe_response [label=unsafe_response shape=box style=rounded] | ||
human_input -> safety_check [style=solid] | ||
safety_check -> unsafe_response [label="safe=False" style=dashed] | ||
safety_check -> ai_response [label="safe=True" style=dashed] | ||
unsafe_response -> human_input [style=solid] | ||
ai_response -> human_input [style=solid] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
|
||
EXAMPLES_DIR = "." | ||
REQUIRED_FILES = ["notebook.ipynb", "application.py", "README.md", "digraph.png"] | ||
|
||
FILTERLIST = [] | ||
|
||
|
||
def should_validate(directory: str) -> bool: | ||
"""Return True if the given directory is an example directory.""" | ||
return ( | ||
os.path.isdir(os.path.join(EXAMPLES_DIR, directory)) | ||
and not directory.startswith(".") | ||
and not directory.startswith("_") | ||
and directory not in FILTERLIST | ||
) | ||
|
||
|
||
def get_directories(base_path: str) -> list[str]: | ||
"""Return a list of directories under the given base_path.""" | ||
return [d for d in os.listdir(base_path) if should_validate(d)] | ||
|
||
|
||
def check_files_exist(directory, files): | ||
"""Check if each file in 'files' exists in 'directory'.""" | ||
missing_files = [] | ||
for file in files: | ||
if not os.path.exists(os.path.join(EXAMPLES_DIR, directory, file)): | ||
missing_files.append(file) | ||
return missing_files | ||
|
||
|
||
# Use pytest_generate_tests to dynamically parameterize the fixture | ||
def pytest_generate_tests(metafunc): | ||
# if "directory" in metafunc.fixturenames: | ||
directories = get_directories(EXAMPLES_DIR) | ||
metafunc.parametrize("directory", directories, scope="module") | ||
|
||
|
||
def test_directory_contents(directory): | ||
required_files = ["notebook.ipynb", "application.py", "README.md", "digraph.png"] | ||
missing_files = check_files_exist(directory, required_files) | ||
assert not missing_files, f"Missing files in '{directory}': {', '.join(missing_files)}" |