Repository navigation
feat: Add granite guardian filter #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+349
−13
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1b3cc93
add granite guardian filter
OscarDDD 57180e9
Add GraniteGuardian41FilterConfig into the sample code
OscarDDD 5be3728
add validator for at least one specified category
OscarDDD bb92799
Align the granite guard with llama guard
OscarDDD a041948
Merge branch 'main' into Add_Granite_Guardian_Filter
OscarDDD 73030c1
Merge branch 'main' into Add_Granite_Guardian_Filter
OscarDDD ebd14a2
Improve the docstring explaination
OscarDDD 096efa3
add integration tests
OscarDDD 46df2f5
fix the integration tests.
OscarDDD 7184eae
fix the integration tests for outputfiltering
OscarDDD 2a44f74
switch enable_reasoning default value from false to none
OscarDDD 1cdba99
Merge branch 'main' into Add_Granite_Guardian_Filter
OscarDDD c502d4d
Merge branch 'main' into Add_Granite_Guardian_Filter
OscarDDD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
packages/gen/gen_ai_hub/orchestration_v2/models/granite_guardian_filter.py
This file contains hidden or 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,58 @@ | ||
| """ | ||
| Granite Guardian 4.1 Content Filter Model | ||
| """ | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from gen_ai_hub.orchestration_v2.models.base import ABCBaseModel as BaseModel | ||
|
|
||
|
|
||
| class GraniteGuardian41Categories(BaseModel): | ||
| """ | ||
| Granite Guardian 4.1 content criteria to evaluate. | ||
|
|
||
| Note: Granite Guardian performs separate calls for each configured content category. | ||
| Recommendation: Use only the ``harm`` catch-all content category. | ||
|
|
||
| Args: | ||
| harm: Catch-all criterion for generally harmful content. | ||
|
|
||
| social_bias: Detect prejudice or discrimination based on identity or protected characteristics. | ||
|
|
||
| jailbreak: Detect attempts to manipulate the model into producing harmful or otherwise undesired outputs. | ||
|
|
||
| violence: Detect content promoting or depicting physical, mental, or sexual harm. | ||
|
|
||
| profanity: Detect offensive language or insults. | ||
|
|
||
| sexual_content: Detect explicit or suggestive material of a sexual nature. | ||
|
|
||
| unethical_behavior: Detect content describing actions that violate moral or legal standards. | ||
| """ | ||
|
|
||
| harm: bool = False | ||
| social_bias: bool = False | ||
| jailbreak: bool = False | ||
| violence: bool = False | ||
| profanity: bool = False | ||
| sexual_content: bool = False | ||
| unethical_behavior: bool = False | ||
|
|
||
|
|
||
| class GraniteGuardian41Filter(BaseModel): | ||
| """ | ||
| Configuration for the IBM Granite Guardian 4.1 filter provider. | ||
|
|
||
| Args: | ||
| enable_reasoning: Enable reasoning (think) mode for Granite Guardian. Applies to every configured | ||
| category. Returns reasoning content when enabled, e.g. | ||
| ``'harm': {'verdict': true, 'reasoning': '...'}``. | ||
|
|
||
| categories: Content criteria to evaluate. | ||
| """ | ||
|
|
||
| enable_reasoning: Optional[bool] = None | ||
| categories: GraniteGuardian41Categories | ||
|
|
||
|
|
||
| __all__ = ["GraniteGuardian41Categories", "GraniteGuardian41Filter"] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.