Analyses the relevance of a generated answer to a given question, ensuring that the response appropriately addresses the query. The detector returns a relevancy score indicating how well the answer relates to the question.

Example request:

import requests
import json
import os

url = "https://api.enkryptai.com/guardrails/detect-relevancy"
payload = json.dumps({
"question": "What is CV Raman known for?",
"llm_answer": "C.V. Raman won the Nobel Prize for Physics in 1930 for his work on light scattering"
})

headers = {
    'Content-Type': 'application/json',
    'api_key': os.getenv('ENKRYPTAI_API_KEY')
}

response = requests.request("POST", url, headers=headers, data=payload)

formatted_response = json.dumps(json.loads(response.text), indent=4)
print(formatted_response)

Example response:

{
	"relevancy_score": 1.0
}