Skip to content

Commit

Permalink
updated readme, requirements, validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rabah-khalek committed Dec 20, 2023
1 parent cf15f35 commit 4477d01
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ The `prompt_injections.csv` file is a concatenation of prompts from the followin
- https://github.com/agencyenterprise/PromptInject

with their respective licenses in the `licenses` directory.

## Setup and validation

The pip `requirement.txt` is only needed to run `validate.py`, a minimal validation script to ensure that the prompt injection data is generated in the correct format.
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
numpy==1.26.2
pandas==2.1.4
python-dateutil==2.8.2
pytz==2023.3.post1
six==1.16.0
tzdata==2023.3
28 changes: 28 additions & 0 deletions validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pandas as pd
import ast

INJECTION_DATA_PATH = "prompt_injections.csv"
GISKARD_META_PATH = "giskard_meta_data.csv"

def _check_matching_dfs_len(df1, df2):
if len(df1) != len(df2):
raise ValueError(
f"{__name__}: {INJECTION_DATA_PATH} and {GISKARD_META_PATH} should "
"have the same length and should be a one-to-one mapping of each other."
)

def _check_meta_df_requirements(df):
if "expected_strings" not in df.columns:
raise ValueError(f"{__name__}: expected_strings are needed for the evaluation.")

if df.expected_strings.isnull().values.any():
raise ValueError(f"{__name__}: expected_strings column cannot have any NaN values.")
df.expected_strings = df.expected_strings.apply(ast.literal_eval)


if __name__ == "__main__":
prompt_injections_df = pd.read_csv(INJECTION_DATA_PATH, index_col=["index"])
meta_df = pd.read_csv(GISKARD_META_PATH, index_col=["index"])
_check_matching_dfs_len(meta_df, prompt_injections_df)
_check_meta_df_requirements(meta_df)
print("Validation passed succesfully!")

0 comments on commit 4477d01

Please sign in to comment.