This commit is contained in:
John (Jet Token)
2023-02-06 16:06:10 -08:00
parent 43450e8e85
commit b021ac7fdf

View File

@@ -16,9 +16,9 @@ The StringGuard works by checking if an output contains a sufficient percentage
The CustomGuard takes in a function to create, as the name suggests, a custom guard. The function should take a single string as input and return a boolean where True means the guard was violated and False means it was not. For example, you may wish to ensure a response is a certain length and so could implement a custom guard to check that the response is greater than some amount of characters.
One of the most promising use cases for a guard is to train your own classifier to accept or deny a response. For example, suppose you have a chat agent that is only supposed to be a cooking assistant. You may worry that users could try to ask the chat agent to say things totally unrelated to cooking or even to say something racist or violent. You could use a restriction guard which will help but its still an extra llm call which is expensive and it may not work every time since llms are unpredictable.
One use case for a guard is to train your own classifier to accept or deny a response. For example, suppose you have a chat agent that is only supposed to be a cooking assistant. You may worry that users could try to ask the chat agent to say things totally unrelated to cooking or even to say something racist or violent. You could use a restriction guard which will help but its still an extra llm call which is expensive and it may not work every time since llms are unpredictable.
Suppose instead you collect 100 examples of cooking related responses and some 200 examples of responses that don't have anything to do with cooking. You could then train a model that determines if a piece of text is about cooking or not. This model could be run on your own infrastructure for minimal cost compared to an LLM and, if trained properly, will be many times as reliable. You could run this model in a function and create a custom guard to restrict the output of your chat agent to only responses that your model deems are related to cooking.
Suppose instead you collect 100 examples of cooking related responses and 200 examples of responses that don't have anything to do with cooking. You could then train a model that classifies if a piece of text is about cooking or not. This model could be run on your own infrastructure for minimal cost compared to an LLM and could potentially be much more reliable. You could then use it to create a custom guard to restrict the output of your chat agent to only responses that your model classifies as related to cooking.
<!-- add this image: docs/modules/guards/ClassifierExample.png -->