-
Notifications
You must be signed in to change notification settings - Fork 9
NOISSUE - Refactor guardrails to sidecar #132
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
NOISSUE - Refactor guardrails to sidecar #132
Conversation
e3fac57 to
dcc852e
Compare
2a61df1 to
7250492
Compare
|
|
||
| cleaned = response.strip() | ||
|
|
||
| cleaned = re.sub(r'^(bot|I)\s+\w+(\s+\w+)*\s*\n', '', cleaned, flags=re.IGNORECASE) |
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.
removes any first line that begins with “I …”, which will delete normal assistant answers. Constrain this to explicit prefixes
| return cleaned.strip() | ||
|
|
||
|
|
||
| @router.post("/messages", tags=["chat"]) |
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.
we should not have this endpoint
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.
if it is purely internal you can leave it
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.
This is internal. And it's needed. Perhaps renaming, but the functionality remains the same: to receive chat contents in the Guardrails service.
proxy/api/transport.go
Outdated
| if !ok { | ||
| func guardrailsHandler(transport http.RoundTripper, rter *router.Router) http.HandlerFunc { | ||
| return func(w http.ResponseWriter, r *http.Request) { | ||
| if r.Header.Get("X-Guardrails-Request") != "true" { |
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.
any client can bypass it by simply adding the header. Replace the header check with proper authentication—either apply the same authn.Middleware() used elsewhere or validate a cryptographically signed token.
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.
Best way to handle is this is building a custom LLM wrapper.
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.
Best way to handle is this is building a custom LLM wrapper.
| return nil, 0, err | ||
| } | ||
| defer resp.Body.Close() | ||
| req.URL.RawQuery = target.RawQuery |
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.
Current logic overwrites the incoming query if target.RawQuery is set. Merge them to avoid losing client parameters.
dcd2de0 to
70fbf66
Compare
proxy/middleware/model_auth.go
Outdated
| modelAuth = bearerPrefix + modelAuth | ||
| } | ||
|
|
||
| r.Header.Set(authorizationHeader, modelAuth) |
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.
remove X -Model-Authorization since it is not used downstream
| ) | ||
|
|
||
| # Extract text from ChatResult | ||
| return result.generations[0].text |
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.
if generations is nil, will panic
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
b492ec7 to
85dfc23
Compare
Signed-off-by: Jilks Smith smithjilks@gmail.com
What type of PR is this?
This is a bug fix because it routes llm requests from Nemo Guardrails through the proxy.
What does this do?
Routes llm requests from Nemo Guardrails through the proxy.
Which issue(s) does this PR fix/relate to?
Resolves #51
Have you included tests for your changes?
No.
Did you document any new/modified features?
No.
Notes