|
79 | 79 | default_groundedness_config = {"groundedness_checker": {"verify_response": False}} |
80 | 80 |
|
81 | 81 |
|
| 82 | +def autoalign_output_api_mapping(result: dict) -> bool: |
| 83 | + """ |
| 84 | + Mapping for autoalign_output_api. |
| 85 | +
|
| 86 | + Expects result to be a dict with a key "guardrails_triggered" (a boolean). |
| 87 | + Returns True (block) if guardrails were triggered. |
| 88 | + """ |
| 89 | + return result.get("guardrails_triggered", False) |
| 90 | + |
| 91 | + |
| 92 | +def autoalign_groundedness_output_api_mapping(result: float) -> bool: |
| 93 | + """ |
| 94 | + Mapping for autoalign_groundedness_output_api. |
| 95 | +
|
| 96 | + Expects result to be a numeric score. |
| 97 | + Returns True (block) if the score is below the default groundedness threshold. |
| 98 | + """ |
| 99 | + DEFAULT_GROUNDEDNESS_THRESHOLD = 0.5 |
| 100 | + return result < DEFAULT_GROUNDEDNESS_THRESHOLD |
| 101 | + |
| 102 | + |
| 103 | +def autoalign_factcheck_output_api_mapping(result: float) -> bool: |
| 104 | + """ |
| 105 | + Mapping for autoalign_factcheck_output_api. |
| 106 | +
|
| 107 | + Expects result to be a numeric score. |
| 108 | + Returns True (block) if the score is below the default factcheck threshold. |
| 109 | + """ |
| 110 | + DEFAULT_FACTCHECK_THRESHOLD = 0.5 |
| 111 | + return result < DEFAULT_FACTCHECK_THRESHOLD |
| 112 | + |
| 113 | + |
82 | 114 | def process_autoalign_output(responses: List[Any], show_toxic_phrases: bool = False): |
83 | 115 | """Processes the output provided AutoAlign API""" |
84 | 116 |
|
@@ -252,6 +284,7 @@ async def autoalign_input_api( |
252 | 284 | context: Optional[dict] = None, |
253 | 285 | show_autoalign_message: bool = True, |
254 | 286 | show_toxic_phrases: bool = False, |
| 287 | + **kwargs, |
255 | 288 | ): |
256 | 289 | """Calls AutoAlign API for the user message and guardrail configuration provided""" |
257 | 290 | user_message = context.get("user_message") |
@@ -285,12 +318,13 @@ async def autoalign_input_api( |
285 | 318 | return autoalign_response |
286 | 319 |
|
287 | 320 |
|
288 | | -@action(name="autoalign_output_api") |
| 321 | +@action(name="autoalign_output_api", output_mapping=autoalign_output_api_mapping) |
289 | 322 | async def autoalign_output_api( |
290 | 323 | llm_task_manager: LLMTaskManager, |
291 | 324 | context: Optional[dict] = None, |
292 | 325 | show_autoalign_message: bool = True, |
293 | 326 | show_toxic_phrases: bool = False, |
| 327 | + **kwargs, |
294 | 328 | ): |
295 | 329 | """Calls AutoAlign API for the bot message and guardrail configuration provided""" |
296 | 330 | bot_message = context.get("bot_message") |
@@ -319,12 +353,16 @@ async def autoalign_output_api( |
319 | 353 | return autoalign_response |
320 | 354 |
|
321 | 355 |
|
322 | | -@action(name="autoalign_groundedness_output_api") |
| 356 | +@action( |
| 357 | + name="autoalign_groundedness_output_api", |
| 358 | + output_mapping=autoalign_groundedness_output_api_mapping, |
| 359 | +) |
323 | 360 | async def autoalign_groundedness_output_api( |
324 | 361 | llm_task_manager: LLMTaskManager, |
325 | 362 | context: Optional[dict] = None, |
326 | 363 | factcheck_threshold: float = 0.0, |
327 | 364 | show_autoalign_message: bool = True, |
| 365 | + **kwargs, |
328 | 366 | ): |
329 | 367 | """Calls AutoAlign groundedness check API and checks whether the bot message is factually grounded according to given |
330 | 368 | documents""" |
@@ -355,7 +393,10 @@ async def autoalign_groundedness_output_api( |
355 | 393 | return score |
356 | 394 |
|
357 | 395 |
|
358 | | -@action(name="autoalign_factcheck_output_api") |
| 396 | +@action( |
| 397 | + name="autoalign_factcheck_output_api", |
| 398 | + output_mapping=autoalign_factcheck_output_api_mapping, |
| 399 | +) |
359 | 400 | async def autoalign_factcheck_output_api( |
360 | 401 | llm_task_manager: LLMTaskManager, |
361 | 402 | context: Optional[dict] = None, |
|
0 commit comments