Skip to content

Commit

Permalink
Juliagomes/rename attribute most similar chunk (#26)
Browse files Browse the repository at this point in the history
* Rename attribute similar_jailbreak_phrase as most_similar_dataset_chunk to reflect more general use case.

* Remove duplicate Arize in fail result error message

---------

Co-authored-by: Julia Gomes <[email protected]>
  • Loading branch information
jgomes168 and Julia Gomes authored Jul 3, 2024
1 parent 7227ef1 commit 3ea96e5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def validate(self, value: Any, metadata: Dict[str, Any]) -> ValidationResult:
# Get cosine distance between the embedding of the user message and the closest embedded jailbreak prompts chunk.
closest_chunk, lowest_distance = self.query_vector_collection(text=user_message, k=1)[0]
metadata["lowest_cosine_distance"] = lowest_distance
metadata["similar_jailbreak_phrase"] = closest_chunk
metadata["most_similar_dataset_chunk"] = closest_chunk

# Pass or fail Guard based on minimum cosine distance between user message and embedded jailbreak prompts.
if lowest_distance < self._threshold:
# At least one jailbreak embedding chunk was within the cosine distance threshold from the user input embedding
return FailResult(
metadata=metadata,
error_message=(
f"The following message triggered the Arize ArizeDatasetEmbeddings Guard:\n\t{user_message}"
f"The following message triggered the ArizeDatasetEmbeddings Guard:\n\t{user_message}"
),
)
# All chunks exceeded the cosine distance threshold
Expand Down

0 comments on commit 3ea96e5

Please sign in to comment.