-
Notifications
You must be signed in to change notification settings - Fork 604
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
Feat: semantic prompt guard plugin #7770
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ce25bf5
semantic prompt guard plugin bones
Guaris b2461a7
added some content to overview and how-to
lmilan 8845c80
submodules updates
lmilan e771bbf
semantic prompt guard plugin bones
Guaris a4a72d6
added content for "how it works" and examples
lmilan 5e04c18
Revert "submodules updates"
lmilan 4bdee95
Apply suggestions from code review
lmilan 8a44f40
remove ai proxy prereq
lmilan 65e6a88
clarify behavior with both allow and deny
lmilan 6d78146
updated ai plugin list
lmilan f3d7709
add version condition
lmilan 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 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 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,5 @@ | ||
## Changelog | ||
|
||
### {{site.base_gateway}} 3.8.0.0 | ||
|
||
* Introduced the new **AI Semantic Prompt Guard** plugin. |
21 changes: 21 additions & 0 deletions
21
app/_hub/kong-inc/ai-semantic-prompt-guard/_metadata/_index.yml
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,21 @@ | ||
name: AI Semantic Prompt Guard | ||
search_aliases: | ||
- ai | ||
- llm | ||
- artificial | ||
- intelligence | ||
- language | ||
- model | ||
- semantic | ||
dbless_compatible: yes | ||
free: true | ||
enterprise: true | ||
paid: true | ||
konnect: false | ||
network_config_opts: All | ||
notes: -- | ||
categories: | ||
- ai | ||
publisher: Kong Inc. | ||
desc: Semantically and intelligently create allow and deny lists of topics that can be requested across every LLM. | ||
type: plugin |
169 changes: 169 additions & 0 deletions
169
app/_hub/kong-inc/ai-semantic-prompt-guard/how-to/_index.md
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,169 @@ | ||
--- | ||
nav_title: Using the AI Semantic Prompt Guard plugin | ||
title: Using the AI Semantic Prompt Guard plugin | ||
--- | ||
|
||
The AI Semantic Prompt Guard configuration takes two arrays of objects: one for `allow` prompts, and | ||
one for `deny` prompts, which it uses to determine which prompts are permitted or blocked. | ||
|
||
## Examples | ||
|
||
The following examples show how to configure allow and deny prompts, and the expected behavior when making requests. | ||
|
||
### Allow only | ||
|
||
For example, to allow only message related to the topic Kong, configure the `allow_prompt` like this: | ||
|
||
```yaml | ||
allow_prompts: | ||
- "Anything about Kong" | ||
``` | ||
|
||
{% navtabs %} | ||
|
||
{% navtab Valid %} | ||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are an IT specialist." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "What does Kong do?" | ||
} | ||
] | ||
} | ||
``` | ||
{% endnavtab %} | ||
|
||
{% navtab Invalid %} | ||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are an IT specialist." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "What is GitHub?" | ||
} | ||
] | ||
} | ||
``` | ||
{% endnavtab %} | ||
|
||
{% endnavtabs %} | ||
|
||
### Deny only | ||
|
||
To deny any questions related to Microsoft, you can configure the following prompt: | ||
|
||
```yaml | ||
deny_prompts: | ||
- "Tell me something about Microsoft" | ||
``` | ||
|
||
{% navtabs %} | ||
|
||
{% navtab Valid %} | ||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are an IT specialist." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "What is an API?" | ||
} | ||
] | ||
} | ||
``` | ||
{% endnavtab %} | ||
|
||
{% navtab Invalid %} | ||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are an IT specialist." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "When was Microsoft founded?" | ||
} | ||
] | ||
} | ||
``` | ||
{% endnavtab %} | ||
|
||
{% endnavtabs %} | ||
|
||
### Allow and deny | ||
|
||
To allow only questions about Kong that are not related to AWS, you can configure the following prompts: | ||
|
||
```yaml | ||
allow_prompts: | ||
- "Questions about Kong" | ||
deny_prompts: | ||
- "Anything related to AWS" | ||
``` | ||
|
||
{% navtabs %} | ||
|
||
{% navtab Valid %} | ||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are an IT specialist." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "What are Kong's products?" | ||
} | ||
] | ||
} | ||
``` | ||
{% endnavtab %} | ||
|
||
{% navtab Invalid %} | ||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are an IT specialist." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "How to install Git?" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are an IT specialist." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "Does Kong have an AWS plugin?" | ||
} | ||
] | ||
} | ||
``` | ||
{% endnavtab %} | ||
|
||
{% endnavtabs %} | ||
lmilan marked this conversation as resolved.
Show resolved
Hide resolved
|
29 changes: 29 additions & 0 deletions
29
app/_hub/kong-inc/ai-semantic-prompt-guard/overview/_index.md
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,29 @@ | ||
--- | ||
nav_title: Overview | ||
--- | ||
|
||
The AI Semantic Prompt Guard plugin enhances the AI Prompt Guard plugin by allowing you to permit or block prompts based on a list of similar prompts, helping to prevent misuse of `llm/v1/chat` or `llm/v1/completions` requests. | ||
|
||
|
||
You can use a combination of `allow` and `deny` rules to maintain integrity and compliance when serving an LLM service using {{site.base_gateway}}. | ||
|
||
## How it works | ||
|
||
The plugin matches lists of prompts to requests through AI Proxy. | ||
|
||
The matching behavior is as follows: | ||
* If any `deny` prompts are set, and the request matches prompt in the `deny` list, the caller receives a 400 response. | ||
* If any `allow` prompts are set, but the request matches none of the allowed prompts, the caller also receives a 400 response. | ||
* If any `allow` prompts are set, and the request matches one of the `allow` prompts, the request passes through to the LLM. | ||
* If there are both `deny` and `allow` prompts set, the `deny` condition takes precedence over `allow`. Any request that matches a prompt in the `deny` list will return a 400 response, even if it also matches a prompt in the `allow` list. If the request does not match a prompt in the `deny` list, then it must match a prompt in the `allow` list to be passed through to the LLM | ||
|
||
## Get started with the AI Prompt Guard plugin | ||
|
||
* [AI Gateway quickstart: Set up AI Proxy](/gateway/latest/get-started/ai-gateway/) | ||
* [Configuration reference](/hub/kong-inc/ai-semantic-prompt-guard/configuration/) | ||
* [Basic configuration example](/hub/kong-inc/ai-semantic-prompt-guard/how-to/basic-example/) | ||
* [Learn how to use the plugin](/hub/kong-inc/ai-semantic-prompt-guard/how-to/) | ||
|
||
### All AI Gateway plugins | ||
|
||
{% include_cached /md/ai-plugins-links.md release=page.release %} |
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,3 @@ | ||
strategy: gateway | ||
releases: | ||
minimum_version: '3.8.x' |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I might want to add here is that deny takes precedence of allow, if they are both speicifed. We also want to mention this to the
ai-prompt-guard
plugin docs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to clarify this in the overview files for both plugins (https://github.com/Kong/docs.konghq.com/pull/7770/files#diff-6e056bdacbd3365e3bd699113524157c895ed9b769f904a66245f6167343ec57R18)