Skip to content

Instantly share code, notes, and snippets.

@aprilspeight
Last active May 7, 2024 19:23
Show Gist options
  • Save aprilspeight/130fba14b351152ae995be78de2df01a to your computer and use it in GitHub Desktop.
Save aprilspeight/130fba14b351152ae995be78de2df01a to your computer and use it in GitHub Desktop.
Groundedness
# --------------------
# Groundedness Q&A
# --------------------
import os
from dotenv import load_dotenv
import requests
load_dotenv()
key = os.environ["CONTENT_SAFETY_KEY"]
endpoint = os.environ["CONTENT_SAFETY_ENDPOINT"]
url = f'{endpoint}/contentsafety/text:detectGroundedness?api-version=2024-02-15-preview'
subscription_key = key
headers = {
'Ocp-Apim-Subscription-Key': subscription_key,
'Content-Type': 'application/json'
}
data = {
"domain": "Generic",
"task": "QnA",
"qna": {
"query": "<Your query>"
},
"text": "<Your text>",
"groundingSources": [
"<Your grounding source>"
],
"reasoning": False
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment