Repository navigation
Hiddenlayer Integration: Add V2 Integration #22708
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
Changes from 1 commit
181313b
9b9b9e4
add70c9
fcb16d9
7afa6a0
7fd02e7
b3a4898
c878dd5
ab68592
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,14 +151,12 @@ async def apply_guardrail( | |
| project_id = headers.get("hl-project-id") | ||
|
|
||
| if scan_params := inputs.get("structured_messages"): | ||
| # Convert AllMessageValues to simple dict format for HiddenLayer API | ||
| messages = [ | ||
| {"role": msg.get("role", "user"), "content": msg.get("content", "")} | ||
| for msg in scan_params | ||
| if isinstance(msg, dict) | ||
| ] | ||
| last_msg = scan_params[-1] | ||
| result = await self._call_hiddenlayer( | ||
| project_id, hl_request_metadata, {"messages": messages}, input_type | ||
| project_id, | ||
| hl_request_metadata, | ||
| {"messages": [{"role": last_msg.get("role", "user"), "content": last_msg.get("content", "")}]}, | ||
| input_type, | ||
| ) | ||
|
Comment on lines
155
to
169
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test coverage for new behavior The existing test Consider adding a test that:
|
||
| elif text := inputs.get("texts"): | ||
| result = await self._call_hiddenlayer( | ||
|
|
@@ -171,11 +169,19 @@ async def apply_guardrail( | |
| result = {} | ||
|
|
||
| if result.get("evaluation", {}).get("action") == HiddenlayerAction.BLOCK: | ||
| detected_reasons = [ | ||
| entry["name"] | ||
| for entry in result.get("analysis", []) | ||
| if entry.get("detected") | ||
| ] | ||
|
Ashton-Sidhu marked this conversation as resolved.
|
||
| threat_level = result.get("evaluation", {}).get("threat_level") | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail={ | ||
| "error": "Violated guardrail policy", | ||
| "hiddenlayer_guardrail_response": HiddenlayerMessages.BLOCK_MESSAGE, | ||
| "hiddenlayer_guardrail_response": HiddenlayerMessages.BLOCK_MESSAGE.value, | ||
| "block_reasons": detected_reasons, | ||
| "threat_level": threat_level, | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.